Skip to content

Commit bd5424f

Browse files
rhansengitster
authored andcommitted
remote-bzr: reuse bzrlib transports when possible
Pass a list of open bzrlib.transport.Transport objects to each bzrlib function that might create a transport. This enables bzrlib to reuse existing transports when possible, avoiding multiple concurrent connections to the same remote server. If the remote server is accessed via ssh, this fixes a couple of problems: * If the user does not have keys loaded into an ssh agent, the user may be prompted for a password multiple times. * If the user is using OpenSSH and the ControlMaster setting is set to auto, git-remote-bzr might hang. This is because bzrlib closes the multiple ssh sessions in an undefined order and might try to close the master ssh session before the other sessions. The master ssh process will not exit until the other sessions have exited, causing a deadlock. (The ssh sessions are closed in an undefined order because bzrlib relies on the Python garbage collector to trigger ssh session termination.) Signed-off-by: Richard Hansen <rhansen@bbn.com> Acked-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d2dbd39 commit bd5424f

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

contrib/remote-helpers/git-remote-bzr

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ def parse_reset(parser):
674674
parsed_refs[ref] = mark_to_rev(from_mark)
675675

676676
def do_export(parser):
677-
global parsed_refs, dirname
677+
global parsed_refs, dirname, transports
678678

679679
parser.next()
680680

@@ -699,7 +699,8 @@ def do_export(parser):
699699
branch.generate_revision_history(revid, marks.get_tip(name))
700700

701701
if name in peers:
702-
peer = bzrlib.branch.Branch.open(peers[name])
702+
peer = bzrlib.branch.Branch.open(peers[name],
703+
possible_transports=transports)
703704
try:
704705
peer.bzrdir.push_branch(branch, revision_id=revid)
705706
except bzrlib.errors.DivergedBranches:
@@ -769,25 +770,28 @@ def do_list(parser):
769770
print
770771

771772
def clone(path, remote_branch):
773+
global transports
772774
try:
773-
bdir = bzrlib.bzrdir.BzrDir.create(path)
775+
bdir = bzrlib.bzrdir.BzrDir.create(path, possible_transports=transports)
774776
except bzrlib.errors.AlreadyControlDirError:
775-
bdir = bzrlib.bzrdir.BzrDir.open(path)
777+
bdir = bzrlib.bzrdir.BzrDir.open(path, possible_transports=transports)
776778
repo = bdir.find_repository()
777779
repo.fetch(remote_branch.repository)
778780
return remote_branch.sprout(bdir, repository=repo)
779781

780782
def get_remote_branch(name):
781-
global dirname, branches
783+
global dirname, branches, transports
782784

783-
remote_branch = bzrlib.branch.Branch.open(branches[name])
785+
remote_branch = bzrlib.branch.Branch.open(branches[name],
786+
possible_transports=transports)
784787
if isinstance(remote_branch.user_transport, bzrlib.transport.local.LocalTransport):
785788
return remote_branch
786789

787790
branch_path = os.path.join(dirname, 'clone', name)
788791

789792
try:
790-
branch = bzrlib.branch.Branch.open(branch_path)
793+
branch = bzrlib.branch.Branch.open(branch_path,
794+
possible_transports=transports)
791795
except bzrlib.errors.NotBranchError:
792796
# clone
793797
branch = clone(branch_path, remote_branch)
@@ -821,17 +825,19 @@ def find_branches(repo):
821825
yield name, branch.base
822826

823827
def get_repo(url, alias):
824-
global dirname, peer, branches
828+
global dirname, peer, branches, transports
825829

826830
normal_url = bzrlib.urlutils.normalize_url(url)
827-
origin = bzrlib.bzrdir.BzrDir.open(url)
831+
origin = bzrlib.bzrdir.BzrDir.open(url, possible_transports=transports)
828832
is_local = isinstance(origin.transport, bzrlib.transport.local.LocalTransport)
829833

830834
shared_path = os.path.join(gitdir, 'bzr')
831835
try:
832-
shared_dir = bzrlib.bzrdir.BzrDir.open(shared_path)
836+
shared_dir = bzrlib.bzrdir.BzrDir.open(shared_path,
837+
possible_transports=transports)
833838
except bzrlib.errors.NotBranchError:
834-
shared_dir = bzrlib.bzrdir.BzrDir.create(shared_path)
839+
shared_dir = bzrlib.bzrdir.BzrDir.create(shared_path,
840+
possible_transports=transports)
835841
try:
836842
shared_repo = shared_dir.open_repository()
837843
except bzrlib.errors.NoRepositoryPresent:
@@ -844,7 +850,8 @@ def get_repo(url, alias):
844850
else:
845851
# check and remove old organization
846852
try:
847-
bdir = bzrlib.bzrdir.BzrDir.open(clone_path)
853+
bdir = bzrlib.bzrdir.BzrDir.open(clone_path,
854+
possible_transports=transports)
848855
bdir.destroy_repository()
849856
except bzrlib.errors.NotBranchError:
850857
pass
@@ -897,6 +904,7 @@ def main(args):
897904
global files_cache
898905
global is_tmp
899906
global branches, peers
907+
global transports
900908

901909
alias = args[1]
902910
url = args[2]
@@ -909,6 +917,7 @@ def main(args):
909917
marks = None
910918
branches = {}
911919
peers = {}
920+
transports = []
912921

913922
if alias[5:] == url:
914923
is_tmp = True

0 commit comments

Comments
 (0)