/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

More work on roundtrip push support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    for k,v in refs.iteritems():
36
36
        if k.startswith("refs/tags/") and not k.endswith("^{}"):
37
37
            v = refs.get(k+"^{}", v)
38
 
            ret[k[len("refs/tags/"):]] = v
 
38
            try:
 
39
                tagname = ref_to_tag_name(k)
 
40
            except UnicodeDecodeError:
 
41
                pass
 
42
            else:
 
43
                ret[tagname] = v
39
44
    return ret
40
45
 
41
46
 
48
53
    if name is None:
49
54
        return default
50
55
    if name == "HEAD":
51
 
        return "HEAD"
 
56
        return name
52
57
    if not name.startswith("refs/"):
53
58
        return "refs/heads/%s" % name
54
59
    else:
70
75
    :param ref: Ref
71
76
    :return: A branch name
72
77
    """
73
 
    if ref == "HEAD":
74
 
        return "HEAD"
 
78
    if ref in (None, "HEAD"):
 
79
        return ref
75
80
    if ref.startswith("refs/heads/"):
76
81
        return ref[len("refs/heads/"):]
77
82
    raise ValueError("unable to map ref %s back to branch name" % ref)
79
84
 
80
85
def ref_to_tag_name(ref):
81
86
    if ref.startswith("refs/tags/"):
82
 
        return ref[len('refs/tags/'):]
 
87
        return ref[len('refs/tags/'):].decode("utf-8")
83
88
    raise ValueError("unable to map ref %s back to branch name" % ref)
84
89
 
85
90
 
110
115
        try:
111
116
            branch = self.dir.open_branch(branch_name)
112
117
        except errors.NoColocatedBranchSupport:
113
 
            raise
 
118
            if branch_name in ("HEAD", "master"):
 
119
                branch = self.dir.open_branch()
 
120
            else:
 
121
                raise
114
122
        return branch.last_revision()
115
123
 
116
124
    def read_loose_ref(self, ref):
128
136
        for branch in self.dir.list_branches():
129
137
            repo = branch.repository
130
138
            if repo.has_revision(branch.last_revision()):
131
 
                keys.add(branch_name_to_ref(branch.name, "HEAD"))
 
139
                ref = branch_name_to_ref(branch.name, "refs/heads/master")
 
140
                keys.add(ref)
 
141
                if branch.name is None:
 
142
                    keys.add("HEAD")
132
143
            for tag_name, revid in branch.tags.get_tag_dict().iteritems():
133
144
                if repo.has_revision(revid):
134
145
                    keys.add(tag_name_to_ref(tag_name))