triage_version.py: improved error handling of version input and sorting (#4667)

This commit is contained in:
Oliver Stöneberg 2023-01-01 15:27:21 +01:00 committed by GitHub
parent d7416bc1e9
commit 525181c5aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 20 deletions

View File

@ -22,8 +22,12 @@ args = parser.parse_args()
def sort_commit_hashes(commits): def sort_commit_hashes(commits):
git_cmd = 'git rev-list --abbrev-commit --topo-order --no-walk=sorted --reverse ' + ' '.join(commits) git_cmd = 'git rev-list --abbrev-commit --topo-order --no-walk=sorted --reverse ' + ' '.join(commits)
p = subprocess.Popen(git_cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=git_repo, universal_newlines=True) p = subprocess.Popen(git_cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=git_repo, universal_newlines=True)
comm = p.communicate() stdout, stderr = p.communicate()
return comm[0].splitlines() if p.returncode != 0:
print('error: sorting commit hashes failed')
print(stderr)
sys.exit(1)
return stdout.splitlines()
verbose = args.verbose verbose = args.verbose
do_compare = args.compare do_compare = args.compare
@ -45,7 +49,13 @@ for filename in os.listdir(directory):
continue continue
versions.append(filename) versions.append(filename)
if len(versions): if not len(versions):
print("error: no versions found in '{}'".format(directory))
sys.exit(1)
if verbose:
print("found {} versions in '{}'".format(len(versions), directory))
try: try:
Version(versions[0]) Version(versions[0])
use_hashes = False use_hashes = False
@ -62,10 +72,13 @@ if len(versions):
# if you use the folder from the bisect script that contains the repo as a folder - so remove it from the list # if you use the folder from the bisect script that contains the repo as a folder - so remove it from the list
if versions.count('cppcheck'): if versions.count('cppcheck'):
versions.remove('cppcheck') versions.remove('cppcheck')
len_in = len(versions)
versions = sort_commit_hashes(versions) versions = sort_commit_hashes(versions)
if len(versions) != len_in:
print('error: unexpected amount of versions after commit hash sorting')
sys.exit(1)
if verbose: if verbose:
print("found {} versions in '{}'".format(len(versions), directory))
print("analyzing '{}'".format(input_file)) print("analyzing '{}'".format(input_file))
last_ec = None last_ec = None