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

GitBranchBuilder now handles file names with newlines correctly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2007 Canonical Ltd
2
 
# Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org>
3
2
#
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
17
16
 
18
17
"""An adapter between a Git Branch and a Bazaar Branch"""
19
18
 
20
 
from dulwich.objects import (
21
 
    Commit,
22
 
    Tag,
23
 
    )
24
 
 
25
19
from bzrlib import (
26
20
    branch,
27
 
    bzrdir,
28
21
    config,
29
 
    errors,
30
 
    repository,
31
22
    revision,
32
 
    tag,
33
 
    transport,
34
 
    )
35
 
from bzrlib.decorators import (
36
 
    needs_read_lock,
37
 
    )
38
 
from bzrlib.trace import (
39
 
    is_quiet,
40
 
    mutter,
41
 
    )
42
 
 
43
 
from bzrlib.plugins.git import (
44
 
    get_rich_root_format,
45
 
    )
46
 
from bzrlib.plugins.git.config import (
47
 
    GitBranchConfig,
48
 
    )
49
 
from bzrlib.plugins.git.errors import (
50
 
    NoPushSupport,
51
 
    NoSuchRef,
52
 
    )
53
 
 
54
 
from bzrlib.foreign import ForeignBranch
55
 
 
56
 
 
57
 
def extract_tags(refs):
58
 
    ret = {}
59
 
    for k,v in refs.iteritems():
60
 
        if k.startswith("refs/tags/") and not k.endswith("^{}"):
61
 
            v = refs.get(k+"^{}", v)
62
 
            ret[k[len("refs/tags/"):]] = v
63
 
    return ret
64
 
 
65
 
 
66
 
class GitPullResult(branch.PullResult):
67
 
 
68
 
    def _lookup_revno(self, revid):
69
 
        assert isinstance(revid, str), "was %r" % revid
70
 
        # Try in source branch first, it'll be faster
71
 
        return self.target_branch.revision_id_to_revno(revid)
72
 
 
73
 
    @property
74
 
    def old_revno(self):
75
 
        return self._lookup_revno(self.old_revid)
76
 
 
77
 
    @property
78
 
    def new_revno(self):
79
 
        return self._lookup_revno(self.new_revid)
80
 
 
81
 
 
82
 
class LocalGitTagDict(tag.BasicTags):
83
 
    """Dictionary with tags in a local repository."""
 
23
    )
 
24
from bzrlib.decorators import needs_read_lock
 
25
 
 
26
from bzrlib.plugins.git import ids
 
27
 
 
28
 
 
29
class GitBranchConfig(config.BranchConfig):
 
30
    """BranchConfig that uses locations.conf in place of branch.conf"""
84
31
 
85
32
    def __init__(self, branch):
86
 
        self.branch = branch
87
 
        self.repository = branch.repository
88
 
 
89
 
    def get_tag_dict(self):
90
 
        ret = {}
91
 
        for k,v in extract_tags(self.repository._git.get_refs()).iteritems():
92
 
            try:
93
 
                obj = self.repository._git[v]
94
 
            except KeyError:
95
 
                mutter("Tag %s points at unknown object %s, ignoring", v, obj)
96
 
                continue
97
 
            while isinstance(obj, Tag):
98
 
                v = obj.object[1]
99
 
                obj = self.repository._git[v]
100
 
            if not isinstance(obj, Commit):
101
 
                mutter("Tag %s points at object %r that is not a commit, "
102
 
                       "ignoring", k, obj)
103
 
                continue
104
 
            ret[k] = self.branch.mapping.revision_id_foreign_to_bzr(v)
105
 
        return ret
106
 
 
107
 
    def set_tag(self, name, revid):
108
 
        self.repository._git.refs["refs/tags/%s" % name], _ = \
109
 
            self.branch.mapping.revision_id_bzr_to_foreign(revid)
110
 
 
111
 
 
112
 
class DictTagDict(LocalGitTagDict):
113
 
 
114
 
 
115
 
    def __init__(self, branch, tags):
116
 
        super(DictTagDict, self).__init__(branch)
117
 
        self._tags = tags
118
 
 
119
 
    def get_tag_dict(self):
120
 
        return self._tags
121
 
 
 
33
        config.BranchConfig.__init__(self, branch)
 
34
        # do not provide a BranchDataConfig
 
35
        self.option_sources = self.option_sources[0], self.option_sources[2]
 
