|
|
@@ -17,6 +17,7 @@ import os
|
|
|
import sys
|
|
|
import subprocess
|
|
|
import tempfile
|
|
|
+from signal import SIGTERM
|
|
|
from error import GitError
|
|
|
from trace import REPO_TRACE, IsTrace, Trace
|
|
|
|
|
|
@@ -29,6 +30,7 @@ LAST_CWD = None
|
|
|
|
|
|
_ssh_proxy_path = None
|
|
|
_ssh_sock_path = None
|
|
|
+_ssh_clients = []
|
|
|
|
|
|
def ssh_sock(create=True):
|
|
|
global _ssh_sock_path
|
|
|
@@ -51,6 +53,24 @@ def _ssh_proxy():
|
|
|
'git_ssh')
|
|
|
return _ssh_proxy_path
|
|
|
|
|
|
+def _add_ssh_client(p):
|
|
|
+ _ssh_clients.append(p)
|
|
|
+
|
|
|
+def _remove_ssh_client(p):
|
|
|
+ try:
|
|
|
+ _ssh_clients.remove(p)
|
|
|
+ except ValueError:
|
|
|
+ pass
|
|
|
+
|
|
|
+def terminate_ssh_clients():
|
|
|
+ global _ssh_clients
|
|
|
+ for p in _ssh_clients:
|
|
|
+ try:
|
|
|
+ os.kill(p.pid, SIGTERM)
|
|
|
+ p.wait()
|
|
|
+ except OSError:
|
|
|
+ pass
|
|
|
+ _ssh_clients = []
|
|
|
|
|
|
class _GitCall(object):
|
|
|
def version(self):
|
|
|
@@ -188,6 +208,9 @@ class GitCommand(object):
|
|
|
except Exception, e:
|
|
|
raise GitError('%s: %s' % (command[1], e))
|
|
|
|
|
|
+ if ssh_proxy:
|
|
|
+ _add_ssh_client(p)
|
|
|
+
|
|
|
self.process = p
|
|
|
self.stdin = p.stdin
|
|
|
|
|
|
@@ -210,4 +233,8 @@ class GitCommand(object):
|
|
|
else:
|
|
|
p.stderr = None
|
|
|
|
|
|
- return self.process.wait()
|
|
|
+ try:
|
|
|
+ rc = p.wait()
|
|
|
+ finally:
|
|
|
+ _remove_ssh_client(p)
|
|
|
+ return rc
|