408
382
self.source.unlock()
411
def _basic_push(self, overwrite=False, stop_revision=None):
412
result = branch.BranchPushResult()
413
result.source_branch = self.source
414
result.target_branch = self.target
415
graph = self.target.repository.get_graph(self.source.repository)
416
result.old_revno, result.old_revid = self.target.last_revision_info()
417
self.update_revisions(stop_revision, overwrite=overwrite,
419
result.new_git_head = self._head
420
result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
422
result.new_revno, result.new_revid = self.target.last_revision_info()
426
class InterGitBranch(branch.GenericInterBranch):
388
branch.InterBranch.register_optimiser(InterGitGenericBranch)
391
class InterGitRemoteLocalBranch(branch.InterBranch):
427
392
"""InterBranch implementation that pulls between Git branches."""
430
class InterGitLocalRemoteBranch(InterGitBranch):
431
"""InterBranch that copies from a local to a remote git branch."""
434
def is_compatible(self, source, target):
435
from bzrlib.plugins.git.remote import RemoteGitBranch
436
return (isinstance(source, LocalGitBranch) and
437
isinstance(target, RemoteGitBranch))
439
def _basic_push(self, overwrite=False, stop_revision=None):
440
result = GitBranchPushResult()
441
result.source_branch = self.source
442
result.target_branch = self.target
443
if stop_revision is None:
444
stop_revision = self.source.last_revision()
445
# FIXME: Check for diverged branches
446
def get_changed_refs(old_refs):
447
result.old_revid = self.target.mapping.revision_id_foreign_to_bzr(old_refs.get("refs/heads/master", "0" * 40))
448
refs = { "refs/heads/master": self.source.repository.lookup_git_revid(stop_revision)[0] }
449
result.new_revid = stop_revision
450
for name, sha in self.source.repository._git.refs.as_dict("refs/tags").iteritems():
451
refs["refs/tags/%s" % name] = sha
453
self.target.repository.send_pack(get_changed_refs,
454
self.source.repository._git.object_store.generate_pack_contents)
458
class InterGitRemoteLocalBranch(InterGitBranch):
459
"""InterBranch that copies from a remote to a local git branch."""
462
395
def is_compatible(self, source, target):
463
396
from bzrlib.plugins.git.remote import RemoteGitBranch
464
397
return (isinstance(source, RemoteGitBranch) and
465
398
isinstance(target, LocalGitBranch))
467
def _basic_push(self, overwrite=False, stop_revision=None):
468
result = branch.BranchPushResult()
400
def pull(self, stop_revision=None, overwrite=False,
401
possible_transports=None, local=False):
402
# This type of branch can't be bound.
404
raise errors.LocalRequiresBoundBranch()
405
result = GitPullResult()
469
406
result.source_branch = self.source
470
407
result.target_branch = self.target
471
result.old_revid = self.target.last_revision()
472
refs, stop_revision = self.update_refs(stop_revision)
473
self.target.generate_revision_history(stop_revision, result.old_revid)
474
self.update_tags(refs)
475
result.new_revid = self.target.last_revision()
478
def update_tags(self, refs):
479
for name, revid in extract_tags(refs, self.target.mapping).iteritems():
480
self.target.tags.set_tag(name, revid)
482
def update_refs(self, stop_revision=None):
483
408
interrepo = repository.InterRepository.get(self.source.repository,
484
409
self.target.repository)
410
result.old_revid = self.target.last_revision()
485
411
if stop_revision is None:
486
412
refs = interrepo.fetch_refs(branches=["HEAD"])
487
413
stop_revision = self.target.mapping.revision_id_foreign_to_bzr(refs["HEAD"])
489
415
refs = interrepo.fetch_refs(revision_id=stop_revision)
490
return refs, stop_revision
492
def pull(self, stop_revision=None, overwrite=False,
493
possible_transports=None, local=False):
494
# This type of branch can't be bound.
496
raise errors.LocalRequiresBoundBranch()
497
result = GitPullResult()
498
result.source_branch = self.source
499
result.target_branch = self.target
500
result.old_revid = self.target.last_revision()
501
refs, stop_revision = self.update_refs(stop_revision)
502
416
self.target.generate_revision_history(stop_revision, result.old_revid)
503
self.update_tags(refs)
417
for name, revid in extract_tags(refs, self.target.mapping).iteritems():
418
self.target.tags.set_tag(name, revid)
504
419
result.new_revid = self.target.last_revision()
508
class InterToGitBranch(branch.InterBranch):
509
"""InterBranch implementation that pulls from Git into bzr."""
512
def is_compatible(self, source, target):
513
return (not isinstance(source, GitBranch) and
514
isinstance(target, GitBranch))
516
def update_revisions(self, *args, **kwargs):
517
raise NoPushSupport()
519
def push(self, overwrite=True, stop_revision=None,
520
_override_hook_source_branch=None):
521
raise NoPushSupport()
523
def lossy_push(self, stop_revision=None):
524
result = GitBranchPushResult()
525
result.source_branch = self.source
526
result.target_branch = self.target
527
result.old_revid = self.target.last_revision()
528
if stop_revision is None:
529
stop_revision = self.source.last_revision()
530
# FIXME: Check for diverged branches
531
refs = { "refs/heads/master": stop_revision }
532
for name, revid in self.source.tags.get_tag_dict().iteritems():
533
if self.source.repository.has_revision(revid):
534
refs["refs/tags/%s" % name] = revid
535
revidmap, new_refs = self.target.repository.dfetch_refs(
536
self.source.repository, refs)
538
self.target.generate_revision_history(revidmap[stop_revision])
539
result.new_revid = revidmap[stop_revision]
541
result.new_revid = result.old_revid
542
result.revidmap = revidmap
546
423
branch.InterBranch.register_optimiser(InterGitRemoteLocalBranch)
547
branch.InterBranch.register_optimiser(InterFromGitBranch)
548
branch.InterBranch.register_optimiser(InterToGitBranch)
549
branch.InterBranch.register_optimiser(InterGitLocalRemoteBranch)