/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to refs.py

Return unpeeled tags in extract_tags.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    """Extract the tags from a refs dictionary.
30
30
 
31
31
    :param refs: Refs to extract the tags from.
32
 
    :return: Dictionary mapping tag names to SHA1s.
 
32
    :return: Dictionary mapping tag names to SHA1s of the actual object
 
33
        and unpeeled object SHA1s.
33
34
    """
34
35
    ret = {}
35
 
    for k,v in refs.iteritems():
 
36
    for k, v in refs.iteritems():
36
37
        if k.startswith("refs/tags/") and not k.endswith("^{}"):
37
 
            v = refs.get(k+"^{}", v)
 
38
            try:
 
39
                peeled = refs[k+"^{}"]
 
40
                unpeeled = v
 
41
            except KeyError:
 
42
                peeled = v
 
43
                unpeeled = None
38
44
            try:
39
45
                tagname = ref_to_tag_name(k)
40
46
            except UnicodeDecodeError:
41
47
                pass
42
48
            else:
43
 
                ret[tagname] = v
 
49
                ret[tagname] = (peeled, unpeeled)
44
50
    return ret
45
51
 
46
52
 
85
91
def ref_to_tag_name(ref):
86
92
    if ref.startswith("refs/tags/"):
87
93
        return ref[len('refs/tags/'):].decode("utf-8")
88
 
    raise ValueError("unable to map ref %s back to branch name" % ref)
 
94
    raise ValueError("unable to map ref %s back to tag name" % ref)
89
95
 
90
96
 
91
97
class BazaarRefsContainer(RefsContainer):