/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

Fix unpeel map.

Show diffs side-by-side

added added

removed removed

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