/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 branch.py

Proper branch names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
 
56
56
 
57
57
def extract_tags(refs):
 
58
    """Extract the tags from a refs dictionary.
 
59
 
 
60
    :param refs: Refs to extract the tags from.
 
61
    :return: Dictionary mapping tag names to SHA1s.
 
62
    """
58
63
    ret = {}
59
64
    for k,v in refs.iteritems():
60
65
        if k.startswith("refs/tags/") and not k.endswith("^{}"):
63
68
    return ret
64
69
 
65
70
 
 
71
def branch_name_to_ref(name):
 
72
    """Map a branch name to a ref.
 
73
 
 
74
    :param name: Branch name
 
75
    :return: ref string
 
76
    """
 
77
    if name is None or name == "HEAD":
 
78
        return "HEAD"
 
79
    if not "/" in name:
 
80
        return "refs/heads/%s" % name
 
81
    else:
 
82
        return name
 
83
 
 
84
 
 
85
def ref_to_branch_name(ref):
 
86
    """Map a ref to a branch name
 
87
 
 
88
    :param ref: Ref
 
89
    :return: A branch name
 
90
    """
 
91
    if ref == "HEAD":
 
92
        return "HEAD"
 
93
    if ref.startswith("refs/heads/"):
 
94
        return ref[len("refs/heads/"):]
 
95
    raise ValueError("unable to map ref %s back to branch name")
 
96
 
 
97
 
66
98
class GitPullResult(branch.PullResult):
67
99
 
68
100
    def _lookup_revno(self, revid):
122
154
 
123
155
class DictTagDict(LocalGitTagDict):
124
156
 
125
 
 
126
157
    def __init__(self, branch, tags):
127
158
        super(DictTagDict, self).__init__(branch)
128
159
        self._tags = tags
131
162
        return self._tags
132
163
 
133
164
 
134
 
 
135
165
class GitBranchFormat(branch.BranchFormat):
136
166
 
137
167
    def get_format_description(self):
158
188
class GitBranch(ForeignBranch):
159
189
    """An adapter to git repositories for bzr Branch objects."""
160
190
 
161
 
    def __init__(self, bzrdir, repository, name, lockfiles, tagsdict=None):
 
191
    def __init__(self, bzrdir, repository, ref, lockfiles, tagsdict=None):
162
192
        self.repository = repository
163
193
        self._format = GitBranchFormat()
164
194
        self.control_files = lockfiles
166
196
        super(GitBranch, self).__init__(repository.get_mapping())
167
197
        if tagsdict is not None:
168
198
            self.tags = DictTagDict(self, tagsdict)
169
 
        self.name = name
 
199
        self.ref = ref
 
200
        self.name = ref_to_branch_name(ref)
170
201
        self._head = None
171
202
        self.base = bzrdir.root_transport.base
172
 
        if self.name != "HEAD":
173
 
            self.base += ",%s" % self.name
174
203
 
175
204
    def _get_checkout_format(self):
176
205
        """Return the most suitable metadir for a checkout of this branch.
198
227
    nick = property(_get_nick, _set_nick)
199
228
 
200
229
    def __repr__(self):
201
 
        return "%s(%r, %r)" % (self.__class__.__name__, self.repository.base, self.name)
 
230
        return "<%s(%r, %r)>" % (self.__class__.__name__, self.repository.base,
 
231
            self.ref)
202
232
 
203
233
    def generate_revision_history(self, revid, old_revid=None):
204
234
        # FIXME: Check that old_revid is in the ancestry of revid
298
328
 
299
329
    def _get_head(self):
300
330
        try:
301
 
            return self.repository._git.ref(self.name)
 
331
            return self.repository._git.ref(self.ref)
302
332
        except KeyError:
303
333
            return None
304
334
 
312
342
 
313
343
    def _set_head(self, value):
314
344
        self._head = value
315
 
        self.repository._git.refs[self.name] = self._head
 
345
        self.repository._git.refs[self.ref] = self._head
316
346
        self._clear_cached_state()
317
347
 
318
348
    head = property(_get_head, _set_head)