triage_version.py: improved error handling of version input and sorting (#4667)
This commit is contained in:
parent
d7416bc1e9
commit
525181c5aa
|
@ -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,12 +49,18 @@ for filename in os.listdir(directory):
|
||||||
continue
|
continue
|
||||||
versions.append(filename)
|
versions.append(filename)
|
||||||
|
|
||||||
if len(versions):
|
if not len(versions):
|
||||||
try:
|
print("error: no versions found in '{}'".format(directory))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print("found {} versions in '{}'".format(len(versions), directory))
|
||||||
|
|
||||||
|
try:
|
||||||
Version(versions[0])
|
Version(versions[0])
|
||||||
use_hashes = False
|
use_hashes = False
|
||||||
versions.sort(key=Version)
|
versions.sort(key=Version)
|
||||||
except:
|
except:
|
||||||
if verbose:
|
if verbose:
|
||||||
print("'{}' not a version - assuming commit hashes".format(versions[0]))
|
print("'{}' not a version - assuming commit hashes".format(versions[0]))
|
||||||
if not git_repo:
|
if not git_repo:
|
||||||
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue