remote-bzr: simplify get_remote_branch()

No need for 'origin', it's only needed for the bzrdir 'sprout' method, which can be greatly simplified. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed May 24, 2013 at 21:24 UTC 1bf09d4fbf402e42b3a0be2411a9c4feb1ba8d25
1 file changed +12 -11
contrib/remote-helpers/git-remote-bzr
+12 -11
@@ -765,25 +765,26 @@ def do_list(parser):
765 print "@refs/heads/%s HEAD" % master_branch
766 print
767
768 -def get_remote_branch(origin, remote_branch, name):
768 +def clone(path, remote_branch):
769 + bdir = bzrlib.bzrdir.BzrDir.create(path)
770 + repo = bdir.find_repository()
771 + repo.fetch(remote_branch.repository)
772 + return remote_branch.sprout(bdir, repository=repo)
773 +
774 +def get_remote_branch(remote_branch, name):
775 global dirname, peers
776
777 branch_path = os.path.join(dirname, 'clone', name)
778
779 try:
774 - d = bzrlib.bzrdir.BzrDir.open(branch_path)
775 - branch = d.open_branch()
780 + branch = bzrlib.branch.Branch.open(branch_path)
781 except bzrlib.errors.NotBranchError:
782 # clone
778 - d = origin.sprout(branch_path, None,
779 - hardlink=True, create_tree_if_local=False,
780 - force_new_repo=False,
781 - source_branch=remote_branch)
782 - branch = d.open_branch()
783 + branch = clone(branch_path, remote_branch)
784 else:
785 # pull
786 try:
786 - branch.pull(remote_branch, [], None, False)
787 + branch.pull(remote_branch, overwrite=True)
788 except bzrlib.errors.DivergedBranches:
789 # use remote branch for now
790 return remote_branch
@@ -856,7 +857,7 @@ def get_repo(url, alias):
857
858 if not is_local:
859 peers[name] = remote_branch.base
859 - branch = get_remote_branch(origin, remote_branch, name)
860 + branch = get_remote_branch(remote_branch, name)
861 else:
862 branch = remote_branch
863
@@ -874,7 +875,7 @@ def get_repo(url, alias):
875
876 if not is_local:
877 peers[name] = remote_branch.base
877 - branch = get_remote_branch(origin, remote_branch, name)
878 + branch = get_remote_branch(remote_branch, name)
879 else:
880 branch = remote_branch
881