From 334851e4b6390f4c78e463b977003f1d967c88ed Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 19 Sep 2011 08:05:31 -0700 Subject: Enhance HTTP support Setting REPO_CURL_VERBOSE=1 in the environment will register a debug level HTTPHandler on the urllib2 library, showing HTTP requests and responses on the stderr channel of repo. During any HTTP or HTTPS request created inside of the repo process, a custom User-Agent header is now defined: User-Agent: git-repo/1.7.5 (Linux) git/1.7.7 Python/2.6.5 Change-Id: Ia5026fb1e1500659bd2af27416d85e205048bf26 Signed-off-by: Shawn O. Pearce --- git_command.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'git_command.py') diff --git a/git_command.py b/git_command.py index 513b9ebf..d1e0c971 100644 --- a/git_command.py +++ b/git_command.py @@ -72,6 +72,8 @@ def terminate_ssh_clients(): pass _ssh_clients = [] +_git_version = None + class _GitCall(object): def version(self): p = GitCommand(None, ['--version'], capture_stdout=True) @@ -79,6 +81,21 @@ class _GitCall(object): return p.stdout return None + def version_tuple(self): + global _git_version + + if _git_version is None: + ver_str = git.version() + if ver_str.startswith('git version '): + _git_version = tuple( + map(lambda x: int(x), + ver_str[len('git version '):].strip().split('.')[0:3] + )) + else: + print >>sys.stderr, 'fatal: "%s" unsupported' % ver_str + sys.exit(1) + return _git_version + def __getattr__(self, name): name = name.replace('_','-') def fun(*cmdv): @@ -88,23 +105,9 @@ class _GitCall(object): return fun git = _GitCall() -_git_version = None - def git_require(min_version, fail=False): - global _git_version - - if _git_version is None: - ver_str = git.version() - if ver_str.startswith('git version '): - _git_version = tuple( - map(lambda x: int(x), - ver_str[len('git version '):].strip().split('.')[0:3] - )) - else: - print >>sys.stderr, 'fatal: "%s" unsupported' % ver_str - sys.exit(1) - - if min_version <= _git_version: + git_version = git.version_tuple() + if min_version <= git_version: return True if fail: need = '.'.join(map(lambda x: str(x), min_version)) -- cgit v1.2.3-54-g00ecf