From fb2316146f6e3036e0cc3e08653920964a428a15 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 10 Apr 2009 18:53:46 -0700 Subject: Automatically use SSH control master support during sync By creating a background ssh "control master" process which lives for the duration of our sync cycle we can easily cut the time for a no-op sync of 132 projects from 60s to 18s. Bug: REPO-11 Signed-off-by: Shawn O. Pearce --- git_command.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'git_command.py') diff --git a/git_command.py b/git_command.py index b6a4a343..954bebad 100644 --- a/git_command.py +++ b/git_command.py @@ -16,6 +16,7 @@ import os import sys import subprocess +import tempfile from error import GitError from trace import REPO_TRACE, IsTrace, Trace @@ -26,6 +27,27 @@ GIT_DIR = 'GIT_DIR' LAST_GITDIR = None LAST_CWD = None +_ssh_proxy_path = None +_ssh_sock_path = None + +def _ssh_sock(create=True): + global _ssh_sock_path + if _ssh_sock_path is None: + if not create: + return None + _ssh_sock_path = os.path.join( + tempfile.mkdtemp('', 'ssh-'), + 'master-%r@%h:%p') + return _ssh_sock_path + +def _ssh_proxy(): + global _ssh_proxy_path + if _ssh_proxy_path is None: + _ssh_proxy_path = os.path.join( + os.path.dirname(__file__), + 'git_ssh') + return _ssh_proxy_path + class _GitCall(object): def version(self): @@ -52,6 +74,7 @@ class GitCommand(object): capture_stdout = False, capture_stderr = False, disable_editor = False, + ssh_proxy = False, cwd = None, gitdir = None): env = dict(os.environ) @@ -68,6 +91,9 @@ class GitCommand(object): if disable_editor: env['GIT_EDITOR'] = ':' + if ssh_proxy: + env['REPO_SSH_SOCK'] = _ssh_sock() + env['GIT_SSH'] = _ssh_proxy() if project: if not cwd: -- cgit v1.2.3-54-g00ecf