From 6db1b9e282c1bf6625ca19a595fb56be44ba276f Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 10 Jul 2019 15:32:36 -0400 Subject: [PATCH] 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 Tested-by: Mike Frysinger --- repo | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/repo b/repo index ce42ad06..114bb662 100755 --- a/repo +++ b/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():