58
def tag_name_to_ref(name):
59
"""Map a tag name to a ref.
64
return "refs/tags/%s" % name
58
67
def ref_to_branch_name(ref):
59
68
"""Map a ref to a branch name
66
75
if ref.startswith("refs/heads/"):
67
76
return ref[len("refs/heads/"):]
68
raise ValueError("unable to map ref %s back to branch name")
77
raise ValueError("unable to map ref %s back to branch name" % ref)
80
def ref_to_tag_name(ref):
81
if ref.startswith("refs/tags/"):
82
return ref[len('refs/tags/'):]
83
raise ValueError("unable to map ref %s back to branch name" % ref)
72
86
class BazaarRefsContainer(RefsContainer):
83
97
"Symbolic references not supported for anything other than "
86
def read_loose_ref(self, ref):
87
branch_name = ref_to_branch_name(ref)
100
def _get_revid_by_tag_name(self, tag_name):
101
for branch in self.dir.list_branches():
103
# FIXME: This is ambiguous!
104
return branch.tags.lookup_tag(tag_name)
105
except errors.NoSuchTag:
109
def _get_revid_by_branch_name(self, branch_name):
89
111
branch = self.dir.open_branch(branch_name)
90
112
except errors.NoColocatedBranchSupport:
91
if ref != "refs/heads/master":
113
if branch_name != "master":
93
115
branch = self.dir.open_branch()
94
return self.object_store._lookup_revision_sha1(
95
branch.last_revision())
116
return branch.last_revision()
118
def read_loose_ref(self, ref):
120
branch_name = ref_to_branch_name(ref)
122
tag_name = ref_to_tag_name(ref)
123
revid = self._get_revid_by_tag_name(tag_name)
125
revid = self._get_revid_by_branch_name(branch_name)
126
return self.object_store._lookup_revision_sha1(revid)
97
128
def allkeys(self):
99
130
for branch in self.dir.list_branches():
100
ref = branch_name_to_ref(branch.name, "refs/heads/master")
131
keys.add(branch_name_to_ref(branch.name, "refs/heads/master"))
132
keys.update([tag_name_to_ref(tag)
133
for tag in branch.tags.get_tag_dict().keys()])
104
136
def __delitem__(self, ref):