diff options
author | Mike Frysinger <vapier@google.com> | 2019-07-10 15:32:36 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2019-07-11 01:28:14 +0000 |
commit | 6db1b9e282c1bf6625ca19a595fb56be44ba276f (patch) | |
tree | d0e1152a57a00e6a0dd000becc95e6f0bda9cdd2 | |
parent | 490e16385db3c0ba674cd6e03fa6e915e3f050ca (diff) | |
download | git-repo-6db1b9e282c1bf6625ca19a595fb56be44ba276f.tar.gz |
repo: return a namedtuple with full version info
We were returning an e.g. tuple(1,2,3), but that strips off the full
version string which we might want in some places e.g. '1.2.3-rc3'.
Change the return value to a namedtuple so we can pass back up the
full version string. For code doing a compare with three elements
(all code today), things still work fine as the namedtuple will DTRT
in this scenario.
Bug: https://crbug.com/gerrit/11144
Change-Id: Ib897b5df308116ad1550b0cf18f49afeb662423e
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/231053
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
-rwxr-xr-x | repo | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -121,6 +121,7 @@ GITC_CONFIG_FILE = '/gitc/.config' | |||
121 | GITC_FS_ROOT_DIR = '/gitc/manifest-rw/' | 121 | GITC_FS_ROOT_DIR = '/gitc/manifest-rw/' |
122 | 122 | ||
123 | 123 | ||
124 | import collections | ||
124 | import errno | 125 | import errno |
125 | import optparse | 126 | import optparse |
126 | import platform | 127 | import platform |
@@ -377,18 +378,25 @@ def _Init(args, gitc_init=False): | |||
377 | raise | 378 | raise |
378 | 379 | ||
379 | 380 | ||
381 | # The git version info broken down into components for easy analysis. | ||
382 | # Similar to Python's sys.version_info. | ||
383 | GitVersion = collections.namedtuple( | ||
384 | 'GitVersion', ('major', 'minor', 'micro', 'full')) | ||
385 | |||
380 | def ParseGitVersion(ver_str): | 386 | def ParseGitVersion(ver_str): |
381 | if not ver_str.startswith('git version '): | 387 | if not ver_str.startswith('git version '): |
382 | return None | 388 | return None |
383 | 389 | ||
384 | num_ver_str = ver_str[len('git version '):].strip().split('-')[0] | 390 | full_version = ver_str[len('git version '):].strip() |
391 | num_ver_str = full_version.split('-')[0] | ||
385 | to_tuple = [] | 392 | to_tuple = [] |
386 | for num_str in num_ver_str.split('.')[:3]: | 393 | for num_str in num_ver_str.split('.')[:3]: |
387 | if num_str.isdigit(): | 394 | if num_str.isdigit(): |
388 | to_tuple.append(int(num_str)) | 395 | to_tuple.append(int(num_str)) |
389 | else: | 396 | else: |
390 | to_tuple.append(0) | 397 | to_tuple.append(0) |
391 | return tuple(to_tuple) | 398 | to_tuple.append(full_version) |
399 | return GitVersion(*to_tuple) | ||
392 | 400 | ||
393 | 401 | ||
394 | def _CheckGitVersion(): | 402 | def _CheckGitVersion(): |