/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

Cope with tuples in refs dictionary.

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