remote-bzr: detect local repositories
So we don't create a clone unnecessarily. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
Nov 28, 2012 at 02:01 UTC
073c3ffa582a4d449b7088108a1e302c9169063b
1 file changed
+28
-20
contrib/remote-helpers/git-remote-bzr
+28
-20
@@ -24,6 +24,7 @@ import bzrlib.plugin
24
bzrlib.plugin.load_plugins()
25
26
import bzrlib.generate_ids
27
+import bzrlib.transport
28
29
import sys
30
import os
@@ -613,11 +614,14 @@ def do_export(parser):
614
if ref == 'refs/heads/master':
615
repo.generate_revision_history(revid, marks.get_tip('master'))
616
revno, revid = repo.last_revision_info()
616
- if hasattr(peer, "import_last_revision_info_and_tags"):
617
- peer.import_last_revision_info_and_tags(repo, revno, revid)
617
+ if peer:
618
+ if hasattr(peer, "import_last_revision_info_and_tags"):
619
+ peer.import_last_revision_info_and_tags(repo, revno, revid)
620
+ else:
621
+ peer.import_last_revision_info(repo.repository, revno, revid)
622
+ wt = peer.bzrdir.open_workingtree()
623
else:
619
- peer.import_last_revision_info(repo.repository, revno, revid)
620
- wt = peer.bzrdir.open_workingtree()
624
+ wt = repo.bzrdir.open_workingtree()
625
wt.update()
626
print "ok %s" % ref
627
print
@@ -649,24 +653,28 @@ def do_list(parser):
653
def get_repo(url, alias):
654
global dirname, peer
655
652
- clone_path = os.path.join(dirname, 'clone')
656
origin = bzrlib.bzrdir.BzrDir.open(url)
654
- remote_branch = origin.open_branch()
655
-
656
- if os.path.exists(clone_path):
657
- # pull
658
- d = bzrlib.bzrdir.BzrDir.open(clone_path)
659
- branch = d.open_branch()
660
- result = branch.pull(remote_branch, [], None, False)
657
+ branch = origin.open_branch()
658
+
659
+ if not isinstance(origin.transport, bzrlib.transport.local.LocalTransport):
660
+ clone_path = os.path.join(dirname, 'clone')
661
+ remote_branch = branch
662
+ if os.path.exists(clone_path):
663
+ # pull
664
+ d = bzrlib.bzrdir.BzrDir.open(clone_path)
665
+ branch = d.open_branch()
666
+ result = branch.pull(remote_branch, [], None, False)
667
+ else:
668
+ # clone
669
+ d = origin.sprout(clone_path, None,
670
+ hardlink=True, create_tree_if_local=False,
671
+ source_branch=remote_branch)
672
+ branch = d.open_branch()
673
+ branch.bind(remote_branch)
674
+
675
+ peer = remote_branch
676
else:
662
- # clone
663
- d = origin.sprout(clone_path, None,
664
- hardlink=True, create_tree_if_local=False,
665
- source_branch=remote_branch)
666
- branch = d.open_branch()
667
- branch.bind(remote_branch)
668
-
669
- peer = remote_branch
677
+ peer = None
678
679
return branch
680