Skip to content

Commit 073c3ff

Browse files
felipecgitster
authored andcommitted
remote-bzr: detect local repositories
So we don't create a clone unnecessarily. Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 570e7ec commit 073c3ff

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

contrib/remote-helpers/git-remote-bzr

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import bzrlib.plugin
2424
bzrlib.plugin.load_plugins()
2525

2626
import bzrlib.generate_ids
27+
import bzrlib.transport
2728

2829
import sys
2930
import os
@@ -613,11 +614,14 @@ def do_export(parser):
613614
if ref == 'refs/heads/master':
614615
repo.generate_revision_history(revid, marks.get_tip('master'))
615616
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()
618623
else:
619-
peer.import_last_revision_info(repo.repository, revno, revid)
620-
wt = peer.bzrdir.open_workingtree()
624+
wt = repo.bzrdir.open_workingtree()
621625
wt.update()
622626
print "ok %s" % ref
623627
print
@@ -649,24 +653,28 @@ def do_list(parser):
649653
def get_repo(url, alias):
650654
global dirname, peer
651655

652-
clone_path = os.path.join(dirname, 'clone')
653656
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
661676
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
670678

671679
return branch
672680

0 commit comments

Comments
 (0)