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,27 +49,36 @@ 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))
|
||||||
Version(versions[0])
|
sys.exit(1)
|
||||||
use_hashes = False
|
|
||||||
versions.sort(key=Version)
|
|
||||||
except:
|
|
||||||
if verbose:
|
|
||||||
print("'{}' not a version - assuming commit hashes".format(versions[0]))
|
|
||||||
if not git_repo:
|
|
||||||
print('error: git repository argument required for commit hash sorting')
|
|
||||||
sys.exit(1)
|
|
||||||
if verbose:
|
|
||||||
print("using git repository '{}' to sort commit hashes".format(git_repo))
|
|
||||||
use_hashes = True
|
|
||||||
# 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'):
|
|
||||||
versions.remove('cppcheck')
|
|
||||||
versions = sort_commit_hashes(versions)
|
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print("found {} versions in '{}'".format(len(versions), directory))
|
print("found {} versions in '{}'".format(len(versions), directory))
|
||||||
|
|
||||||
|
try:
|
||||||
|
Version(versions[0])
|
||||||
|
use_hashes = False
|
||||||
|
versions.sort(key=Version)
|
||||||
|
except:
|
||||||
|
if verbose:
|
||||||
|
print("'{}' not a version - assuming commit hashes".format(versions[0]))
|
||||||
|
if not git_repo:
|
||||||
|
print('error: git repository argument required for commit hash sorting')
|
||||||
|
sys.exit(1)
|
||||||
|
if verbose:
|
||||||
|
print("using git repository '{}' to sort commit hashes".format(git_repo))
|
||||||
|
use_hashes = True
|
||||||
|
# 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'):
|
||||||
|
versions.remove('cppcheck')
|
||||||
|
len_in = len(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:
|
||||||
print("analyzing '{}'".format(input_file))
|
print("analyzing '{}'".format(input_file))
|
||||||
|
|
||||||
last_ec = None
|
last_ec = None
|
||||||
|
|
Loading…
Reference in New Issue