ssh: rewrite proxy management for multiprocessing usage
We changed sync to use multiprocessing for parallel work. This broke
the ssh proxy code as it's all based on threads. Rewrite the logic to
be multiprocessing safe.
Now instead of the module acting as a stateful object, callers have to
instantiate a new ProxyManager class that holds all the state, an pass
that down to any users.
Bug: https://crbug.com/gerrit/12389
Change-Id: I4b1af116f7306b91e825d3c56fb4274c9b033562
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/305486
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Chris Mcdonald <cjmcdonald@google.com>
diff --git a/git_command.py b/git_command.py
index fabad0e..04953f3 100644
--- a/git_command.py
+++ b/git_command.py
@@ -21,7 +21,6 @@
from git_refs import HEAD
import platform_utils
from repo_trace import REPO_TRACE, IsTrace, Trace
-import ssh
from wrapper import Wrapper
GIT = 'git'
@@ -167,7 +166,7 @@
capture_stderr=False,
merge_output=False,
disable_editor=False,
- ssh_proxy=False,
+ ssh_proxy=None,
cwd=None,
gitdir=None):
env = self._GetBasicEnv()
@@ -175,8 +174,8 @@
if disable_editor:
env['GIT_EDITOR'] = ':'
if ssh_proxy:
- env['REPO_SSH_SOCK'] = ssh.sock()
- env['GIT_SSH'] = ssh.proxy()
+ env['REPO_SSH_SOCK'] = ssh_proxy.sock()
+ env['GIT_SSH'] = ssh_proxy.proxy
env['GIT_SSH_VARIANT'] = 'ssh'
if 'http_proxy' in env and 'darwin' == sys.platform:
s = "'http.proxy=%s'" % (env['http_proxy'],)
@@ -259,7 +258,7 @@
raise GitError('%s: %s' % (command[1], e))
if ssh_proxy:
- ssh.add_client(p)
+ ssh_proxy.add_client(p)
self.process = p
if input:
@@ -271,7 +270,8 @@
try:
self.stdout, self.stderr = p.communicate()
finally:
- ssh.remove_client(p)
+ if ssh_proxy:
+ ssh_proxy.remove_client(p)
self.rc = p.wait()
@staticmethod