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
39
tagname = ref_to_tag_name(k)
40
except UnicodeDecodeError:
52
57
if not name.startswith("refs/"):
53
58
return "refs/heads/%s" % name
63
def tag_name_to_ref(name):
64
"""Map a tag name to a ref.
69
return "refs/tags/%s" % name
58
72
def ref_to_branch_name(ref):
59
73
"""Map a ref to a branch name
62
76
:return: A branch name
78
if ref in (None, "HEAD"):
66
80
if ref.startswith("refs/heads/"):
67
81
return ref[len("refs/heads/"):]
68
raise ValueError("unable to map ref %s back to branch name")
82
raise ValueError("unable to map ref %s back to branch name" % ref)
85
def ref_to_tag_name(ref):
86
if ref.startswith("refs/tags/"):
87
return ref[len('refs/tags/'):].decode("utf-8")
88
raise ValueError("unable to map ref %s back to branch name" % ref)
72
91
class BazaarRefsContainer(RefsContainer):
83
102
"Symbolic references not supported for anything other than "
86
def read_loose_ref(self, ref):
87
branch_name = ref_to_branch_name(ref)
105
def _get_revid_by_tag_name(self, tag_name):
106
for branch in self.dir.list_branches():
108
# FIXME: This is ambiguous!
109
return branch.tags.lookup_tag(tag_name)
110
except errors.NoSuchTag:
114
def _get_revid_by_branch_name(self, branch_name):
89
116
branch = self.dir.open_branch(branch_name)
90
117
except errors.NoColocatedBranchSupport:
91
if ref != "refs/heads/master":
118
if branch_name in ("HEAD", "master"):
119
branch = self.dir.open_branch()
93
branch = self.dir.open_branch()
94
return self.object_store._lookup_revision_sha1(
95
branch.last_revision())
122
return branch.last_revision()
124
def read_loose_ref(self, ref):
126
branch_name = ref_to_branch_name(ref)
128
tag_name = ref_to_tag_name(ref)
129
revid = self._get_revid_by_tag_name(tag_name)
131
revid = self._get_revid_by_branch_name(branch_name)
132
return self.object_store._lookup_revision_sha1(revid)
97
134
def allkeys(self):
99
136
for branch in self.dir.list_branches():
100
ref = branch_name_to_ref(branch.name, "refs/heads/master")
137
repo = branch.repository
138
if repo.has_revision(branch.last_revision()):
139
ref = branch_name_to_ref(branch.name, "refs/heads/master")
141
if branch.name is None:
143
for tag_name, revid in branch.tags.get_tag_dict().iteritems():
144
if repo.has_revision(revid):
145
keys.add(tag_name_to_ref(tag_name))
104
148
def __delitem__(self, ref):