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, revid)
511
def _get_old_revno(self):
512
if self._old_revno is not None:
513
return self._old_revno
514
return self._lookup_revno(self.old_revid)
516
def _set_old_revno(self, revno):
517
self._old_revno = revno
519
old_revno = property(_get_old_revno, _set_old_revno)
521
def _get_new_revno(self):
522
if self._new_revno is not None:
523
return self._new_revno
524
return self._lookup_revno(self.new_revid)
526
def _set_new_revno(self, revno):
527
self._new_revno = revno
529
new_revno = property(_get_new_revno, _set_new_revno)
532
class GitBranchPushResult(branch.BranchPushResult):
534
def _lookup_revno(self, revid):
535
return _quick_lookup_revno(self.source_branch, self.target_branch, revid)
539
return self._lookup_revno(self.old_revid)
543
new_original_revno = getattr(self, "new_original_revno", None)
544
if new_original_revno:
545
return new_original_revno
546
if getattr(self, "new_original_revid", None) is not None:
547
return self._lookup_revno(self.new_original_revid)
548
return self._lookup_revno(self.new_revid)
551
class InterFromGitBranch(branch.GenericInterBranch):
552
"""InterBranch implementation that pulls from Git into bzr."""
555
def _get_branch_formats_to_test():
557
default_format = branch.format_registry.get_default()
558
except AttributeError:
559
default_format = branch.BranchFormat._default_format
561
(GitBranchFormat(), GitBranchFormat()),
562
(GitBranchFormat(), default_format)]
565
def _get_interrepo(self, source, target):
566
return _mod_repository.InterRepository.get(source.repository, target.repository)
569
def is_compatible(cls, source, target):
570
return (isinstance(source, GitBranch) and
571
not isinstance(target, GitBranch) and
572
(getattr(cls._get_interrepo(source, target), "fetch_objects", None) is not None))
574
def fetch(self, stop_revision=None, fetch_tags=True):
575
self.fetch_objects(stop_revision, fetch_tags=fetch_tags)
577
def fetch_objects(self, stop_revision, fetch_tags):
578
interrepo = self._get_interrepo(self.source, self.target)
579
def determine_wants(heads):
580
if self.source.ref is not None and not self.source.ref in heads:
581
raise NoSuchRef(self.source.ref, heads.keys())
583
if stop_revision is None:
584
if self.source.ref is not None:
585
head = heads[self.source.ref]
588
self._last_revid = self.source.lookup_foreign_revision_id(head)
590
self._last_revid = stop_revision
591
real = interrepo.get_determine_wants_revids(
592
[self._last_revid], include_tags=fetch_tags)
594
pack_hint, head, refs = interrepo.fetch_objects(
595
determine_wants, self.source.mapping)
596
if (pack_hint is not None and
597
self.target.repository._format.pack_compresses):
598
self.target.repository.pack(hint=pack_hint)
601
def update_revisions(self, stop_revision=None, overwrite=False,
603
"""See InterBranch.update_revisions()."""
604
head, refs = self.fetch_objects(stop_revision, fetch_tags=True)
606
prev_last_revid = None
608
prev_last_revid = self.target.last_revision()
609
self.target.generate_revision_history(self._last_revid,
610
prev_last_revid, self.source)
613
def pull(self, overwrite=False, stop_revision=None,
614
possible_transports=None, _hook_master=None, run_hooks=True,
615
_override_hook_target=None, local=False):
618
:param _hook_master: Private parameter - set the branch to
619
be supplied as the master to pull hooks.
620
:param run_hooks: Private parameter - if false, this branch
621
is being called because it's the master of the primary branch,
622
so it should not run its hooks.
623
:param _override_hook_target: Private parameter - set the branch to be
624
supplied as the target_branch to pull hooks.
626
# This type of branch can't be bound.
628
raise errors.LocalRequiresBoundBranch()
629
result = GitBranchPullResult()
630
result.source_branch = self.source
631
if _override_hook_target is None:
632
result.target_branch = self.target
634
result.target_branch = _override_hook_target
635
self.source.lock_read()
637
# We assume that during 'pull' the target repository is closer than
639
graph = self.target.repository.get_graph(self.source.repository)
640
(result.old_revno, result.old_revid) = \
641
self.target.last_revision_info()
642
result.new_git_head, remote_refs = self.update_revisions(
643
stop_revision, overwrite=overwrite, graph=graph)
644
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
646
(result.new_revno, result.new_revid) = \
647
self.target.last_revision_info()
649
result.master_branch = _hook_master
650
result.local_branch = result.target_branch
652
result.master_branch = result.target_branch
653
result.local_branch = None
655
for hook in branch.Branch.hooks['post_pull']:
661
def _basic_push(self, overwrite=False, stop_revision=None):
662
result = branch.BranchPushResult()
663
result.source_branch = self.source
664
result.target_branch = self.target
665
graph = self.target.repository.get_graph(self.source.repository)
666
result.old_revno, result.old_revid = self.target.last_revision_info()
667
result.new_git_head, remote_refs = self.update_revisions(
668
stop_revision, overwrite=overwrite, graph=graph)
669
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
671
result.new_revno, result.new_revid = self.target.last_revision_info()
675
class InterGitBranch(branch.GenericInterBranch):
676
"""InterBranch implementation that pulls between Git branches."""
679
class InterLocalGitRemoteGitBranch(InterGitBranch):
680
"""InterBranch that copies from a local to a remote git branch."""
683
def _get_branch_formats_to_test():
688
def is_compatible(self, source, target):
689
from bzrlib.plugins.git.remote import RemoteGitBranch
690
return (isinstance(source, LocalGitBranch) and
691
isinstance(target, RemoteGitBranch))
693
def _basic_push(self, overwrite=False, stop_revision=None):
694
result = GitBranchPushResult()
695
result.source_branch = self.source
696
result.target_branch = self.target
697
if stop_revision is None:
698
stop_revision = self.source.last_revision()
699
# FIXME: Check for diverged branches
700
def get_changed_refs(old_refs):
701
result.old_revid = self.target.lookup_foreign_revision_id(old_refs.get(self.target.ref, ZERO_SHA))
702
refs = { self.target.ref: self.source.repository.lookup_bzr_revision_id(stop_revision)[0] }
703
result.new_revid = stop_revision
704
for name, sha in self.source.repository._git.refs.as_dict("refs/tags").iteritems():
705
refs[tag_name_to_ref(name)] = sha
707
self.target.repository.send_pack(get_changed_refs,
708
self.source.repository._git.object_store.generate_pack_contents)
712
class InterGitLocalGitBranch(InterGitBranch):
713
"""InterBranch that copies from a remote to a local git branch."""
716
def _get_branch_formats_to_test():
721
def is_compatible(self, source, target):
722
return (isinstance(source, GitBranch) and
723
isinstance(target, LocalGitBranch))
725
def _basic_push(self, overwrite=False, stop_revision=None):
726
result = branch.BranchPushResult()
727
result.source_branch = self.source
728
result.target_branch = self.target
729
result.old_revid = self.target.last_revision()
730
refs, stop_revision = self.update_refs(stop_revision)
731
self.target.generate_revision_history(stop_revision, result.old_revid)
732
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
733
source_refs=refs, overwrite=overwrite)
734
result.new_revid = self.target.last_revision()
737
def update_refs(self, stop_revision=None):
738
interrepo = _mod_repository.InterRepository.get(self.source.repository,
739
self.target.repository)
740
if stop_revision is None:
741
refs = interrepo.fetch(branches=["HEAD"])
742
stop_revision = self.target.lookup_foreign_revision_id(refs["HEAD"])
744
refs = interrepo.fetch(revision_id=stop_revision)
745
return refs, stop_revision
747
def pull(self, stop_revision=None, overwrite=False,
748
possible_transports=None, run_hooks=True,local=False):
749
# This type of branch can't be bound.
751
raise errors.LocalRequiresBoundBranch()
752
result = GitPullResult()
753
result.source_branch = self.source
754
result.target_branch = self.target
755
result.old_revid = self.target.last_revision()
756
refs, stop_revision = self.update_refs(stop_revision)
757
self.target.generate_revision_history(stop_revision, result.old_revid)
758
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
759
overwrite=overwrite, source_refs=refs)
760
result.new_revid = self.target.last_revision()
764
class InterToGitBranch(branch.GenericInterBranch):
765
"""InterBranch implementation that pulls from Git into bzr."""
767
def __init__(self, source, target):
768
super(InterToGitBranch, self).__init__(source, target)
769
self.interrepo = _mod_repository.InterRepository.get(source.repository,
773
def _get_branch_formats_to_test():
775
default_format = branch.format_registry.get_default()
776
except AttributeError:
777
default_format = branch.BranchFormat._default_format
778
return [(default_format, GitBranchFormat())]
781
def is_compatible(self, source, target):
782
return (not isinstance(source, GitBranch) and
783
isinstance(target, GitBranch))
785
def update_revisions(self, *args, **kwargs):
786
raise NoPushSupport()
788
def _get_new_refs(self, stop_revision=None):
789
if stop_revision is None:
790
(stop_revno, stop_revision) = self.source.last_revision_info()
791
assert type(stop_revision) is str
792
main_ref = self.target.ref or "refs/heads/master"
793
refs = { main_ref: (None, stop_revision) }
794
for name, revid in self.source.tags.get_tag_dict().iteritems():
795
if self.source.repository.has_revision(revid):
796
refs[tag_name_to_ref(name)] = (None, revid)
797
return refs, main_ref, (stop_revno, stop_revision)
799
def pull(self, overwrite=False, stop_revision=None, local=False,
800
possible_transports=None, run_hooks=True):
801
result = GitBranchPullResult()
802
result.source_branch = self.source
803
result.target_branch = self.target
804
new_refs, main_ref, stop_revinfo = self._get_new_refs(stop_revision)
805
def update_refs(old_refs):
806
refs = dict(old_refs)
807
# FIXME: Check for diverged branches
808
refs.update(new_refs)
811
old_refs, new_refs = self.interrepo.fetch_refs(update_refs)
812
except NoPushSupport:
813
raise errors.NoRoundtrippingSupport(self.source, self.target)
814
(result.old_revid, old_sha1) = old_refs.get(main_ref, (ZERO_SHA, NULL_REVISION))
815
if result.old_revid is None:
816
result.old_revid = self.target.lookup_foreign_revision_id(old_sha1)
817
result.new_revid = new_refs[main_ref][1]
820
def push(self, overwrite=False, stop_revision=None,
821
_override_hook_source_branch=None):
822
result = GitBranchPushResult()
823
result.source_branch = self.source
824
result.target_branch = self.target
825
new_refs, main_ref, stop_revinfo = self._get_new_refs(stop_revision)
826
def update_refs(old_refs):
827
refs = dict(old_refs)
828
# FIXME: Check for diverged branches
829
refs.update(new_refs)
832
old_refs, new_refs = self.interrepo.fetch_refs(update_refs)
833
except NoPushSupport:
834
raise errors.NoRoundtrippingSupport(self.source, self.target)
835
(result.old_revid, old_sha1) = old_refs.get(main_ref, (ZERO_SHA, NULL_REVISION))
836
if result.old_revid is None:
837
result.old_revid = self.target.lookup_foreign_revision_id(old_sha1)
838
result.new_revid = new_refs[main_ref][1]
841
def lossy_push(self, stop_revision=None):
842
result = GitBranchPushResult()
843
result.source_branch = self.source
844
result.target_branch = self.target
845
new_refs, main_ref, stop_revinfo = self._get_new_refs(stop_revision)
846
def update_refs(old_refs):
847
refs = dict(old_refs)
848
# FIXME: Check for diverged branches
849
refs.update(new_refs)
851
result.revidmap, old_refs, new_refs = self.interrepo.dfetch_refs(
853
result.old_revid = old_refs.get(self.target.ref, (None, NULL_REVISION))[1]
854
result.new_revid = new_refs[main_ref][1]
855
(result.new_original_revno, result.new_original_revid) = stop_revinfo
859
branch.InterBranch.register_optimiser(InterGitLocalGitBranch)
860
branch.InterBranch.register_optimiser(InterFromGitBranch)
861
branch.InterBranch.register_optimiser(InterToGitBranch)
862
branch.InterBranch.register_optimiser(InterLocalGitRemoteGitBranch)