36
 
 
37
    def set_user_option(self, name, value, local=False):
 
38
        """Force local to True"""
 
39
        config.BranchConfig.set_user_option(self, name, value, local=True)
122
40
 
123
41
 
124
42
class GitBranchFormat(branch.BranchFormat):
125
43
 
126
 
    def get_format_description(self):
 
44
    def get_branch_description(self):
127
45
        return 'Git Branch'
128
46
 
129
 
    def network_name(self):
130
 
        return "git"
131
 
 
132
 
    def supports_tags(self):
133
 
        return True
134
 
 
135
 
    def get_foreign_tests_branch_factory(self):
136
 
        from bzrlib.plugins.git.tests.test_branch import ForeignTestsBranchFactory
137
 
        return ForeignTestsBranchFactory()
138
 
 
139
 
    def make_tags(self, branch):
140
 
        if getattr(branch.repository, "get_refs", None) is not None:
141
 
            from bzrlib.plugins.git.remote import RemoteGitTagDict
142
 
            return RemoteGitTagDict(branch)
143
 
        else:
144
 
            return LocalGitTagDict(branch)
145
 
 
146
 
 
147
 
class GitBranch(ForeignBranch):
 
47
 
 
48
class GitBranch(branch.Branch):
148
49
    """An adapter to git repositories for bzr Branch objects."""
149
50
 
150
 
    def __init__(self, bzrdir, repository, name, lockfiles, tagsdict=None):
151
 
        self.repository = repository
 
51
    def __init__(self, gitdir, lockfiles):
 
52
        from bzrlib.plugins.git import git_repository
 
53
        self.bzrdir = gitdir
 
54
        self.control_files = lockfiles
 
55
        self.repository = git_repository.GitRepository(gitdir, lockfiles)
 
56
        self.base = gitdir.root_transport.base
 
57
        if '.git' not in gitdir.root_transport.list_dir('.'):
 
58
            raise errors.NotBranchError(self.base)
152
59
        self._format = GitBranchFormat()
153
 
        self.control_files = lockfiles
154
 
        self.bzrdir = bzrdir
155
 
        super(GitBranch, self).__init__(repository.get_mapping())
156
 
        if tagsdict is not None:
157
 
            self.tags = DictTagDict(self, tagsdict)
158
 
        self.name = name
159
 
        self._head = None
160
 
        self.base = bzrdir.root_transport.base
161
 
 
162
 
    def _get_checkout_format(self):
163
 
        """Return the most suitable metadir for a checkout of this branch.
164
 
        Weaves are used if this branch's repository uses weaves.
165
 
        """
166
 
        return get_rich_root_format()
167
 
 
168
 
    def get_child_submit_format(self):
169
 
        """Return the preferred format of submissions to this branch."""
170
 
        ret = self.get_config().get_user_option("child_submit_format")
171
 
        if ret is not None:
172
 
            return ret
173
 
        return "git"
174
 
 
175
 
    def _get_nick(self, local=False, possible_master_transports=None):
176
 
        """Find the nick name for this branch.
177
 
 
178
 
        :return: Branch nick
179
 
        """
180
 
        return self.name
181
 
 
182
 
    def _set_nick(self, nick):
183
 
        raise NotImplementedError
184
 
 
185
 
    nick = property(_get_nick, _set_nick)
186
 
 
187
 
    def __repr__(self):
188
 
        return "%s(%r, %r)" % (self.__class__.__name__, self.repository.base, self.name)
189
 
 
190
 
    def generate_revision_history(self, revid, old_revid=None):
191
 
        # FIXME: Check that old_revid is in the ancestry of revid
192
 
        newhead, self.mapping = self.mapping.revision_id_bzr_to_foreign(revid)
193
 
        self._set_head(newhead)
194
60
 
195
61
    def lock_write(self):
196
62
        self.control_files.lock_write()
197
63
 
198
 
    def get_stacked_on_url(self):
199
 
        # Git doesn't do stacking (yet...)
200
 
        raise errors.UnstackableBranchFormat(self._format, self.base)
201
 
 
202
 
    def get_parent(self):
203
 
        """See Branch.get_parent()."""
204
 
        # FIXME: Set "origin" url from .git/config ?
205
 
        return None
206
 
 
207
 
    def set_parent(self, url):
208
 
        # FIXME: Set "origin" url in .git/config ?
209
 
        pass
210
 
 
211
 
    def lock_read(self):
