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)
39
tagname = ref_to_tag_name(k)
40
except UnicodeDecodeError:
38
ret[k[len("refs/tags/"):]] = v
57
52
if not name.startswith("refs/"):
58
53
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
72
58
def ref_to_branch_name(ref):
73
59
"""Map a ref to a branch name
76
62
:return: A branch name
78
if ref in (None, "HEAD"):
80
66
if ref.startswith("refs/heads/"):
81
67
return ref[len("refs/heads/"):]
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)
68
raise ValueError("unable to map ref %s back to branch name")
91
72
class BazaarRefsContainer(RefsContainer):
102
83
"Symbolic references not supported for anything other than "
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):
86
def read_loose_ref(self, ref):
87
branch_name = ref_to_branch_name(ref)
116
89
branch = self.dir.open_branch(branch_name)
117
90
except errors.NoColocatedBranchSupport:
118
if branch_name in ("HEAD", "master"):
119
branch = self.dir.open_branch()
91
if ref != "refs/heads/master":
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)
93
branch = self.dir.open_branch()
94
return self.object_store._lookup_revision_sha1(
95
branch.last_revision())
134
97
def allkeys(self):
136
99
for branch in self.dir.list_branches():
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))
100
ref = branch_name_to_ref(branch.name, "refs/heads/master")
148
104
def __delitem__(self, ref):