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 (
64
from bzrlib.plugins.git.unpeel_map import (
68
from bzrlib.foreign import ForeignBranch
71
class GitPullResult(branch.PullResult):
72
"""Result of a pull from a Git branch."""
74
def _lookup_revno(self, revid):
75
assert isinstance(revid, str), "was %r" % revid
76
# Try in source branch first, it'll be faster
77
return self.target_branch.revision_id_to_revno(revid)
81
return self._lookup_revno(self.old_revid)
85
return self._lookup_revno(self.new_revid)
88
class GitTags(tag.BasicTags):
89
"""Ref-based tag dictionary."""
91
def __init__(self, branch):
93
self.repository = branch.repository
96
raise NotImplementedError(self.get_refs)
98
def _iter_tag_refs(self, refs):
99
raise NotImplementedError(self._iter_tag_refs)
101
def _merge_to_git(self, to_tags, refs, overwrite=False):
102
target_repo = to_tags.repository
104
for k, v in refs.iteritems():
107
if overwrite or not k in target_repo._git.refs:
108
target_repo._git.refs[k] = v
109
elif target_repo._git.refs[k] == v:
112
conflicts.append((ref_to_tag_name(k), v, target_repo.refs[k]))
115
def _merge_to_non_git(self, to_tags, refs, overwrite=False):
116
unpeeled_map = defaultdict(set)
118
result = dict(to_tags.get_tag_dict())
119
for n, peeled, unpeeled, bzr_revid in self._iter_tag_refs(refs):
120
if unpeeled is not None:
121
unpeeled_map[peeled].add(unpeeled)
122
if n not in result or overwrite:
123
result[n] = bzr_revid
124
elif result[n] == bzr_revid:
127
conflicts.append((n, result[n], bzr_revid))
128
to_tags._set_tag_dict(result)
129
if len(unpeeled_map) > 0:
130
map_file = UnpeelMap.from_repository(to_tags.branch.repository)
131
map_file.update(unpeeled_map)
132
map_file.save_in_repository(to_tags.branch.repository)
135
def merge_to(self, to_tags, overwrite=False, ignore_master=False,
137
"""See Tags.merge_to."""
138
if source_refs is None:
139
source_refs = self.get_refs()
142
if isinstance(to_tags, GitTags):
143
return self._merge_to_git(to_tags, source_refs,
149
master = to_tags.branch.get_master_branch()
150
conflicts = self._merge_to_non_git(to_tags, source_refs,
152
if master is not None:
153
conflicts += self.merge_to(master.tags, overwrite=overwrite,
154
source_refs=source_refs,
155
ignore_master=ignore_master)
158
def get_tag_dict(self):
160
refs = self.get_refs()
161
for (name, peeled, unpeeled, bzr_revid) in self._iter_tag_refs(refs):
162
ret[name] = bzr_revid
166
class LocalGitTagDict(GitTags):
167
"""Dictionary with tags in a local repository."""
169
def __init__(self, branch):
170
super(LocalGitTagDict, self).__init__(branch)
171
self.refs = self.repository._git.refs
174
return self.repository._git.get_refs()
176
def _iter_tag_refs(self, refs):
177
"""Iterate over the tag refs.
179
:param refs: Refs dictionary (name -> git sha1)
180
:return: iterator over (name, peeled_sha1, unpeeled_sha1, bzr_revid)
182
for k, (peeled, unpeeled) in extract_tags(refs).iteritems():
184
obj = self.repository._git[peeled]
186
mutter("Tag %s points at unknown object %s, ignoring", peeled,
189
# FIXME: this shouldn't really be necessary, the repository
190
# already should have these unpeeled.
191
while isinstance(obj, Tag):
192
peeled = obj.object[1]
193
obj = self.repository._git[peeled]
194
if not isinstance(obj, Commit):
195
mutter("Tag %s points at object %r that is not a commit, "
198
yield (k, peeled, unpeeled,
199
self.branch.lookup_foreign_revision_id(peeled))
201
def _set_tag_dict(self, to_dict):
202
extra = set(self.get_refs().keys())
203
for k, revid in to_dict.iteritems():
204
name = tag_name_to_ref(k)
207
self.set_tag(k, revid)
210
del self.repository._git[name]
212
def set_tag(self, name, revid):
213
self.refs[tag_name_to_ref(name)], _ = \
214
self.branch.lookup_bzr_revision_id(revid)
217
class DictTagDict(tag.BasicTags):
219
def __init__(self, branch, tags):
220
super(DictTagDict, self).__init__(branch)
223
def get_tag_dict(self):
227
class GitBranchFormat(branch.BranchFormat):
229
def get_format_description(self):
232
def network_name(self):
235
def supports_tags(self):
238
def supports_leaving_lock(self):
242
def _matchingbzrdir(self):
243
from bzrlib.plugins.git.dir import LocalGitControlDirFormat
244
return LocalGitControlDirFormat()
246
def get_foreign_tests_branch_factory(self):
247
from bzrlib.plugins.git.tests.test_branch import ForeignTestsBranchFactory
248
return ForeignTestsBranchFactory()
250
def make_tags(self, branch):
251
if getattr(branch.repository, "get_refs", None) is not None:
252
from bzrlib.plugins.git.remote import RemoteGitTagDict
253
return RemoteGitTagDict(branch)
255
return LocalGitTagDict(branch)
257
def initialize(self, a_bzrdir, name=None, repository=None):
258
from bzrlib.plugins.git.dir import LocalGitDir
259
if not isinstance(a_bzrdir, LocalGitDir):
260
raise errors.IncompatibleFormat(self, a_bzrdir._format)
261
if repository is None:
262
repository = a_bzrdir.open_repository()
263
ref = branch_name_to_ref(name, "HEAD")
264
repository._git[ref] = ZERO_SHA
265
return LocalGitBranch(a_bzrdir, repository, ref, a_bzrdir._lockfiles)
268
class GitReadLock(object):
270
def __init__(self, unlock):
274
class GitWriteLock(object):
276
def __init__(self, unlock):
277
self.branch_token = None
281
class GitBranch(ForeignBranch):
282
"""An adapter to git repositories for bzr Branch objects."""
285
def control_transport(self):
286
return self.bzrdir.control_transport
288
def __init__(self, bzrdir, repository, ref, lockfiles, tagsdict=None):
289
self.base = bzrdir.root_transport.base
290
self.repository = repository
291
self._format = GitBranchFormat()
292
self.control_files = lockfiles
294
self._lock_mode = None
296
super(GitBranch, self).__init__(repository.get_mapping())
297
if tagsdict is not None:
298
self.tags = DictTagDict(self, tagsdict)
300
self.name = ref_to_branch_name(ref)
303
def _get_checkout_format(self):
304
"""Return the most suitable metadir for a checkout of this branch.
305
Weaves are used if this branch's repository uses weaves.
307
return bzrdir.format_registry.make_bzrdir("default")
309
def get_child_submit_format(self):
310
"""Return the preferred format of submissions to this branch."""
311
ret = self.get_config().get_user_option("child_submit_format")
316
def _get_nick(self, local=False, possible_master_transports=None):
317
"""Find the nick name for this branch.
321
return self.name or "HEAD"
323
def _set_nick(self, nick):
324
raise NotImplementedError
326
nick = property(_get_nick, _set_nick)
329
return "<%s(%r, %r)>" % (self.__class__.__name__, self.repository.base,
332
def generate_revision_history(self, revid, old_revid=None):
333
if revid == NULL_REVISION:
336
# FIXME: Check that old_revid is in the ancestry of revid
337
newhead, self.mapping = self.mapping.revision_id_bzr_to_foreign(revid)
338
if self.mapping is None:
340
self._set_head(newhead)
342
def lock_write(self, token=None):
343
if token is not None:
344
raise errors.TokenLockingNotSupported(self)
346
assert self._lock_mode == 'w'
347
self._lock_count += 1
349
self._lock_mode = 'w'
351
self.repository.lock_write()
352
return GitWriteLock(self.unlock)
354
def get_stacked_on_url(self):
355
# Git doesn't do stacking (yet...)
356
raise errors.UnstackableBranchFormat(self._format, self.base)
358
def get_parent(self):
359
"""See Branch.get_parent()."""
360
# FIXME: Set "origin" url from .git/config ?
363
def set_parent(self, url):
364
# FIXME: Set "origin" url in .git/config ?
369
assert self._lock_mode in ('r', 'w')
370
self._lock_count += 1
372
self._lock_mode = 'r'
374
self.repository.lock_read()
375
return GitReadLock(self.unlock)
377
def peek_lock_mode(self):
378
return self._lock_mode
381
return (self._lock_mode is not None)
384
"""See Branch.unlock()."""
385
self._lock_count -= 1
386
if self._lock_count == 0:
387
self._lock_mode = None
388
self._clear_cached_state()
389
self.repository.unlock()
391
def get_physical_lock_status(self):
395
def last_revision(self):
396
# perhaps should escape this ?
397
if self.head is None:
398
return revision.NULL_REVISION
399
return self.lookup_foreign_revision_id(self.head)
401
def _basic_push(self, target, overwrite=False, stop_revision=None):
402
return branch.InterBranch.get(self, target)._basic_push(
403
overwrite, stop_revision)
405
def lookup_foreign_revision_id(self, foreign_revid):
406
return self.repository.lookup_foreign_revision_id(foreign_revid,
409
def lookup_bzr_revision_id(self, revid):
410
return self.repository.lookup_bzr_revision_id(
411
revid, mapping=self.mapping)
414
class LocalGitBranch(GitBranch):
415
"""A local Git branch."""
417
def __init__(self, bzrdir, repository, ref, lockfiles, tagsdict=None):
418
super(LocalGitBranch, self).__init__(bzrdir, repository, ref,
420
refs = repository._git.get_refs()
421
if not (ref in refs.keys() or "HEAD" in refs.keys()):
422
raise errors.NotBranchError(self.base)
424
def create_checkout(self, to_location, revision_id=None, lightweight=False,
425
accelerator_tree=None, hardlink=False):
427
t = transport.get_transport(to_location)
429
format = self._get_checkout_format()
430
checkout = format.initialize_on_transport(t)
431
from_branch = branch.BranchReferenceFormat().initialize(checkout,
433
tree = checkout.create_workingtree(revision_id,
434
from_branch=from_branch, hardlink=hardlink)
437
return self._create_heavyweight_checkout(to_location, revision_id,
440
def _create_heavyweight_checkout(self, to_location, revision_id=None,
442
"""Create a new heavyweight checkout of this branch.
444
:param to_location: URL of location to create the new checkout in.
445
:param revision_id: Revision that should be the tip of the checkout.
446
:param hardlink: Whether to hardlink
447
:return: WorkingTree object of checkout.
449
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
450
to_location, force_new_tree=False)
451
checkout = checkout_branch.bzrdir
452
checkout_branch.bind(self)
453
# pull up to the specified revision_id to set the initial
454
# branch tip correctly, and seed it with history.
455
checkout_branch.pull(self, stop_revision=revision_id)
456
return checkout.create_workingtree(revision_id, hardlink=hardlink)
458
def _gen_revision_history(self):
459
if self.head is None:
461
graph = self.repository.get_graph()
462
ret = list(graph.iter_lefthand_ancestry(self.last_revision(),
463
(revision.NULL_REVISION, )))
469
return self.repository._git.ref(self.ref or "HEAD")
473
def _read_last_revision_info(self):
474
last_revid = self.last_revision()
475
graph = self.repository.get_graph()
476
revno = graph.find_distance_to_null(last_revid,
477
[(revision.NULL_REVISION, 0)])
478
return revno, last_revid
480
def set_last_revision_info(self, revno, revision_id):
481
self.set_last_revision(revision_id)
482
self._last_revision_info_cache = revno, revision_id
484
def set_last_revision(self, revid):
485
if not revid or not isinstance(revid, basestring):
486
raise errors.InvalidRevisionId(revision_id=revid, branch=self)
487
if revid == NULL_REVISION:
490
(newhead, self.mapping) = self.repository.lookup_bzr_revision_id(revid)
491
if self.mapping is None:
493
self._set_head(newhead)
495
def _set_head(self, value):
497
self.repository._git.refs[self.ref or "HEAD"] = self._head
498
self._clear_cached_state()
500
head = property(_get_head, _set_head)
502
def get_config(self):
503
return GitBranchConfig(self)
505
def get_push_location(self):
506
"""See Branch.get_push_location."""
507
push_loc = self.get_config().get_user_option('push_location')
510
def set_push_location(self, location):
511
"""See Branch.set_push_location."""
512
self.get_config().set_user_option('push_location', location,
513
store=config.STORE_LOCATION)
515
def supports_tags(self):
519
def _quick_lookup_revno(local_branch, remote_branch, revid):
520
assert isinstance(revid, str), "was %r" % revid
521
# Try in source branch first, it'll be faster
523
return local_branch.revision_id_to_revno(revid)
524
except errors.NoSuchRevision:
525
graph = local_branch.repository.get_graph()
527
return graph.find_distance_to_null(revid)
528
except errors.GhostRevisionsHaveNoRevno:
529
# FIXME: Check using graph.find_distance_to_null() ?
530
return remote_branch.revision_id_to_revno(revid)
533
class GitBranchPullResult(branch.PullResult):
536
super(GitBranchPullResult, self).__init__()
537
self.new_git_head = None
538
self._old_revno = None
539
self._new_revno = None
541
def report(self, to_file):
543
if self.old_revid == self.new_revid:
544
to_file.write('No revisions to pull.\n')
545
elif self.new_git_head is not None:
546
to_file.write('Now on revision %d (git sha: %s).\n' %
547
(self.new_revno, self.new_git_head))
549
to_file.write('Now on revision %d.\n' % (self.new_revno,))
550
self._show_tag_conficts(to_file)
552
def _lookup_revno(self, revid):
553
return _quick_lookup_revno(self.target_branch, self.source_branch,
556
def _get_old_revno(self):
557
if self._old_revno is not None:
558
return self._old_revno
559
return self._lookup_revno(self.old_revid)
561
def _set_old_revno(self, revno):
562
self._old_revno = revno
564
old_revno = property(_get_old_revno, _set_old_revno)
566
def _get_new_revno(self):
567
if self._new_revno is not None:
568
return self._new_revno
569
return self._lookup_revno(self.new_revid)
571
def _set_new_revno(self, revno):
572
self._new_revno = revno
574
new_revno = property(_get_new_revno, _set_new_revno)
577
class GitBranchPushResult(branch.BranchPushResult):
579
def _lookup_revno(self, revid):
580
return _quick_lookup_revno(self.source_branch, self.target_branch,
585
return self._lookup_revno(self.old_revid)
589
new_original_revno = getattr(self, "new_original_revno", None)
590
if new_original_revno:
591
return new_original_revno
592
if getattr(self, "new_original_revid", None) is not None:
593
return self._lookup_revno(self.new_original_revid)
594
return self._lookup_revno(self.new_revid)
597
class InterFromGitBranch(branch.GenericInterBranch):
598
"""InterBranch implementation that pulls from Git into bzr."""
601
def _get_branch_formats_to_test():
603
default_format = branch.format_registry.get_default()
604
except AttributeError:
605
default_format = branch.BranchFormat._default_format
607
(GitBranchFormat(), GitBranchFormat()),
608
(GitBranchFormat(), default_format)]
611
def _get_interrepo(self, source, target):
612
return _mod_repository.InterRepository.get(source.repository, target.repository)
615
def is_compatible(cls, source, target):
616
if not isinstance(source, GitBranch):
618
if isinstance(target, GitBranch):
619
# InterLocalGitRemoteGitBranch or InterToGitBranch should be used
621
if getattr(cls._get_interrepo(source, target), "fetch_objects", None) is None:
622
# fetch_objects is necessary for this to work
626
def fetch(self, stop_revision=None, fetch_tags=True, limit=None):
627
self.fetch_objects(stop_revision, fetch_tags=fetch_tags, limit=limit)
629
def fetch_objects(self, stop_revision, fetch_tags, limit=None):
630
interrepo = self._get_interrepo(self.source, self.target)
631
def determine_wants(heads):
632
if self.source.ref is not None and not self.source.ref in heads:
633
raise NoSuchRef(self.source.ref, heads.keys())
635
if stop_revision is None:
636
if self.source.ref is not None:
637
head = heads[self.source.ref]
640
self._last_revid = self.source.lookup_foreign_revision_id(head)
642
self._last_revid = stop_revision
643
real = interrepo.get_determine_wants_revids(
644
[self._last_revid], include_tags=fetch_tags)
646
pack_hint, head, refs = interrepo.fetch_objects(
647
determine_wants, self.source.mapping, limit=limit)
648
if (pack_hint is not None and
649
self.target.repository._format.pack_compresses):
650
self.target.repository.pack(hint=pack_hint)
653
def _update_revisions(self, stop_revision=None, overwrite=False):
654
head, refs = self.fetch_objects(stop_revision, fetch_tags=True)
656
prev_last_revid = None
658
prev_last_revid = self.target.last_revision()
659
self.target.generate_revision_history(self._last_revid,
660
prev_last_revid, self.source)
663
def pull(self, overwrite=False, stop_revision=None,
664
possible_transports=None, _hook_master=None, run_hooks=True,
665
_override_hook_target=None, local=False):
668
:param _hook_master: Private parameter - set the branch to
669
be supplied as the master to pull hooks.
670
:param run_hooks: Private parameter - if false, this branch
671
is being called because it's the master of the primary branch,
672
so it should not run its hooks.
673
:param _override_hook_target: Private parameter - set the branch to be
674
supplied as the target_branch to pull hooks.
676
# This type of branch can't be bound.
678
raise errors.LocalRequiresBoundBranch()
679
result = GitBranchPullResult()
680
result.source_branch = self.source
681
if _override_hook_target is None:
682
result.target_branch = self.target
684
result.target_branch = _override_hook_target
685
self.source.lock_read()
687
# We assume that during 'pull' the target repository is closer than
689
(result.old_revno, result.old_revid) = \
690
self.target.last_revision_info()
691
result.new_git_head, remote_refs = self._update_revisions(
692
stop_revision, overwrite=overwrite)
693
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
695
(result.new_revno, result.new_revid) = \
696
self.target.last_revision_info()
698
result.master_branch = _hook_master
699
result.local_branch = result.target_branch
701
result.master_branch = result.target_branch
702
result.local_branch = None
704
for hook in branch.Branch.hooks['post_pull']:
710
def _basic_push(self, overwrite=False, stop_revision=None):
711
result = branch.BranchPushResult()
712
result.source_branch = self.source
713
result.target_branch = self.target
714
result.old_revno, result.old_revid = self.target.last_revision_info()
715
result.new_git_head, remote_refs = self._update_revisions(
716
stop_revision, overwrite=overwrite)
717
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
719
result.new_revno, result.new_revid = self.target.last_revision_info()
723
class InterGitBranch(branch.GenericInterBranch):
724
"""InterBranch implementation that pulls between Git branches."""
727
class InterLocalGitRemoteGitBranch(InterGitBranch):
728
"""InterBranch that copies from a local to a remote git branch."""
731
def _get_branch_formats_to_test():
736
def is_compatible(self, source, target):
737
from bzrlib.plugins.git.remote import RemoteGitBranch
738
return (isinstance(source, LocalGitBranch) and
739
isinstance(target, RemoteGitBranch))
741
def _basic_push(self, overwrite=False, stop_revision=None):
742
result = GitBranchPushResult()
743
result.source_branch = self.source
744
result.target_branch = self.target
745
if stop_revision is None:
746
stop_revision = self.source.last_revision()
747
# FIXME: Check for diverged branches
748
def get_changed_refs(old_refs):
749
result.old_revid = self.target.lookup_foreign_revision_id(old_refs.get(self.target.ref, ZERO_SHA))
750
refs = { self.target.ref: self.source.repository.lookup_bzr_revision_id(stop_revision)[0] }
751
result.new_revid = stop_revision
752
for name, sha in self.source.repository._git.refs.as_dict("refs/tags").iteritems():
753
refs[tag_name_to_ref(name)] = sha
755
self.target.repository.send_pack(get_changed_refs,
756
self.source.repository._git.object_store.generate_pack_contents)
760
class InterGitLocalGitBranch(InterGitBranch):
761
"""InterBranch that copies from a remote to a local git branch."""
764
def _get_branch_formats_to_test():
769
def is_compatible(self, source, target):
770
return (isinstance(source, GitBranch) and
771
isinstance(target, LocalGitBranch))
773
def _basic_push(self, overwrite=False, stop_revision=None):
774
result = branch.BranchPushResult()
775
result.source_branch = self.source
776
result.target_branch = self.target
777
result.old_revid = self.target.last_revision()
778
refs, stop_revision = self.update_refs(stop_revision)
779
self.target.generate_revision_history(stop_revision, result.old_revid)
780
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
781
source_refs=refs, overwrite=overwrite)
782
result.new_revid = self.target.last_revision()
785
def update_refs(self, stop_revision=None):
786
interrepo = _mod_repository.InterRepository.get(self.source.repository,
787
self.target.repository)
788
if stop_revision is None:
789
refs = interrepo.fetch(branches=["HEAD"])
790
stop_revision = self.target.lookup_foreign_revision_id(refs["HEAD"])
792
refs = interrepo.fetch(revision_id=stop_revision)
793
return refs, stop_revision
795
def pull(self, stop_revision=None, overwrite=False,
796
possible_transports=None, run_hooks=True,local=False):
797
# This type of branch can't be bound.
799
raise errors.LocalRequiresBoundBranch()
800
result = GitPullResult()
801
result.source_branch = self.source
802
result.target_branch = self.target
803
result.old_revid = self.target.last_revision()
804
refs, stop_revision = self.update_refs(stop_revision)
805
self.target.generate_revision_history(stop_revision, result.old_revid)
806
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
807
overwrite=overwrite, source_refs=refs)
808
result.new_revid = self.target.last_revision()
812
class InterToGitBranch(branch.GenericInterBranch):
813
"""InterBranch implementation that pulls into a Git branch."""
815
def __init__(self, source, target):
816
super(InterToGitBranch, self).__init__(source, target)
817
self.interrepo = _mod_repository.InterRepository.get(source.repository,
821
def _get_branch_formats_to_test():
823
default_format = branch.format_registry.get_default()
824
except AttributeError:
825
default_format = branch.BranchFormat._default_format
826
return [(default_format, GitBranchFormat())]
829
def is_compatible(self, source, target):
830
return (not isinstance(source, GitBranch) and
831
isinstance(target, GitBranch))
833
def _get_new_refs(self, stop_revision=None):
834
if stop_revision is None:
835
(stop_revno, stop_revision) = self.source.last_revision_info()
837
stop_revno = self.source.revision_id_to_revno(stop_revision)
838
assert type(stop_revision) is str
839
main_ref = self.target.ref or "refs/heads/master"
840
refs = { main_ref: (None, stop_revision) }
841
for name, revid in self.source.tags.get_tag_dict().iteritems():
842
if self.source.repository.has_revision(revid):
843
refs[tag_name_to_ref(name)] = (None, revid)
844
return refs, main_ref, (stop_revno, stop_revision)
846
def pull(self, overwrite=False, stop_revision=None, local=False,
847
possible_transports=None, run_hooks=True):
848
result = GitBranchPullResult()
849
result.source_branch = self.source
850
result.target_branch = self.target
851
new_refs, main_ref, stop_revinfo = self._get_new_refs(stop_revision)
852
def update_refs(old_refs):
853
refs = dict(old_refs)
854
# FIXME: Check for diverged branches
855
refs.update(new_refs)
858
old_refs, new_refs = self.interrepo.fetch_refs(update_refs)
859
except NoPushSupport:
860
raise errors.NoRoundtrippingSupport(self.source, self.target)
861
(result.old_revid, old_sha1) = old_refs.get(main_ref, (ZERO_SHA, NULL_REVISION))
862
if result.old_revid is None:
863
result.old_revid = self.target.lookup_foreign_revision_id(old_sha1)
864
result.new_revid = new_refs[main_ref][1]
867
def push(self, overwrite=False, stop_revision=None, lossy=False,
868
_override_hook_source_branch=None):
869
result = GitBranchPushResult()
870
result.source_branch = self.source
871
result.target_branch = self.target
872
new_refs, main_ref, stop_revinfo = self._get_new_refs(stop_revision)
873
def update_refs(old_refs):
874
refs = dict(old_refs)
875
# FIXME: Check for diverged branches
876
refs.update(new_refs)
879
result.revidmap, old_refs, new_refs = self.interrepo.dfetch_refs(
883
old_refs, new_refs = self.interrepo.fetch_refs(update_refs)
884
except NoPushSupport:
885
raise errors.NoRoundtrippingSupport(self.source, self.target)
886
(result.old_revid, old_sha1) = old_refs.get(main_ref, (ZERO_SHA, NULL_REVISION))
887
if result.old_revid is None:
888
result.old_revid = self.target.lookup_foreign_revision_id(old_sha1)
889
result.new_revid = new_refs[main_ref][1]
890
(result.new_original_revno, result.new_original_revid) = stop_revinfo
893
def lossy_push(self, stop_revision=None):
894
# For compatibility with bzr < 2.4
895
return self.push(lossy=True, stop_revision=stop_revision)
898
branch.InterBranch.register_optimiser(InterGitLocalGitBranch)
899
branch.InterBranch.register_optimiser(InterFromGitBranch)
900
branch.InterBranch.register_optimiser(InterToGitBranch)
901
branch.InterBranch.register_optimiser(InterLocalGitRemoteGitBranch)