212
 
        self.control_files.lock_read()
213
 
 
214
 
    def is_locked(self):
215
 
        return self.control_files.is_locked()
216
 
 
217
 
    def unlock(self):
218
 
        self.control_files.unlock()
219
 
 
220
 
    def get_physical_lock_status(self):
221
 
        return False
222
 
 
223
64
    @needs_read_lock
224
65
    def last_revision(self):
225
66
        # perhaps should escape this ?
226
 
        if self.head is None:
 
67
        head_git_id = self.repository._git.get_head()
 
68
        if head_git_id is None:
227
69
            return revision.NULL_REVISION
228
 
        return self.mapping.revision_id_foreign_to_bzr(self.head)
229
 
 
230
 
    def _basic_push(self, target, overwrite=False, stop_revision=None):
231
 
        return branch.InterBranch.get(self, target)._basic_push(
232
 
            overwrite, stop_revision)
233
 
 
234
 
 
235
 
class LocalGitBranch(GitBranch):
236
 
    """A local Git branch."""
237
 
 
238
 
    def create_checkout(self, to_location, revision_id=None, lightweight=False,
239
 
        accelerator_tree=None, hardlink=False):
240
 
        if lightweight:
241
 
            t = transport.get_transport(to_location)
242
 
            t.ensure_base()
243
 
            format = self._get_checkout_format()
244
 
            checkout = format.initialize_on_transport(t)
245
 
            from_branch = branch.BranchReferenceFormat().initialize(checkout,
246
 
                self)
247
 
            tree = checkout.create_workingtree(revision_id,
248
 
                from_branch=from_branch, hardlink=hardlink)
249
 
            return tree
250
 
        else:
251
 
            return self._create_heavyweight_checkout(to_location, revision_id,
252
 
            hardlink)
253
 
 
254
 
    def _create_heavyweight_checkout(self, to_location, revision_id=None,
255
 
                                     hardlink=False):
256
 
        """Create a new heavyweight checkout of this branch.
257
 
 
258
 
        :param to_location: URL of location to create the new checkout in.
259
 
        :param revision_id: Revision that should be the tip of the checkout.
260
 
        :param hardlink: Whether to hardlink
261
 
        :return: WorkingTree object of checkout.
262
 
        """
263
 
        checkout_branch = bzrdir.BzrDir.create_branch_convenience(
264
 
            to_location, force_new_tree=False, format=get_rich_root_format())
265
 
        checkout = checkout_branch.bzrdir
266
 
        checkout_branch.bind(self)
267
 
        # pull up to the specified revision_id to set the initial
268
 
        # branch tip correctly, and seed it with history.
269
 
        checkout_branch.pull(self, stop_revision=revision_id)
270
 
        return checkout.create_workingtree(revision_id, hardlink=hardlink)
271
 
 
272
 
    def _gen_revision_history(self):
273
 
        if self.head is None:
 
70
        return ids.convert_revision_id_git_to_bzr(head_git_id)
 
71
 
 
72
    @needs_read_lock
 
73
    def revision_history(self):
 
74
        node = self.last_revision()
 
75
        if node == revision.NULL_REVISION:
274
76
            return []
275
 
        ret = list(self.repository.iter_reverse_revision_history(
276
 
            self.last_revision()))
277
 
        ret.reverse()
278
 
        return ret
279
 
 
280
 
    def _get_head(self):
281
 
        try:
282
 
            return self.repository._git.ref(self.name)
283
 
        except KeyError:
284
 
            return None
285
 
 
286
 
    def set_last_revision_info(self, revno, revid):
287
 
        self.set_last_revision(revid)
288
 
 
289
 
    def set_last_revision(self, revid):
290
 
        (newhead, self.mapping) = self.mapping.revision_id_bzr_to_foreign(
291
 
                revid)
292
 
        self.head = newhead
293
 
 
294
 
    def _set_head(self, value):
295
 
        self._head = value
296
 
        self.repository._git.refs[self.name] = self._head
297
 
        self._clear_cached_state()
298
 
 
299
 
    head = property(_get_head, _set_head)
 
77
        ancestors = self.repository.get_revision_graph(node)
 
78
        history = []
 
79
        while node is not None:
 
80
            history.append(node)
 
81
            if len(ancestors[node]) > 0:
 
82
                node = ancestors[node][0]
 
83
            else:
 
84
                node = None
 
85
        return list(reversed(history))
300
86
 
