From a415697d70794f0e6e09135e1e107390c2f46435 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Wed, 18 May 2022 13:19:11 -0500 Subject: [PATCH] Allow result sha to be overriden with local sha (#77832) --- hacking/azp/incidental.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/hacking/azp/incidental.py b/hacking/azp/incidental.py index 10729299dd4..87d4d213c94 100755 --- a/hacking/azp/incidental.py +++ b/hacking/azp/incidental.py @@ -86,6 +86,10 @@ def parse_args(): action='store_true', help='increase verbosity') + parser.add_argument('--result-sha', + default=None, + help='Override the result sha') + targets = parser.add_mutually_exclusive_group() targets.add_argument('--targets', @@ -131,11 +135,13 @@ def incidental_report(args): git = Git(os.path.abspath(args.source)) coverage_data = CoverageData(os.path.abspath(args.result)) + result_sha = args.result_sha or coverage_data.result_sha + try: - git.show([coverage_data.result_sha, '--']) + git.show([result_sha, '--']) except subprocess.CalledProcessError: raise ApplicationError('%s: commit not found: %s\n' - 'make sure your source repository is up-to-date' % (git.path, coverage_data.result_sha)) + 'make sure your source repository is up-to-date' % (git.path, result_sha)) if coverage_data.result != "succeeded": check_failed(args, 'results indicate tests did not pass (result: %s)\n' @@ -225,7 +231,7 @@ def incidental_report(args): cached(source_expanded_target_path, args.use_cache, args.verbose, lambda: ct.expand(source_target_path, source_expanded_target_path)) - summary[target_name] = sources = collect_sources(source_expanded_target_path, git, coverage_data) + summary[target_name] = sources = collect_sources(source_expanded_target_path, git, coverage_data, result_sha) txt_report_path = os.path.join(reports_path, '%s.txt' % cache_name) cached(txt_report_path, args.use_cache, args.verbose, @@ -364,7 +370,7 @@ class SourceFile: self.covered_lines = set(abs(p[0]) for p in self.covered_points) | set(abs(p[1]) for p in self.covered_points) -def collect_sources(data_path, git, coverage_data): +def collect_sources(data_path, git, coverage_data, result_sha): with open(data_path) as data_file: data = json.load(data_file) @@ -372,7 +378,7 @@ def collect_sources(data_path, git, coverage_data): for path_coverage in data.values(): for path, path_data in path_coverage.items(): - sources.append(SourceFile(path, git.show(['%s:%s' % (coverage_data.result_sha, path)]), coverage_data, path_data)) + sources.append(SourceFile(path, git.show(['%s:%s' % (result_sha, path)]), coverage_data, path_data)) return sources