/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

Support pulling from git to git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
    )
44
44
 
45
45
 
 
46
class GitPullResult(branch.PullResult):
 
47
 
 
48
    def _lookup_revno(self, revid):
 
49
        assert isinstance(revid, str), "was %r" % revid
 
50
        # Try in source branch first, it'll be faster
 
51
        return self.target_branch.revision_id_to_revno(revid)
 
52
 
 
53
    @property
 
54
    def old_revno(self):
 
55
        return self._lookup_revno(self.old_revid)
 
56
 
 
57
    @property
 
58
    def new_revno(self):
 
59
        return self._lookup_revno(self.new_revid)
 
60
 
 
61
 
46
62
class LocalGitTagDict(tag.BasicTags):
47
63
    """Dictionary with tags in a local repository."""
48
64
 
129
145
            stop_revision = source.last_revision()
130
146
        # FIXME: Check for diverged branches
131
147
        revidmap = self.repository.dfetch(source.repository, stop_revision)
132
 
        self.head, self.mapping = self.mapping.revision_id_bzr_to_foreign(
133
 
            revidmap[stop_revision])
 
148
        self.generate_revision_history(revidmap[stop_revision])
 
149
        return revidmap
 
150
 
 
151
    def generate_revision_history(self, revid, old_revid=None):
 
152
        # FIXME: Check that old_revid is in the ancestry of revid
 
153
        newhead, self.mapping = self.mapping.revision_id_bzr_to_foreign(revid)
 
154
        self._set_head(newhead)
 
155
 
 
156
    def _set_head(self, head):
134
157
        self.repository._git.set_ref(self.name, self.head)
135
 
        return revidmap
 
158
        self.head = head
136
159
 
137
160
    def lock_write(self):
138
161
        self.control_files.lock_write()
242
265
 
243
266
    @classmethod
244
267
    def is_compatible(self, source, target):
245
 
        return isinstance(source, GitBranch)
 
268
        return (isinstance(source, GitBranch) and 
 
269
                not isinstance(target, GitBranch))
246
270
 
247
271
    def update_revisions(self, stop_revision=None, overwrite=False,
248
272
        graph=None):
273
297
 
274
298
 
275
299
branch.InterBranch.register_optimiser(InterGitGenericBranch)
 
300
 
 
301
 
 
302
class InterGitRemoteLocalBranch(branch.InterBranch):
 
303
    """InterBranch implementation that pulls between Git branches."""
 
304
 
 
305
    @classmethod
 
306
    def is_compatible(self, source, target):
 
307
        from bzrlib.plugins.git.remote import RemoteGitBranch
 
308
        return (isinstance(source, RemoteGitBranch) and 
 
309
                isinstance(target, LocalGitBranch))
 
310
 
 
311
    def pull(self, stop_revision=None, overwrite=False, 
 
312
        possible_transports=None):
 
313
        result = GitPullResult()
 
314
        result.source_branch = self.source
 
315
        result.target_branch = self.target
 
316
        interrepo = repository.InterRepository.get(self.source.repository, 
 
317
            self.target.repository)
 
318
        result.old_revid = self.target.last_revision()
 
319
        if stop_revision is None:
 
320
            stop_revision = self.source.last_revision()
 
321
        interrepo.fetch(revision_id=stop_revision)
 
322
        self.target.generate_revision_history(stop_revision, result.old_revid)
 
323
        result.new_revid = self.target.last_revision()
 
324
        return result
 
325
 
 
326
 
 
327
branch.InterBranch.register_optimiser(InterGitRemoteLocalBranch)