/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

Cope with open_branch() actually checking whether there is a branch present.

Show diffs side-by-side

added added

removed removed

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