mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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>
This commit is contained in:
parent
490e16385d
commit
6db1b9e282
12
repo
12
repo
@ -121,6 +121,7 @@ GITC_CONFIG_FILE = '/gitc/.config'
|
||||
GITC_FS_ROOT_DIR = '/gitc/manifest-rw/'
|
||||
|
||||
|
||||
import collections
|
||||
import errno
|
||||
import optparse
|
||||
import platform
|
||||
@ -377,18 +378,25 @@ def _Init(args, gitc_init=False):
|
||||
raise
|
||||
|
||||
|
||||
# The git version info broken down into components for easy analysis.
|
||||
# Similar to Python's sys.version_info.
|
||||
GitVersion = collections.namedtuple(
|
||||
'GitVersion', ('major', 'minor', 'micro', 'full'))
|
||||
|
||||
def ParseGitVersion(ver_str):
|
||||
if not ver_str.startswith('git version '):
|
||||
return None
|
||||
|
||||
num_ver_str = ver_str[len('git version '):].strip().split('-')[0]
|
||||
full_version = ver_str[len('git version '):].strip()
|
||||
num_ver_str = full_version.split('-')[0]
|
||||
to_tuple = []
|
||||
for num_str in num_ver_str.split('.')[:3]:
|
||||
if num_str.isdigit():
|
||||
to_tuple.append(int(num_str))
|
||||
else:
|
||||
to_tuple.append(0)
|
||||
return tuple(to_tuple)
|
||||
to_tuple.append(full_version)
|
||||
return GitVersion(*to_tuple)
|
||||
|
||||
|
||||
def _CheckGitVersion():
|
||||
|
Loading…
Reference in New Issue
Block a user