/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

update copyright years

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