diff options
Diffstat (limited to 'git_command.py')
-rw-r--r-- | git_command.py | 35 |
1 files changed, 19 insertions, 16 deletions
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(): | |||
72 | pass | 72 | pass |
73 | _ssh_clients = [] | 73 | _ssh_clients = [] |
74 | 74 | ||
75 | _git_version = None | ||
76 | |||
75 | class _GitCall(object): | 77 | class _GitCall(object): |
76 | def version(self): | 78 | def version(self): |
77 | p = GitCommand(None, ['--version'], capture_stdout=True) | 79 | p = GitCommand(None, ['--version'], capture_stdout=True) |
@@ -79,6 +81,21 @@ class _GitCall(object): | |||
79 | return p.stdout | 81 | return p.stdout |
80 | return None | 82 | return None |
81 | 83 | ||
84 | def version_tuple(self): | ||
85 | global _git_version | ||
86 | |||
87 | if _git_version is None: | ||
88 | ver_str = git.version() | ||
89 | if ver_str.startswith('git version '): | ||
90 | _git_version = tuple( | ||
91 | map(lambda x: int(x), | ||
92 | ver_str[len('git version '):].strip().split('.')[0:3] | ||
93 | )) | ||
94 | else: | ||
95 | print >>sys.stderr, 'fatal: "%s" unsupported' % ver_str | ||
96 | sys.exit(1) | ||
97 | return _git_version | ||
98 | |||
82 | def __getattr__(self, name): | 99 | def __getattr__(self, name): |
83 | name = name.replace('_','-') | 100 | name = name.replace('_','-') |
84 | def fun(*cmdv): | 101 | def fun(*cmdv): |
@@ -88,23 +105,9 @@ class _GitCall(object): | |||
88 | return fun | 105 | return fun |
89 | git = _GitCall() | 106 | git = _GitCall() |
90 | 107 | ||
91 | _git_version = None | ||
92 | |||
93 | def git_require(min_version, fail=False): | 108 | def git_require(min_version, fail=False): |
94 | global _git_version | 109 | git_version = git.version_tuple() |
95 | 110 | if min_version <= git_version: | |
96 | if _git_version is None: | ||
97 | ver_str = git.version() | ||
98 | if ver_str.startswith('git version '): | ||
99 | _git_version = tuple( | ||
100 | map(lambda x: int(x), | ||
101 | ver_str[len('git version '):].strip().split('.')[0:3] | ||
102 | )) | ||
103 | else: | ||
104 | print >>sys.stderr, 'fatal: "%s" unsupported' % ver_str | ||
105 | sys.exit(1) | ||
106 | |||
107 | if min_version <= _git_version: | ||
108 | return True | 111 | return True |
109 | if fail: | 112 | if fail: |
110 | need = '.'.join(map(lambda x: str(x), min_version)) | 113 | need = '.'.join(map(lambda x: str(x), min_version)) |