301
87
    def get_config(self):
302
88
        return GitBranchConfig(self)
303
89
 
 
90
    def lock_read(self):
 
91
        self.control_files.lock_read()
 
92
 
 
93
    def unlock(self):
 
94
        self.control_files.unlock()
 
95
 
304
96
    def get_push_location(self):
305
97
        """See Branch.get_push_location."""
306
98
        push_loc = self.get_config().get_user_option('push_location')
309
101
    def set_push_location(self, location):
310
102
        """See Branch.set_push_location."""
311
103
        self.get_config().set_user_option('push_location', location,
312
 
                                          store=config.STORE_LOCATION)
313
 
 
314
 
    def supports_tags(self):
315
 
        return True
316
 
 
317
 
 
318
 
class GitBranchPullResult(branch.PullResult):
319
 
 
320
 
    def report(self, to_file):
321
 
        if not is_quiet():
322
 
            if self.old_revid == self.new_revid:
323
 
                to_file.write('No revisions to pull.\n')
324
 
            else:
325
 
                to_file.write('Now on revision %d (git sha: %s).\n' %
326
 
                        (self.new_revno, self.new_git_head))
327
 
        self._show_tag_conficts(to_file)
328
 
 
329
 
 
330
 
class GitBranchPushResult(branch.BranchPushResult):
331
 
 
332
 
    def _lookup_revno(self, revid):
333
 
        assert isinstance(revid, str), "was %r" % revid
334
 
        # Try in source branch first, it'll be faster
335
 
        try:
336
 
            return self.source_branch.revision_id_to_revno(revid)
337
 
        except errors.NoSuchRevision:
338
 
            # FIXME: Check using graph.find_distance_to_null() ?
339
 
            return self.target_branch.revision_id_to_revno(revid)
340
 
 
341
 
    @property
342
 
    def old_revno(self):
343
 
        return self._lookup_revno(self.old_revid)
344
 
 
345
 
    @property
346
 
    def new_revno(self):
347
 
        return self._lookup_revno(self.new_revid)
348
 
 
349
 
 
350
 
class InterFromGitBranch(branch.GenericInterBranch):
351
 
    """InterBranch implementation that pulls from Git into bzr."""
352
 
 
353
 
    @classmethod
354
 
    def _get_interrepo(self, source, target):
355
 
        return repository.InterRepository.get(source.repository,
356
 
            target.repository)
357
 
 
358
 
    @classmethod
359
 
    def is_compatible(cls, source, target):
360
 
        return (isinstance(source, GitBranch) and
361
 
                not isinstance(target, GitBranch) and
362
 
                (getattr(cls._get_interrepo(source, target), "fetch_objects", None) is not None))
363
 
 
364
 
    def update_revisions(self, stop_revision=None, overwrite=False,
365
 
        graph=None):
366
 
        """See InterBranch.update_revisions()."""
367
 
        interrepo = self._get_interrepo(self.source, self.target)
368
 
        self._head = None
369
 
        self._last_revid = None
370
 
        def determine_wants(heads):
371
 
            if not self.source.name in heads:
372
 
                raise NoSuchRef(self.source.name, heads.keys())
373
 
            if stop_revision is not None:
374
 
                self._last_revid = stop_revision
375
 
                self._head, mapping = self.source.repository.lookup_bzr_revision_id(
376
 
                    stop_revision)
377
 
            else:
378
 
                self._head = heads[self.source.name]
379
 
                self._last_revid = \
380
 
                    self.source.mapping.revision_id_foreign_to_bzr(self._head)
381
 
            if self.target.repository.has_revision(self._last_revid):
382
 
                return []
383
 
            return [self._head]
384
 
        interrepo.fetch_objects(determine_wants, self.source.mapping)
385
 
        if overwrite:
386
 
            prev_last_revid = None
387
 
        else:
388
 
            prev_last_revid = self.target.last_revision()
389
 
        self.target.generate_revision_history(self._last_revid, prev_last_revid)
390
 
 
391
 
    def pull(self, overwrite=False, stop_revision=None,
392
 
             possible_transports=None, _hook_master=None, run_hooks=True,
393
 
             _override_hook_target=None, local=False):
394
 
        """See Branch.pull.
395
 
 
396
 
        :param _hook_master: Private parameter - set the branch to
397
 
            be supplied as the master to pull hooks.
398
 
        :param run_hooks: Private parameter - if false, this branch
399
 
            is being called because it's the master of the primary branch,
400
 
            so it should not run its hooks.
401
 
        :param _override_hook_target: Private parameter - set the branch to be
402
 
            supplied as the target_branch to pull hooks.
403
 
        """
