1
# Copyright (C) 2007 Canonical Ltd
2
# Copyright (C) 2009-2010 Jelmer Vernooij <jelmer@samba.org>
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.
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.
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
18
"""An adapter between a Git Branch and a Bazaar Branch"""
20
from collections import defaultdict
22
from dulwich.objects import (
33
repository as _mod_repository,
38
from bzrlib.decorators import (
41
from bzrlib.revision import (
44
from bzrlib.trace import (
49
from bzrlib.plugins.git.config import (
52
from bzrlib.plugins.git.errors import (
56
from bzrlib.plugins.git.refs import (
66
from bzrlib.foreign import ForeignBranch
69
class GitPullResult(branch.PullResult):
70
"""Result of a pull from a Git branch."""
72
def _lookup_revno(self, revid):
73
assert isinstance(revid, str), "was %r" % revid
74
# Try in source branch first, it'll be faster
75
return self.target_branch.revision_id_to_revno(revid)
79
return self._lookup_revno(self.old_revid)
83
return self._lookup_revno(self.new_revid)
86
class GitTags(tag.BasicTags):
87
"""Ref-based tag dictionary."""
89
def __init__(self, branch):
91
self.repository = branch.repository
94
raise NotImplementedError(self.get_refs)
96
def _iter_tag_refs(self, refs):
97
raise NotImplementedError(self._iter_tag_refs)
99
def _merge_to_git(self, to_tags, refs, overwrite=False):
100
target_repo = to_tags.repository
102
for k, v in refs.iteritems():
105
if overwrite or not k in target_repo._git.refs:
106
target_repo._git.refs[k] = v
107
elif target_repo._git.refs[k] == v:
110
conflicts.append((ref_to_tag_name(k), v, target_repo.refs[k]))
113
def _merge_to_non_git(self, to_tags, refs, overwrite=False):
114
unpeeled_map = defaultdict(set)
116
result = dict(to_tags.get_tag_dict())
117
for n, peeled, unpeeled, bzr_revid in self._iter_tag_refs(refs):
118
if unpeeled is not None:
119
unpeeled_map[peeled].add(unpeeled)
120
if n not in result or overwrite:
121
result[n] = bzr_revid
122
elif result[n] == bzr_revid:
125
conflicts.append((n, result[n], bzr_revid))
126
to_tags._set_tag_dict(result)
127
if len(unpeeled_map) > 0:
128
map_file = UnpeelMap.from_repository(to_tags.branch.repository)
129
map_file.update(unpeeled_map)
130
map_file.save_in_repository(to_tags.branch.repository)
133
def merge_to(self, to_tags, overwrite=False, ignore_master=False,
135
"""See Tags.merge_to."""
136
if source_refs is None:
137
source_refs = self.get_refs()
140
if isinstance(to_tags, GitTags):
141
return self._merge_to_git(to_tags, source_refs,
147
master = to_tags.branch.get_master_branch()
148
conflicts = self._merge_to_non_git(to_tags, source_refs,
150
if master is not None:
151
conflicts += self.merge_to(master.tags, overwrite=overwrite,
152
source_refs=source_refs,
153
ignore_master=ignore_master)
156
def get_tag_dict(self):
158
refs = self.get_refs()
159
for (name, peeled, unpeeled, bzr_revid) in self._iter_tag_refs(refs):
160
ret[name] = bzr_revid
164
class LocalGitTagDict(GitTags):
165
"""Dictionary with tags in a local repository."""
167
def __init__(self, branch):
168
super(LocalGitTagDict, self).__init__(branch)
169
self.refs = self.repository._git.refs
172
return self.repository._git.get_refs()
174
def _iter_tag_refs(self, refs):
175
"""Iterate over the tag refs.
177
:param refs: Refs dictionary (name -> git sha1)
178
:return: iterator over (name, peeled_sha1, unpeeled_sha1, bzr_revid)
180
for k, (peeled, unpeeled) in extract_tags(refs).iteritems():
182
obj = self.repository._git[peeled]
184
mutter("Tag %s points at unknown object %s, ignoring", peeled,
187
# FIXME: this shouldn't really be necessary, the repository
188
# already should have these unpeeled.
189
while isinstance(obj, Tag):
190
peeled = obj.object[1]
191
obj = self.repository._git[peeled]
192
if not isinstance(obj, Commit):
193
mutter("Tag %s points at object %r that is not a commit, "
196
yield (k, peeled, unpeeled,
197
self.branch.lookup_foreign_revision_id(peeled))
199
def _set_tag_dict(self, to_dict):
200
extra = set(self.get_refs().keys())
201
for k, revid in to_dict.iteritems():
202
name = tag_name_to_ref(k)
205
self.set_tag(k, revid)
208
del self.repository._git[name]
210
def set_tag(self, name, revid):
211
self.refs[tag_name_to_ref(name)], _ = \
212
self.branch.lookup_bzr_revision_id(revid)
215
class DictTagDict(tag.BasicTags):
217
def __init__(self, branch, tags):
218
super(DictTagDict, self).__init__(branch)
221
def get_tag_dict(self):
225
class GitBranchFormat(branch.BranchFormat):
227
def get_format_description(self):
230
def network_name(self):
233
def supports_tags(self):
236
def supports_leaving_lock(self):
240
def _matchingbzrdir(self):
241
from bzrlib.plugins.git.dir import LocalGitControlDirFormat
242
return LocalGitControlDirFormat()
244
def get_foreign_tests_branch_factory(self):
245
from bzrlib.plugins.git.tests.test_branch import ForeignTestsBranchFactory
246
return ForeignTestsBranchFactory()
248
def make_tags(self, branch):
249
if getattr(branch.repository, "get_refs", None) is not None:
250
from bzrlib.plugins.git.remote import RemoteGitTagDict
251
return RemoteGitTagDict(branch)
253
return LocalGitTagDict(branch)
255
def initialize(self, a_bzrdir, name=None, repository=None):
256
from bzrlib.plugins.git.dir import LocalGitDir
257
if not isinstance(a_bzrdir, LocalGitDir):
258
raise errors.IncompatibleFormat(self, a_bzrdir._format)
259
if repository is None:
260
repository = a_bzrdir.open_repository()
261
ref = branch_name_to_ref(name, "HEAD")
262
repository._git[ref] = ZERO_SHA
263
return LocalGitBranch(a_bzrdir, repository, ref, a_bzrdir._lockfiles)
266
class GitReadLock(object):
268
def __init__(self, unlock):
272
class GitWriteLock(object):
274
def __init__(self, unlock):
275
self.branch_token = None
279
class GitBranch(ForeignBranch):
280
"""An adapter to git repositories for bzr Branch objects."""
283
def control_transport(self):
284
return self.bzrdir.control_transport
286
def __init__(self, bzrdir, repository, ref, lockfiles, tagsdict=None):
287
self.repository = repository
288
self._format = GitBranchFormat()
289
self.control_files = lockfiles
291
super(GitBranch, self).__init__(repository.get_mapping())
292
if tagsdict is not None:
293
self.tags = DictTagDict(self, tagsdict)
295
self.name = ref_to_branch_name(ref)
297
self.base = bzrdir.root_transport.base
299
def _get_checkout_format(self):
300
"""Return the most suitable metadir for a checkout of this branch.
301
Weaves are used if this branch's repository uses weaves.
303
return bzrdir.format_registry.make_bzrdir("default")
305
def get_child_submit_format(self):
306
"""Return the preferred format of submissions to this branch."""
307
ret = self.get_config().get_user_option("child_submit_format")
312
def _get_nick(self, local=False, possible_master_transports=None):
313
"""Find the nick name for this branch.
317
return self.name or "HEAD"
319
def _set_nick(self, nick):
320
raise NotImplementedError
322
nick = property(_get_nick, _set_nick)
325
return "<%s(%r, %r)>" % (self.__class__.__name__, self.repository.base,
328
def generate_revision_history(self, revid, old_revid=None):
329
if revid == NULL_REVISION:
332
# FIXME: Check that old_revid is in the ancestry of revid
333
newhead, self.mapping = self.mapping.revision_id_bzr_to_foreign(revid)
334
self._set_head(newhead)
336
def lock_write(self):
337
self.control_files.lock_write()
338
return GitWriteLock(self.unlock)
340
def get_stacked_on_url(self):
341
# Git doesn't do stacking (yet...)
342
raise errors.UnstackableBranchFormat(self._format, self.base)
344
def get_parent(self):
345
"""See Branch.get_parent()."""
346
# FIXME: Set "origin" url from .git/config ?
349
def set_parent(self, url):
350
# FIXME: Set "origin" url in .git/config ?
354
self.control_files.lock_read()
355
return GitReadLock(self.unlock)
358
return self.control_files.is_locked()
361
self.control_files.unlock()
363
def get_physical_lock_status(self):
367
def last_revision(self):
368
# perhaps should escape this ?
369
if self.head is None:
370
return revision.NULL_REVISION
371
return self.lookup_foreign_revision_id(self.head)
373
def _basic_push(self, target, overwrite=False, stop_revision=None):
374
return branch.InterBranch.get(self, target)._basic_push(
375
overwrite, stop_revision)
377
def lookup_foreign_revision_id(self, foreign_revid):
378
return self.repository.lookup_foreign_revision_id(foreign_revid,
381
def lookup_bzr_revision_id(self, revid):
382
return self.repository.lookup_bzr_revision_id(
383
revid, mapping=self.mapping)
386
class LocalGitBranch(GitBranch):
387
"""A local Git branch."""
389
def __init__(self, bzrdir, repository, ref, lockfiles, tagsdict=None):
390
super(LocalGitBranch, self).__init__(bzrdir, repository, ref,
392
refs = repository._git.get_refs()
393
if not (ref in refs.keys() or "HEAD" in refs.keys()):
394
raise errors.NotBranchError(self.base)
396
def create_checkout(self, to_location, revision_id=None, lightweight=False,
397
accelerator_tree=None, hardlink=False):
399
t = transport.get_transport(to_location)
401
format = self._get_checkout_format()
402
checkout = format.initialize_on_transport(t)
403
from_branch = branch.BranchReferenceFormat().initialize(checkout,
405
tree = checkout.create_workingtree(revision_id,
406
from_branch=from_branch, hardlink=hardlink)
409
return self._create_heavyweight_checkout(to_location, revision_id,
412
def _create_heavyweight_checkout(self, to_location, revision_id=None,
414
"""Create a new heavyweight checkout of this branch.
416
:param to_location: URL of location to create the new checkout in.
417
:param revision_id: Revision that should be the tip of the checkout.
418
:param hardlink: Whether to hardlink
419
:return: WorkingTree object of checkout.
421
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
422
to_location, force_new_tree=False)
423
checkout = checkout_branch.bzrdir
424
checkout_branch.bind(self)
425
# pull up to the specified revision_id to set the initial
426
# branch tip correctly, and seed it with history.
427
checkout_branch.pull(self, stop_revision=revision_id)
428
return checkout.create_workingtree(revision_id, hardlink=hardlink)
430
def _gen_revision_history(self):
431
if self.head is None:
433
ret = list(self.repository.iter_reverse_revision_history(
434
self.last_revision()))
440
return self.repository._git.ref(self.ref or "HEAD")
444
def set_last_revision_info(self, revno, revid):
445
self.set_last_revision(revid)
447
def set_last_revision(self, revid):
448
(newhead, self.mapping) = self.repository.lookup_bzr_revision_id(revid)
451
def _set_head(self, value):
453
self.repository._git.refs[self.ref or "HEAD"] = self._head
454
self._clear_cached_state()
456
head = property(_get_head, _set_head)
458
def get_config(self):
459
return GitBranchConfig(self)
461
def get_push_location(self):
462
"""See Branch.get_push_location."""
463
push_loc = self.get_config().get_user_option('push_location')
466
def set_push_location(self, location):
467
"""See Branch.set_push_location."""
468
self.get_config().set_user_option('push_location', location,
469
store=config.STORE_LOCATION)
471
def supports_tags(self):
475
def _quick_lookup_revno(local_branch, remote_branch, revid):
476
assert isinstance(revid, str), "was %r" % revid
477
# Try in source branch first, it'll be faster
479
return local_branch.revision_id_to_revno(revid)
480
except errors.NoSuchRevision:
481
graph = local_branch.repository.get_graph()
483
return graph.find_distance_to_null(revid)
484
except errors.GhostRevisionsHaveNoRevno:
485
# FIXME: Check using graph.find_distance_to_null() ?
486
return remote_branch.revision_id_to_revno(revid)
489
class GitBranchPullResult(branch.PullResult):
492
super(GitBranchPullResult, self).__init__()
493
self.new_git_head = None
494
self._old_revno = None
495
self._new_revno = None
497
def report(self, to_file):
499
if self.old_revid == self.new_revid:
500
to_file.write('No revisions to pull.\n')
501
elif self.new_git_head is not None:
502
to_file.write('Now on revision %d (git sha: %s).\n' %
503
(self.new_revno, self.new_git_head))
505
to_file.write('Now on revision %d.\n' % (self.new_revno,))
506
self._show_tag_conficts(to_file)
508
def _lookup_revno(self, revid):
509
return _quick_lookup_revno(self.target_branch, self.source_branch,
512
def _get_old_revno(self):
513
if self._old_revno is not None:
514
return self._old_revno
515
return self._lookup_revno(self.old_revid)
517
def _set_old_revno(self, revno):
518
self._old_revno = revno
520
old_revno = property(_get_old_revno, _set_old_revno)
522
def _get_new_revno(self):
523
if self._new_revno is not None:
524
return self._new_revno
525
return self._lookup_revno(self.new_revid)
527
def _set_new_revno(self, revno):
528
self._new_revno = revno
530
new_revno = property(_get_new_revno, _set_new_revno)
533
class GitBranchPushResult(branch.BranchPushResult):
535
def _lookup_revno(self, revid):
536
return _quick_lookup_revno(self.source_branch, self.target_branch,
541
return self._lookup_revno(self.old_revid)
545
new_original_revno = getattr(self, "new_original_revno", None)
546
if new_original_revno:
547
return new_original_revno
548
if getattr(self, "new_original_revid", None) is not None:
549
return self._lookup_revno(self.new_original_revid)
550
return self._lookup_revno(self.new_revid)
553
class InterFromGitBranch(branch.GenericInterBranch):
554
"""InterBranch implementation that pulls from Git into bzr."""
557
def _get_branch_formats_to_test():
559
default_format = branch.format_registry.get_default()
560
except AttributeError:
561
default_format = branch.BranchFormat._default_format
563
(GitBranchFormat(), GitBranchFormat()),
564
(GitBranchFormat(), default_format)]
567
def _get_interrepo(self, source, target):
568
return _mod_repository.InterRepository.get(source.repository, target.repository)
571
def is_compatible(cls, source, target):
572
return (isinstance(source, GitBranch) and
573
not isinstance(target, GitBranch) and
574
(getattr(cls._get_interrepo(source, target), "fetch_objects", None) is not None))
576
def fetch(self, stop_revision=None, fetch_tags=True):
577
self.fetch_objects(stop_revision, fetch_tags=fetch_tags)
579
def fetch_objects(self, stop_revision, fetch_tags):
580
interrepo = self._get_interrepo(self.source, self.target)
581
def determine_wants(heads):
582
if self.source.ref is not None and not self.source.ref in heads:
583
raise NoSuchRef(self.source.ref, heads.keys())
585
if stop_revision is None:
586
if self.source.ref is not None:
587
head = heads[self.source.ref]
590
self._last_revid = self.source.lookup_foreign_revision_id(head)
592
self._last_revid = stop_revision
593
real = interrepo.get_determine_wants_revids(
594
[self._last_revid], include_tags=fetch_tags)
596
pack_hint, head, refs = interrepo.fetch_objects(
597
determine_wants, self.source.mapping)
598
if (pack_hint is not None and
599
self.target.repository._format.pack_compresses):
600
self.target.repository.pack(hint=pack_hint)
603
def update_revisions(self, stop_revision=None, overwrite=False,
605
"""See InterBranch.update_revisions()."""
606
head, refs = self.fetch_objects(stop_revision, fetch_tags=True)
608
prev_last_revid = None
610
prev_last_revid = self.target.last_revision()
611
self.target.generate_revision_history(self._last_revid,
612
prev_last_revid, self.source)
615
def pull(self, overwrite=False, stop_revision=None,
616
possible_transports=None, _hook_master=None, run_hooks=True,
617
_override_hook_target=None, local=False):
620
:param _hook_master: Private parameter - set the branch to
621
be supplied as the master to pull hooks.
622
:param run_hooks: Private parameter - if false, this branch
623
is being called because it's the master of the primary branch,
624
so it should not run its hooks.
625
:param _override_hook_target: Private parameter - set the branch to be
626
supplied as the target_branch to pull hooks.
628
# This type of branch can't be bound.
630
raise errors.LocalRequiresBoundBranch()
631
result = GitBranchPullResult()
632
result.source_branch = self.source
633
if _override_hook_target is None:
634
result.target_branch = self.target
636
result.target_branch = _override_hook_target
637
self.source.lock_read()
639
# We assume that during 'pull' the target repository is closer than
641
graph = self.target.repository.get_graph(self.source.repository)
642
(result.old_revno, result.old_revid) = \
643
self.target.last_revision_info()
644
result.new_git_head, remote_refs = self.update_revisions(
645
stop_revision, overwrite=overwrite, graph=graph)
646
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
648
(result.new_revno, result.new_revid) = \
649
self.target.last_revision_info()
651
result.master_branch = _hook_master
652
result.local_branch = result.target_branch
654
result.master_branch = result.target_branch
655
result.local_branch = None
657
for hook in branch.Branch.hooks['post_pull']:
663
def _basic_push(self, overwrite=False, stop_revision=None):
664
result = branch.BranchPushResult()
665
result.source_branch = self.source
666
result.target_branch = self.target
667
graph = self.target.repository.get_graph(self.source.repository)
668
result.old_revno, result.old_revid = self.target.last_revision_info()
669
result.new_git_head, remote_refs = self.update_revisions(
670
stop_revision, overwrite=overwrite, graph=graph)
671
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
673
result.new_revno, result.new_revid = self.target.last_revision_info()
677
class InterGitBranch(branch.GenericInterBranch):
678
"""InterBranch implementation that pulls between Git branches."""
681
class InterLocalGitRemoteGitBranch(InterGitBranch):
682
"""InterBranch that copies from a local to a remote git branch."""
685
def _get_branch_formats_to_test():
690
def is_compatible(self, source, target):
691
from bzrlib.plugins.git.remote import RemoteGitBranch
692
return (isinstance(source, LocalGitBranch) and
693
isinstance(target, RemoteGitBranch))
695
def _basic_push(self, overwrite=False, stop_revision=None):
696
result = GitBranchPushResult()
697
result.source_branch = self.source
698
result.target_branch = self.target
699
if stop_revision is None:
700
stop_revision = self.source.last_revision()
701
# FIXME: Check for diverged branches
702
def get_changed_refs(old_refs):
703
result.old_revid = self.target.lookup_foreign_revision_id(old_refs.get(self.target.ref, ZERO_SHA))
704
refs = { self.target.ref: self.source.repository.lookup_bzr_revision_id(stop_revision)[0] }
705
result.new_revid = stop_revision
706
for name, sha in self.source.repository._git.refs.as_dict("refs/tags").iteritems():
707
refs[tag_name_to_ref(name)] = sha
709
self.target.repository.send_pack(get_changed_refs,
710
self.source.repository._git.object_store.generate_pack_contents)
714
class InterGitLocalGitBranch(InterGitBranch):
715
"""InterBranch that copies from a remote to a local git branch."""
718
def _get_branch_formats_to_test():
723
def is_compatible(self, source, target):
724
return (isinstance(source, GitBranch) and
725
isinstance(target, LocalGitBranch))
727
def _basic_push(self, overwrite=False, stop_revision=None):
728
result = branch.BranchPushResult()
729
result.source_branch = self.source
730
result.target_branch = self.target
731
result.old_revid = self.target.last_revision()
732
refs, stop_revision = self.update_refs(stop_revision)
733
self.target.generate_revision_history(stop_revision, result.old_revid)
734
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
735
source_refs=refs, overwrite=overwrite)
736
result.new_revid = self.target.last_revision()
739
def update_refs(self, stop_revision=None):
740
interrepo = _mod_repository.InterRepository.get(self.source.repository,
741
self.target.repository)
742
if stop_revision is None:
743
refs = interrepo.fetch(branches=["HEAD"])
744
stop_revision = self.target.lookup_foreign_revision_id(refs["HEAD"])
746
refs = interrepo.fetch(revision_id=stop_revision)
747
return refs, stop_revision
749
def pull(self, stop_revision=None, overwrite=False,
750
possible_transports=None, run_hooks=True,local=False):
751
# This type of branch can't be bound.
753
raise errors.LocalRequiresBoundBranch()
754
result = GitPullResult()
755
result.source_branch = self.source
756
result.target_branch = self.target
757
result.old_revid = self.target.last_revision()
758
refs, stop_revision = self.update_refs(stop_revision)
759
self.target.generate_revision_history(stop_revision, result.old_revid)
760
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
761
overwrite=overwrite, source_refs=refs)
762
result.new_revid = self.target.last_revision()
766
class InterToGitBranch(branch.GenericInterBranch):
767
"""InterBranch implementation that pulls into a Git branch."""
769
def __init__(self, source, target):
770
super(InterToGitBranch, self).__init__(source, target)
771
self.interrepo = _mod_repository.InterRepository.get(source.repository,
775
def _get_branch_formats_to_test():
777
default_format = branch.format_registry.get_default()
778
except AttributeError:
779
default_format = branch.BranchFormat._default_format
780
return [(default_format, GitBranchFormat())]
783
def is_compatible(self, source, target):
784
return (not isinstance(source, GitBranch) and
785
isinstance(target, GitBranch))
787
def update_revisions(self, *args, **kwargs):
788
raise NoPushSupport()
790
def _get_new_refs(self, stop_revision=None):
791
if stop_revision is None:
792
(stop_revno, stop_revision) = self.source.last_revision_info()
794
stop_revno = self.source.revision_id_to_revno(stop_revision)
795
assert type(stop_revision) is str
796
main_ref = self.target.ref or "refs/heads/master"
797
refs = { main_ref: (None, stop_revision) }
798
for name, revid in self.source.tags.get_tag_dict().iteritems():
799
if self.source.repository.has_revision(revid):
800
refs[tag_name_to_ref(name)] = (None, revid)
801
return refs, main_ref, (stop_revno, stop_revision)
803
def pull(self, overwrite=False, stop_revision=None, local=False,
804
possible_transports=None, run_hooks=True):
805
result = GitBranchPullResult()
806
result.source_branch = self.source
807
result.target_branch = self.target
808
new_refs, main_ref, stop_revinfo = self._get_new_refs(stop_revision)
809
def update_refs(old_refs):
810
refs = dict(old_refs)
811
# FIXME: Check for diverged branches
812
refs.update(new_refs)
815
old_refs, new_refs = self.interrepo.fetch_refs(update_refs)
816
except NoPushSupport:
817
raise errors.NoRoundtrippingSupport(self.source, self.target)
818
(result.old_revid, old_sha1) = old_refs.get(main_ref, (ZERO_SHA, NULL_REVISION))
819
if result.old_revid is None:
820
result.old_revid = self.target.lookup_foreign_revision_id(old_sha1)
821
result.new_revid = new_refs[main_ref][1]
824
def push(self, overwrite=False, stop_revision=None,
825
_override_hook_source_branch=None):
826
result = GitBranchPushResult()
827
result.source_branch = self.source
828
result.target_branch = self.target
829
new_refs, main_ref, stop_revinfo = self._get_new_refs(stop_revision)
830
def update_refs(old_refs):
831
refs = dict(old_refs)
832
# FIXME: Check for diverged branches
833
refs.update(new_refs)
836
old_refs, new_refs = self.interrepo.fetch_refs(update_refs)
837
except NoPushSupport:
838
raise errors.NoRoundtrippingSupport(self.source, self.target)
839
(result.old_revid, old_sha1) = old_refs.get(main_ref, (ZERO_SHA, NULL_REVISION))
840
if result.old_revid is None:
841
result.old_revid = self.target.lookup_foreign_revision_id(old_sha1)
842
result.new_revid = new_refs[main_ref][1]
845
def lossy_push(self, stop_revision=None):
846
result = GitBranchPushResult()
847
result.source_branch = self.source
848
result.target_branch = self.target
849
new_refs, main_ref, stop_revinfo = self._get_new_refs(stop_revision)
850
def update_refs(old_refs):
851
refs = dict(old_refs)
852
# FIXME: Check for diverged branches
853
refs.update(new_refs)
855
result.revidmap, old_refs, new_refs = self.interrepo.dfetch_refs(
857
result.old_revid = old_refs.get(self.target.ref, (None, NULL_REVISION))[1]
858
result.new_revid = new_refs[main_ref][1]
859
(result.new_original_revno, result.new_original_revid) = stop_revinfo
863
branch.InterBranch.register_optimiser(InterGitLocalGitBranch)
864
branch.InterBranch.register_optimiser(InterFromGitBranch)
865
branch.InterBranch.register_optimiser(InterToGitBranch)
866
branch.InterBranch.register_optimiser(InterLocalGitRemoteGitBranch)