diff options
author | Conley Owens <cco3@android.com> | 2014-01-30 14:46:03 -0800 |
---|---|---|
committer | Conley Owens <cco3@android.com> | 2014-01-30 15:18:56 -0800 |
commit | ff0a3c8f80339960623acf76ec2bb6c1ad61c352 (patch) | |
tree | da428ef023417f9716f6aa6ce980a7777ed1d78c /repo | |
parent | 094cdbe090a18c35fdcfb463435d793cc0239e83 (diff) | |
download | git-repo-ff0a3c8f80339960623acf76ec2bb6c1ad61c352.tar.gz |
Share git version parsing code with wrapper modulev1.12.12
'repo' and 'git_command.py' had their own git version parsing code.
This change shares that code between the modules. DRY is good.
Change-Id: Ic896d2dc08353644bd4ced57e15a91284d97d54a
Diffstat (limited to 'repo')
-rwxr-xr-x | repo | 19 |
1 files changed, 16 insertions, 3 deletions
@@ -278,6 +278,20 @@ def _Init(args): | |||
278 | raise | 278 | raise |
279 | 279 | ||
280 | 280 | ||
281 | def ParseGitVersion(ver_str): | ||
282 | if not ver_str.startswith('git version '): | ||
283 | return None | ||
284 | |||
285 | num_ver_str = ver_str[len('git version '):].strip().split('-')[0] | ||
286 | to_tuple = [] | ||
287 | for num_str in num_ver_str.split('.')[:3]: | ||
288 | if num_str.isdigit(): | ||
289 | to_tuple.append(int(num_str)) | ||
290 | else: | ||
291 | to_tuple.append(0) | ||
292 | return tuple(to_tuple) | ||
293 | |||
294 | |||
281 | def _CheckGitVersion(): | 295 | def _CheckGitVersion(): |
282 | cmd = [GIT, '--version'] | 296 | cmd = [GIT, '--version'] |
283 | try: | 297 | try: |
@@ -295,12 +309,11 @@ def _CheckGitVersion(): | |||
295 | proc.stdout.close() | 309 | proc.stdout.close() |
296 | proc.wait() | 310 | proc.wait() |
297 | 311 | ||
298 | if not ver_str.startswith('git version '): | 312 | ver_act = ParseGitVersion(ver_str) |
313 | if ver_act is None: | ||
299 | _print('error: "%s" unsupported' % ver_str, file=sys.stderr) | 314 | _print('error: "%s" unsupported' % ver_str, file=sys.stderr) |
300 | raise CloneFailure() | 315 | raise CloneFailure() |
301 | 316 | ||
302 | ver_str = ver_str[len('git version '):].strip() | ||
303 | ver_act = tuple(map(int, ver_str.split('.')[0:3])) | ||
304 | if ver_act < MIN_GIT_VERSION: | 317 | if ver_act < MIN_GIT_VERSION: |
305 | need = '.'.join(map(str, MIN_GIT_VERSION)) | 318 | need = '.'.join(map(str, MIN_GIT_VERSION)) |
306 | _print('fatal: git %s or later required' % need, file=sys.stderr) | 319 | _print('fatal: git %s or later required' % need, file=sys.stderr) |