404
 
        # This type of branch can't be bound.
405
 
        if local:
406
 
            raise errors.LocalRequiresBoundBranch()
407
 
        result = GitBranchPullResult()
408
 
        result.source_branch = self.source
409
 
        if _override_hook_target is None:
410
 
            result.target_branch = self.target
411
 
        else:
412
 
            result.target_branch = _override_hook_target
413
 
        self.source.lock_read()
414
 
        try:
415
 
            # We assume that during 'pull' the target repository is closer than
416
 
            # the source one.
417
 
            graph = self.target.repository.get_graph(self.source.repository)
418
 
            result.old_revno, result.old_revid = \
419
 
                self.target.last_revision_info()
420
 
            self.update_revisions(stop_revision, overwrite=overwrite,
421
 
                graph=graph)
422
 
            result.new_git_head = self._head
423
 
            result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
424
 
                overwrite)
425
 
            result.new_revno, result.new_revid = self.target.last_revision_info()
426
 
            if _hook_master:
427
 
                result.master_branch = _hook_master
428
 
                result.local_branch = result.target_branch
429
 
            else:
430
 
                result.master_branch = result.target_branch
431
 
                result.local_branch = None
432
 
            if run_hooks:
433
 
                for hook in branch.Branch.hooks['post_pull']:
434
 
                    hook(result)
435
 
        finally:
436
 
            self.source.unlock()
437
 
        return result
438
 
 
439
 
    def _basic_push(self, overwrite=False, stop_revision=None):
440
 
        result = branch.BranchPushResult()
441
 
        result.source_branch = self.source
442
 
        result.target_branch = self.target
443
 
        graph = self.target.repository.get_graph(self.source.repository)
444
 
        result.old_revno, result.old_revid = self.target.last_revision_info()
445
 
        self.update_revisions(stop_revision, overwrite=overwrite, graph=graph)
446
 
        result.new_git_head = self._head
447
 
        result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
448
 
            overwrite)
449
 
        result.new_revno, result.new_revid = self.target.last_revision_info()
450
 
        return result
451
 
 
452
 
 
453
 
class InterGitBranch(branch.GenericInterBranch):
454
 
    """InterBranch implementation that pulls between Git branches."""
455
 
 
456
 
 
457
 
class InterGitLocalRemoteBranch(InterGitBranch):
458
 
    """InterBranch that copies from a local to a remote git branch."""
459
 
 
460
 
    @classmethod
461
 
    def is_compatible(self, source, target):
462
 
        from bzrlib.plugins.git.remote import RemoteGitBranch
463
 
        return (isinstance(source, LocalGitBranch) and
464
 
                isinstance(target, RemoteGitBranch))
465
 
 
466
 
    def _basic_push(self, overwrite=False, stop_revision=None):
467
 
        result = GitBranchPushResult()
468
 
        result.source_branch = self.source
469
 
        result.target_branch = self.target
470
 
        if stop_revision is None:
471
 
            stop_revision = self.source.last_revision()
472
 
        # FIXME: Check for diverged branches
473
 
        def get_changed_refs(old_refs):
474
 
            result.old_revid = self.target.mapping.revision_id_foreign_to_bzr(old_refs.get("refs/heads/master", "0" * 40))
475
 
            refs = { "refs/heads/master": self.source.repository.lookup_bzr_revision_id(stop_revision)[0] }
476
 
            result.new_revid = stop_revision
477
 
            for name, sha in self.source.repository._git.refs.as_dict("refs/tags").iteritems():
478
 
                refs["refs/tags/%s" % name] = sha
479
 
            return refs
480
 
        self.target.repository.send_pack(get_changed_refs,
481
 
                self.source.repository._git.object_store.generate_pack_contents)
482
 
        return result
483
 
 
484
 
 
485
 
class InterGitRemoteLocalBranch(InterGitBranch):
486
 
    """InterBranch that copies from a remote to a local git branch."""
487
 
 
488
 
    @classmethod
489
 
    def is_compatible(self, source, target):
490
 
        from bzrlib.plugins.git.remote import RemoteGitBranch
491
 
        return (isinstance(source, RemoteGitBranch) and
492
 
                isinstance(target, LocalGitBranch))
