remote-bzr: delay cloning/pulling
Until the branch is actually going to be used. 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
2ae078e8476639b0dcd559d9b797771e6ffd97ff
1 file changed
+13
-15
contrib/remote-helpers/git-remote-bzr
+13
-15
@@ -278,7 +278,7 @@ def export_branch(repo, name):
278
ref = '%s/heads/%s' % (prefix, name)
279
tip = marks.get_tip(name)
280
281
- branch = bzrlib.branch.Branch.open(branches[name])
281
+ branch = get_remote_branch(name)
282
repo = branch.repository
283
284
branch.lock_read()
@@ -590,7 +590,7 @@ def parse_commit(parser):
590
591
if ref.startswith('refs/heads/'):
592
name = ref[len('refs/heads/'):]
593
- branch = bzrlib.branch.Branch.open(branches[name])
593
+ branch = get_remote_branch(name)
594
else:
595
die('unknown ref')
596
@@ -692,7 +692,7 @@ def do_export(parser):
692
for ref, revid in parsed_refs.iteritems():
693
if ref.startswith('refs/heads/'):
694
name = ref[len('refs/heads/'):]
695
- branch = bzrlib.branch.Branch.open(branches[name])
695
+ branch = get_remote_branch(name)
696
branch.generate_revision_history(revid, marks.get_tip(name))
697
698
if name in peers:
@@ -749,7 +749,7 @@ def do_list(parser):
749
master_branch = name
750
print "? refs/heads/%s" % name
751
752
- branch = bzrlib.branch.Branch.open(branches[master_branch])
752
+ branch = get_remote_branch(master_branch)
753
branch.lock_read()
754
for tag, revid in branch.tags.get_tag_dict().items():
755
try:
@@ -771,8 +771,12 @@ def clone(path, remote_branch):
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
774
+def get_remote_branch(name):
775
+ global dirname, branches
776
+
777
+ remote_branch = bzrlib.branch.Branch.open(branches[name])
778
+ if isinstance(remote_branch.user_transport, bzrlib.transport.local.LocalTransport):
779
+ return remote_branch
780
781
branch_path = os.path.join(dirname, 'clone', name)
782
@@ -857,13 +861,10 @@ def get_repo(url, alias):
861
862
if not is_local:
863
peers[name] = remote_branch.base
860
- branch = get_remote_branch(remote_branch, name)
861
- else:
862
- branch = remote_branch
864
864
- branches[name] = branch.base
865
+ branches[name] = remote_branch.base
866
866
- return branch.repository
867
+ return remote_branch.repository
868
else:
869
# repository
870
@@ -875,11 +876,8 @@ def get_repo(url, alias):
876
877
if not is_local:
878
peers[name] = remote_branch.base
878
- branch = get_remote_branch(remote_branch, name)
879
- else:
880
- branch = remote_branch
879
882
- branches[name] = branch.base
880
+ branches[name] = remote_branch.base
881
882
return repo
883