# Path: ellen/utils/format.py
# def format_tag(tag, repository):
#     d = {}
#     d['name'] = tag.name
#     d['tag'] = tag.name
#     d['target'] = str(tag.target)
#     d['type'] = 'tag'
#     d['tagger'] = _format_pygit2_signature(tag.tagger)
#     d['message'], _, d['body'] = tag.message.strip().partition('\n\n')
#     d['sha'] = str(tag.id)
#     return d
# 
# Path: ellen/utils/format.py
# def format_lw_tag(ref, tag, repository):
#     """format lightweight tag"""
#     d = {}
#     d['name'] = _format_short_reference_name(ref)
#     d['tag'] = d['name']
#     d['object'] = str(tag.id)
#     d['type'] = 'commit'  # really useful ?
#     d['commit'] = format_commit(tag, repository)
#     return d


from pygit2 import GIT_OBJ_TAG
from pygit2 import GIT_OBJ_COMMIT
from pygit2 import Signature
from ellen.utils.format import format_tag
from ellen.utils.format import format_lw_tag
#!/usr/bin/env python
# -*- coding: utf-8 -*-




def list_tags(repository, name_only=None):
    """git tag command, pygit2 wrapper"""
    tags = []
    refs = repository.listall_references()
    for ref in refs:
        if ref.startswith("refs/tags/"):
            if name_only:
                tags.append(ref.rpartition('/')[-1])
                continue
            # this is a tag but maybe a lightweight tag
            tag_obj = repository.revparse_single(ref)
            if tag_obj and tag_obj.type == GIT_OBJ_COMMIT:
                # lightweight tag
                tags.append(format_lw_tag(ref, tag_obj, repository))
            elif tag_obj and tag_obj.type == GIT_OBJ_TAG:

# Path: ellen/utils/format.py
# def format_tag(tag, repository):
#     d = {}
#     d['name'] = tag.name
#     d['tag'] = tag.name
#     d['target'] = str(tag.target)
#     d['type'] = 'tag'
#     d['tagger'] = _format_pygit2_signature(tag.tagger)
#     d['message'], _, d['body'] = tag.message.strip().partition('\n\n')
#     d['sha'] = str(tag.id)
#     return d
# 
# Path: ellen/utils/format.py
# def format_lw_tag(ref, tag, repository):
#     """format lightweight tag"""
#     d = {}
#     d['name'] = _format_short_reference_name(ref)
#     d['tag'] = d['name']
#     d['object'] = str(tag.id)
#     d['type'] = 'commit'  # really useful ?
#     d['commit'] = format_commit(tag, repository)
#     return d


# Path: ellen/git/tag.py
from pygit2 import GIT_OBJ_TAG
from pygit2 import GIT_OBJ_COMMIT
from pygit2 import Signature
from ellen.utils.format import format_tag
from ellen.utils.format import format_lw_tag

#!/usr/bin/env python
# -*- coding: utf-8 -*-




def list_tags(repository, name_only=None):
    """git tag command, pygit2 wrapper"""
    tags = []
    refs = repository.listall_references()
    for ref in refs:
        if ref.startswith("refs/tags/"):
            if name_only:
                tags.append(ref.rpartition('/')[-1])
                continue
            # this is a tag but maybe a lightweight tag
            tag_obj = repository.revparse_single(ref)
            if tag_obj and tag_obj.type == GIT_OBJ_COMMIT:
                # lightweight tag
                tags.append(format_lw_tag(ref, tag_obj, repository))
            elif tag_obj and tag_obj.type == GIT_OBJ_TAG:

                tags.append(format_tag(tag_obj, repository))