493
 
 
494
 
    def _basic_push(self, overwrite=False, stop_revision=None):
495
 
        result = branch.BranchPushResult()
496
 
        result.source_branch = self.source
497
 
        result.target_branch = self.target
498
 
        result.old_revid = self.target.last_revision()
499
 
        refs, stop_revision = self.update_refs(stop_revision)
500
 
        self.target.generate_revision_history(stop_revision, result.old_revid)
501
 
        self.update_tags(refs)
502
 
        result.new_revid = self.target.last_revision()
503
 
        return result
504
 
 
505
 
    def update_tags(self, refs):
506
 
        for name, v in extract_tags(refs).iteritems():
507
 
            revid = self.target.mapping.revision_id_foreign_to_bzr(v)
508
 
            self.target.tags.set_tag(name, revid)
509
 
 
510
 
    def update_refs(self, stop_revision=None):
511
 
        interrepo = repository.InterRepository.get(self.source.repository,
512
 
            self.target.repository)
513
 
        if stop_revision is None:
514
 
            refs = interrepo.fetch_refs(branches=["HEAD"])
515
 
            stop_revision = self.target.mapping.revision_id_foreign_to_bzr(refs["HEAD"])
516
 
        else:
517
 
            refs = interrepo.fetch_refs(revision_id=stop_revision)
518
 
        return refs, stop_revision
519
 
 
520
 
    def pull(self, stop_revision=None, overwrite=False,
521
 
        possible_transports=None, local=False):
522
 
        # This type of branch can't be bound.
523
 
        if local:
524
 
            raise errors.LocalRequiresBoundBranch()
525
 
        result = GitPullResult()
526
 
        result.source_branch = self.source
527
 
        result.target_branch = self.target
528
 
        result.old_revid = self.target.last_revision()
529
 
        refs, stop_revision = self.update_refs(stop_revision)
530
 
        self.target.generate_revision_history(stop_revision, result.old_revid)
531
 
        self.update_tags(refs)
532
 
        result.new_revid = self.target.last_revision()
533
 
        return result
534
 
 
535
 
 
536
 
class InterToGitBranch(branch.InterBranch):
537
 
    """InterBranch implementation that pulls from Git into bzr."""
538
 
 
539
 
    @staticmethod
540
 
    def _get_branch_formats_to_test():
541
 
        return None, None
542
 
 
543
 
    @classmethod
544
 
    def is_compatible(self, source, target):
545
 
        return (not isinstance(source, GitBranch) and
546
 
                isinstance(target, GitBranch))
547
 
 
548
 
    def update_revisions(self, *args, **kwargs):
549
 
        raise NoPushSupport()
550
 
 
551
 
    def push(self, overwrite=True, stop_revision=None,
552
 
             _override_hook_source_branch=None):
553
 
        raise NoPushSupport()
554
 
 
555
 
    def lossy_push(self, stop_revision=None):
556
 
        result = GitBranchPushResult()
557
 
        result.source_branch = self.source
558
 
        result.target_branch = self.target
559
 
        try:
560
 
            result.old_revid = self.target.last_revision()
561
 
        except NoSuchRef:
562
 
            result.old_revid = revision.NULL_REVISION
563
 
        if stop_revision is None:
564
 
            stop_revision = self.source.last_revision()
565
 
        # FIXME: Check for diverged branches
566
 
        refs = { "refs/heads/master": stop_revision }
567
 
        for name, revid in self.source.tags.get_tag_dict().iteritems():
568
 
            if self.source.repository.has_revision(revid):
569
 
                refs["refs/tags/%s" % name] = revid
570
 
        revidmap, new_refs = self.target.repository.dfetch_refs(
571
 
            self.source.repository, refs)
572
 
        if revidmap != {}:
573
 
            self.target.generate_revision_history(revidmap[stop_revision])
574
 
            result.new_revid = revidmap[stop_revision]
575
 
        else:
576
 
            result.new_revid = result.old_revid
577
 
        result.revidmap = revidmap
578
 
        return result
579
 
 
580
 
 
581
 
branch.InterBranch.register_optimiser(InterGitRemoteLocalBranch)
582
 
branch.InterBranch.register_optimiser(InterFromGitBranch)
583
 
branch.InterBranch.register_optimiser(InterToGitBranch)
584
 
branch.InterBranch.register_optimiser(InterGitLocalRemoteBranch)
 
104
                                          local=True)