/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

SupportĀ tagĀ refs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
        return name
56
56
 
57
57
 
 
58
def tag_name_to_ref(name):
 
59
    """Map a tag name to a ref.
 
60
 
 
61
    :param name: Tag name
 
62
    :return: ref string
 
63
    """
 
64
    return "refs/tags/%s" % name
 
65
 
 
66
 
58
67
def ref_to_branch_name(ref):
59
68
    """Map a ref to a branch name
60
69
 
65
74
        return "HEAD"
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")
69
 
 
 
77
    raise ValueError("unable to map ref %s back to branch name" % ref)
 
78
 
 
79
 
 
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)
70
84
 
71
85
 
72
86
class BazaarRefsContainer(RefsContainer):
83
97
                "Symbolic references not supported for anything other than "
84
98
                "HEAD")
85
99
 
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():
 
102
            try:
 
103
                # FIXME: This is ambiguous!
 
104
                return branch.tags.lookup_tag(tag_name)
 
105
            except errors.NoSuchTag:
 
106
                pass
 
107
        return None
 
108
 
 
109
    def _get_revid_by_branch_name(self, branch_name):
88
110
        try:
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":
92
114
                raise
93
115
            branch = self.dir.open_branch()
94
 
        return self.object_store._lookup_revision_sha1(
95
 
            branch.last_revision())
 
116
        return branch.last_revision()
 
117
 
 
118
    def read_loose_ref(self, ref):
 
119
        try:
 
120
            branch_name = ref_to_branch_name(ref)
 
121
        except ValueError:
 
122
            tag_name = ref_to_tag_name(ref)
 
123
            revid = self._get_revid_by_tag_name(tag_name)
 
124
        else:
 
125
            revid = self._get_revid_by_branch_name(branch_name)
 
126
        return self.object_store._lookup_revision_sha1(revid)
96
127
 
97
128
    def allkeys(self):
98
129
        keys = set()
99
130
        for branch in self.dir.list_branches():
100
 
            ref = branch_name_to_ref(branch.name, "refs/heads/master")
101
 
            keys.add(ref)
 
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()])
102
134
        return keys
103
135
 
104
136
    def __delitem__(self, ref):