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
self._lock_mode = None
293
super(GitBranch, self).__init__(repository.get_mapping())
294
if tagsdict is not None:
295
self.tags = DictTagDict(self, tagsdict)
297
self.name = ref_to_branch_name(ref)
299
self.base = bzrdir.root_transport.base
301
def _get_checkout_format(self):
302
"""Return the most suitable metadir for a checkout of this branch.
303
Weaves are used if this branch's repository uses weaves.
305
return bzrdir.format_registry.make_bzrdir("default")
307
def get_child_submit_format(self):
308
"""Return the preferred format of submissions to this branch."""
309
ret = self.get_config().get_user_option("child_submit_format")
314
def _get_nick(self, local=False, possible_master_transports=None):
315
"""Find the nick name for this branch.
319
return self.name or "HEAD"
321
def _set_nick(self, nick):
322
raise NotImplementedError
324
nick = property(_get_nick, _set_nick)
327
return "<%s(%r, %r)>" % (self.__class__.__name__, self.repository.base,
330
def generate_revision_history(self, revid, old_revid=None):
331
if revid == NULL_REVISION:
334
# FIXME: Check that old_revid is in the ancestry of revid
335
newhead, self.mapping = self.mapping.revision_id_bzr_to_foreign(revid)
336
if self.mapping is None:
338
self._set_head(newhead)
340
def lock_write(self, token=None):
341
if token is not None:
342
raise errors.TokenLockingNotSupported(self)
344
assert self._lock_mode == 'w'
345
self._lock_count += 1
347
self._lock_mode = 'w'
349
self.repository.lock_write()
350
return GitWriteLock(self.unlock)
352
def get_stacked_on_url(self):
353
# Git doesn't do stacking (yet...)
354
raise errors.UnstackableBranchFormat(self._format, self.base)
356
def get_parent(self):
357
"""See Branch.get_parent()."""
358
# FIXME: Set "origin" url from .git/config ?
361
def set_parent(self, url):
362
# FIXME: Set "origin" url in .git/config ?
367
assert self._lock_mode in ('r', 'w')
368
self._lock_count += 1
370
self._lock_mode = 'r'
372
self.repository.lock_read()
373
return GitReadLock(self.unlock)
375
def peek_lock_mode(self):
376
return self._lock_mode
379
return (self._lock_mode is not None)
382
"""See Branch.unlock()."""
383
self._lock_count -= 1
384
if self._lock_count == 0:
385
self._lock_mode = None
386
self._clear_cached_state()
387
self.repository.unlock()
389
def get_physical_lock_status(self):
393
def last_revision(self):
394
# perhaps should escape this ?
395
if self.head is None:
396
return revision.NULL_REVISION
397
return self.lookup_foreign_revision_id(self.head)
399
def _basic_push(self, target, overwrite=False, stop_revision=None):
400
return branch.InterBranch.get(self, target)._basic_push(
401
overwrite, stop_revision)
403
def lookup_foreign_revision_id(self, foreign_revid):
404
return self.repository.lookup_foreign_revision_id(foreign_revid,
407
def lookup_bzr_revision_id(self, revid):
408
return self.repository.lookup_bzr_revision_id(
409
revid, mapping=self.mapping)
412
class LocalGitBranch(GitBranch):
413
"""A local Git branch."""
415
def __init__(self, bzrdir, repository, ref, lockfiles, tagsdict=None):
416
super(LocalGitBranch, self).__init__(bzrdir, repository, ref,
418
refs = repository._git.get_refs()
419
if not (ref in refs.keys() or "HEAD" in refs.keys()):
420
raise errors.NotBranchError(self.base)
422
def create_checkout(self, to_location, revision_id=None, lightweight=False,
423
accelerator_tree=None, hardlink=False):
425
t = transport.get_transport(to_location)
427
format = self._get_checkout_format()
428
checkout = format.initialize_on_transport(t)
429
from_branch = branch.BranchReferenceFormat().initialize(checkout,
431
tree = checkout.create_workingtree(revision_id,
432
from_branch=from_branch, hardlink=hardlink)
435
return self._create_heavyweight_checkout(to_location, revision_id,
438
def _create_heavyweight_checkout(self, to_location, revision_id=None,
440
"""Create a new heavyweight checkout of this branch.
442
:param to_location: URL of location to create the new checkout in.
443
:param revision_id: Revision that should be the tip of the checkout.
444
:param hardlink: Whether to hardlink
445
:return: WorkingTree object of checkout.
447
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
448
to_location, force_new_tree=False)
449
checkout = checkout_branch.bzrdir
450
checkout_branch.bind(self)
451
# pull up to the specified revision_id to set the initial
452
# branch tip correctly, and seed it with history.
453
checkout_branch.pull(self, stop_revision=revision_id)
454
return checkout.create_workingtree(revision_id, hardlink=hardlink)
456
def _gen_revision_history(self):
457
if self.head is None:
459
graph = self.repository.get_graph()
460
ret = list(graph.iter_lefthand_ancestry(self.last_revision(),
461
(revision.NULL_REVISION, )))
467
return self.repository._git.ref(self.ref or "HEAD")
471
def _read_last_revision_info(self):
472
last_revid = self.last_revision()
473
graph = self.repository.get_graph()
474
revno = graph.find_distance_to_null(last_revid,
475
[(revision.NULL_REVISION, 0)])
476
return revno, last_revid
478
def set_last_revision_info(self, revno, revision_id):
479
self.set_last_revision(revision_id)
480
self._last_revision_info_cache = revno, revision_id
482
def set_last_revision(self, revid):
483
if not revid or not isinstance(revid, basestring):
484
raise errors.InvalidRevisionId(revision_id=revid, branch=self)
485
if revid == NULL_REVISION:
488
(newhead, self.mapping) = self.repository.lookup_bzr_revision_id(revid)
489
if self.mapping is None:
491
self._set_head(newhead)
493
def _set_head(self, value):
495
self.repository._git.refs[self.ref or "HEAD"] = self._head
496
self._clear_cached_state()
498
head = property(_get_head, _set_head)
500
def get_config(self):
501
return GitBranchConfig(self)
503
def get_push_location(self):
504
"""See Branch.get_push_location."""
505
push_loc = self.get_config().get_user_option('push_location')
508
def set_push_location(self, location):
509
"""See Branch.set_push_location."""
510
self.get_config().set_user_option('push_location', location,
511
store=config.STORE_LOCATION)
513
def supports_tags(self):
517
def _quick_lookup_revno(local_branch, remote_branch, revid):
518
assert isinstance(revid, str), "was %r" % revid
519
# Try in source branch first, it'll be faster
521
return local_branch.revision_id_to_revno(revid)
522
except errors.NoSuchRevision:
523
graph = local_branch.repository.get_graph()
525
return graph.find_distance_to_null(revid)
526
except errors.GhostRevisionsHaveNoRevno:
527
# FIXME: Check using graph.find_distance_to_null() ?
528
return remote_branch.revision_id_to_revno(revid)
531
class GitBranchPullResult(branch.PullResult):
534
super(GitBranchPullResult, self).__init__()
535
self.new_git_head = None
536
self._old_revno = None
537
self._new_revno = None
539
def report(self, to_file):
541
if self.old_revid == self.new_revid:
542
to_file.write('No revisions to pull.\n')
543
elif self.new_git_head is not None:
544
to_file.write('Now on revision %d (git sha: %s).\n' %
545
(self.new_revno, self.new_git_head))
547
to_file.write('Now on revision %d.\n' % (self.new_revno,))
548
self._show_tag_conficts(to_file)
550
def _lookup_revno(self, revid):
551
return _quick_lookup_revno(self.target_branch, self.source_branch,
554
def _get_old_revno(self):
555
if self._old_revno is not None:
556
return self._old_revno
557
return self._lookup_revno(self.old_revid)
559
def _set_old_revno(self, revno):
560
self._old_revno = revno
562
old_revno = property(_get_old_revno, _set_old_revno)
564
def _get_new_revno(self):
565
if self._new_revno is not None:
566
return self._new_revno
567
return self._lookup_revno(self.new_revid)
569
def _set_new_revno(self, revno):
570
self._new_revno = revno
572
new_revno = property(_get_new_revno, _set_new_revno)
575
class GitBranchPushResult(branch.BranchPushResult):
577
def _lookup_revno(self, revid):
578
return _quick_lookup_revno(self.source_branch, self.target_branch,
583
return self._lookup_revno(self.old_revid)
587
new_original_revno = getattr(self, "new_original_revno", None)
588
if new_original_revno:
589
return new_original_revno
590
if getattr(self, "new_original_revid", None) is not None:
591
return self._lookup_revno(self.new_original_revid)
592
return self._lookup_revno(self.new_revid)
595
class InterFromGitBranch(branch.GenericInterBranch):
596
"""InterBranch implementation that pulls from Git into bzr."""
599
def _get_branch_formats_to_test():
601
default_format = branch.format_registry.get_default()
602
except AttributeError:
603
default_format = branch.BranchFormat._default_format
605
(GitBranchFormat(), GitBranchFormat()),
606
(GitBranchFormat(), default_format)]
609
def _get_interrepo(self, source, target):
610
return _mod_repository.InterRepository.get(source.repository, target.repository)
613
def is_compatible(cls, source, target):
614
if not isinstance(source, GitBranch):
616
if isinstance(target, GitBranch):
617
# InterLocalGitRemoteGitBranch or InterToGitBranch should be used
619
if getattr(cls._get_interrepo(source, target), "fetch_objects", None) is None:
620
# fetch_objects is necessary for this to work
624
def fetch(self, stop_revision=None, fetch_tags=True, limit=None):
625
self.fetch_objects(stop_revision, fetch_tags=fetch_tags, limit=limit)
627
def fetch_objects(self, stop_revision, fetch_tags, limit=None):
628
interrepo = self._get_interrepo(self.source, self.target)
629
def determine_wants(heads):
630
if self.source.ref is not None and not self.source.ref in heads:
631
raise NoSuchRef(self.source.ref, heads.keys())
633
if stop_revision is None:
634
if self.source.ref is not None:
635
head = heads[self.source.ref]
638
self._last_revid = self.source.lookup_foreign_revision_id(head)
640
self._last_revid = stop_revision
641
real = interrepo.get_determine_wants_revids(
642
[self._last_revid], include_tags=fetch_tags)
644
pack_hint, head, refs = interrepo.fetch_objects(
645
determine_wants, self.source.mapping, limit=limit)
646
if (pack_hint is not None and
647
self.target.repository._format.pack_compresses):
648
self.target.repository.pack(hint=pack_hint)
651
def _update_revisions(self, stop_revision=None, overwrite=False):
652
head, refs = self.fetch_objects(stop_revision, fetch_tags=True)
654
prev_last_revid = None
656
prev_last_revid = self.target.last_revision()
657
self.target.generate_revision_history(self._last_revid,
658
prev_last_revid, self.source)
661
def pull(self, overwrite=False, stop_revision=None,
662
possible_transports=None, _hook_master=None, run_hooks=True,
663
_override_hook_target=None, local=False):
666
:param _hook_master: Private parameter - set the branch to
667
be supplied as the master to pull hooks.
668
:param run_hooks: Private parameter - if false, this branch
669
is being called because it's the master of the primary branch,
670
so it should not run its hooks.
671
:param _override_hook_target: Private parameter - set the branch to be
672
supplied as the target_branch to pull hooks.
674
# This type of branch can't be bound.
676
raise errors.LocalRequiresBoundBranch()
677
result = GitBranchPullResult()
678
result.source_branch = self.source
679
if _override_hook_target is None:
680
result.target_branch = self.target
682
result.target_branch = _override_hook_target
683
self.source.lock_read()
685
# We assume that during 'pull' the target repository is closer than
687
(result.old_revno, result.old_revid) = \
688
self.target.last_revision_info()
689
result.new_git_head, remote_refs = self._update_revisions(
690
stop_revision, overwrite=overwrite)
691
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
693
(result.new_revno, result.new_revid) = \
694
self.target.last_revision_info()
696
result.master_branch = _hook_master
697
result.local_branch = result.target_branch
699
result.master_branch = result.target_branch
700
result.local_branch = None
702
for hook in branch.Branch.hooks['post_pull']:
708
def _basic_push(self, overwrite=False, stop_revision=None):
709
result = branch.BranchPushResult()
710
result.source_branch = self.source
711
result.target_branch = self.target
712
result.old_revno, result.old_revid = self.target.last_revision_info()
713
result.new_git_head, remote_refs = self._update_revisions(
714
stop_revision, overwrite=overwrite)
715
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
717
result.new_revno, result.new_revid = self.target.last_revision_info()
721
class InterGitBranch(branch.GenericInterBranch):
722
"""InterBranch implementation that pulls between Git branches."""
725
class InterLocalGitRemoteGitBranch(InterGitBranch):
726
"""InterBranch that copies from a local to a remote git branch."""
729
def _get_branch_formats_to_test():
734
def is_compatible(self, source, target):
735
from bzrlib.plugins.git.remote import RemoteGitBranch
736
return (isinstance(source, LocalGitBranch) and
737
isinstance(target, RemoteGitBranch))
739
def _basic_push(self, overwrite=False, stop_revision=None):
740
result = GitBranchPushResult()
741
result.source_branch = self.source
742
result.target_branch = self.target
743
if stop_revision is None:
744
stop_revision = self.source.last_revision()
745
# FIXME: Check for diverged branches
746
def get_changed_refs(old_refs):
747
result.old_revid = self.target.lookup_foreign_revision_id(old_refs.get(self.target.ref, ZERO_SHA))
748
refs = { self.target.ref: self.source.repository.lookup_bzr_revision_id(stop_revision)[0] }
749
result.new_revid = stop_revision
750
for name, sha in self.source.repository._git.refs.as_dict("refs/tags").iteritems():
751
refs[tag_name_to_ref(name)] = sha
753
self.target.repository.send_pack(get_changed_refs,
754
self.source.repository._git.object_store.generate_pack_contents)
758
class InterGitLocalGitBranch(InterGitBranch):
759
"""InterBranch that copies from a remote to a local git branch."""
762
def _get_branch_formats_to_test():
767
def is_compatible(self, source, target):
768
return (isinstance(source, GitBranch) and
769
isinstance(target, LocalGitBranch))
771
def _basic_push(self, overwrite=False, stop_revision=None):
772
result = branch.BranchPushResult()
773
result.source_branch = self.source
774
result.target_branch = self.target
775
result.old_revid = self.target.last_revision()
776
refs, stop_revision = self.update_refs(stop_revision)
777
self.target.generate_revision_history(stop_revision, result.old_revid)
778
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
779
source_refs=refs, overwrite=overwrite)
780
result.new_revid = self.target.last_revision()
783
def update_refs(self, stop_revision=None):
784
interrepo = _mod_repository.InterRepository.get(self.source.repository,
785
self.target.repository)
786
if stop_revision is None:
787
refs = interrepo.fetch(branches=["HEAD"])
788
stop_revision = self.target.lookup_foreign_revision_id(refs["HEAD"])
790
refs = interrepo.fetch(revision_id=stop_revision)
791
return refs, stop_revision
793
def pull(self, stop_revision=None, overwrite=False,
794
possible_transports=None, run_hooks=True,local=False):
795
# This type of branch can't be bound.
797
raise errors.LocalRequiresBoundBranch()
798
result = GitPullResult()
799
result.source_branch = self.source
800
result.target_branch = self.target
801
result.old_revid = self.target.last_revision()
802
refs, stop_revision = self.update_refs(stop_revision)
803
self.target.generate_revision_history(stop_revision, result.old_revid)
804
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
805
overwrite=overwrite, source_refs=refs)
806
result.new_revid = self.target.last_revision()
810
class InterToGitBranch(branch.GenericInterBranch):
811
"""InterBranch implementation that pulls into a Git branch."""
813
def __init__(self, source, target):
814
super(InterToGitBranch, self).__init__(source, target)
815
self.interrepo = _mod_repository.InterRepository.get(source.repository,
819
def _get_branch_formats_to_test():
821
default_format = branch.format_registry.get_default()
822
except AttributeError:
823
default_format = branch.BranchFormat._default_format
824
return [(default_format, GitBranchFormat())]
827
def is_compatible(self, source, target):
828
return (not isinstance(source, GitBranch) and
829
isinstance(target, GitBranch))
831
def _get_new_refs(self, stop_revision=None):
832
if stop_revision is None:
833
(stop_revno, stop_revision) = self.source.last_revision_info()
835
stop_revno = self.source.revision_id_to_revno(stop_revision)
836
assert type(stop_revision) is str
837
main_ref = self.target.ref or "refs/heads/master"
838
refs = { main_ref: (None, stop_revision) }
839
for name, revid in self.source.tags.get_tag_dict().iteritems():
840
if self.source.repository.has_revision(revid):
841
refs[tag_name_to_ref(name)] = (None, revid)
842
return refs, main_ref, (stop_revno, stop_revision)
844
def pull(self, overwrite=False, stop_revision=None, local=False,
845
possible_transports=None, run_hooks=True):
846
result = GitBranchPullResult()
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)
856
old_refs, new_refs = self.interrepo.fetch_refs(update_refs)
857
except NoPushSupport:
858
raise errors.NoRoundtrippingSupport(self.source, self.target)
859
(result.old_revid, old_sha1) = old_refs.get(main_ref, (ZERO_SHA, NULL_REVISION))
860
if result.old_revid is None:
861
result.old_revid = self.target.lookup_foreign_revision_id(old_sha1)
862
result.new_revid = new_refs[main_ref][1]
865
def push(self, overwrite=False, stop_revision=None, lossy=False,
866
_override_hook_source_branch=None):
867
result = GitBranchPushResult()
868
result.source_branch = self.source
869
result.target_branch = self.target
870
new_refs, main_ref, stop_revinfo = self._get_new_refs(stop_revision)
871
def update_refs(old_refs):
872
refs = dict(old_refs)
873
# FIXME: Check for diverged branches
874
refs.update(new_refs)
877
result.revidmap, old_refs, new_refs = self.interrepo.dfetch_refs(
881
old_refs, new_refs = self.interrepo.fetch_refs(update_refs)
882
except NoPushSupport:
883
raise errors.NoRoundtrippingSupport(self.source, self.target)
884
(result.old_revid, old_sha1) = old_refs.get(main_ref, (ZERO_SHA, NULL_REVISION))
885
if result.old_revid is None:
886
result.old_revid = self.target.lookup_foreign_revision_id(old_sha1)
887
result.new_revid = new_refs[main_ref][1]
888
(result.new_original_revno, result.new_original_revid) = stop_revinfo
891
def lossy_push(self, stop_revision=None):
892
# For compatibility with bzr < 2.4
893
return self.push(lossy=True, stop_revision=stop_revision)
896
branch.InterBranch.register_optimiser(InterGitLocalGitBranch)
897
branch.InterBranch.register_optimiser(InterFromGitBranch)
898
branch.InterBranch.register_optimiser(InterToGitBranch)
899
branch.InterBranch.register_optimiser(InterLocalGitRemoteGitBranch)