Skip to content

Commit d2e6df3

Browse files
gburgessivChromeos LUCI
authored andcommitted
llvm_tools: sync revert_checker from upstream
This integrates the changes made in llvm/llvm-project#134108 BUG=b:407969361 TEST=None (though tested upstream before landing) Change-Id: I405a4124728a1c80b27777aa038dfa5c0f2e7387 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/6428392 Tested-by: George Burgess <[email protected]> Reviewed-by: Jordan Abrahams-Whitehead <[email protected]> Auto-Submit: George Burgess <[email protected]> Commit-Queue: Jordan Abrahams-Whitehead <[email protected]>
1 parent 38b9903 commit d2e6df3

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

llvm_tools/revert_checker.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ def _rev_parse(git_dir: str, ref: str) -> str:
217217

218218

219219
def _find_common_parent_commit(git_dir: str, ref_a: str, ref_b: str) -> str:
220-
"""Finds the closest common parent commit between `ref_a` and `ref_b`."""
220+
"""Finds the closest common parent commit between `ref_a` and `ref_b`.
221+
222+
Returns:
223+
A SHA. Note that `ref_a` will be returned if `ref_a` is a parent of
224+
`ref_b`, and vice-versa.
225+
"""
221226
return subprocess.check_output(
222227
["git", "-C", git_dir, "merge-base", ref_a, ref_b],
223228
encoding="utf-8",
@@ -347,16 +352,31 @@ def find_reverts(
347352
)
348353
continue
349354

350-
if object_type == "commit":
351-
all_reverts.append(Revert(sha, reverted_sha))
355+
if object_type != "commit":
356+
logging.error(
357+
"%s claims to revert the %s %s, which isn't a commit",
358+
sha,
359+
object_type,
360+
reverted_sha,
361+
)
362+
continue
363+
364+
# Rarely, reverts will cite SHAs on other branches (e.g., revert
365+
# commit says it reverts a commit with SHA ${X}, but ${X} is not a
366+
# parent of the revert). This can happen if e.g., the revert has
367+
# been mirrored to another branch. Treat them the same as
368+
# reverts of non-commits.
369+
if _find_common_parent_commit(git_dir, sha, reverted_sha) != reverted_sha:
370+
logging.error(
371+
"%s claims to revert %s, which is a commit that is not "
372+
"a parent of the revert",
373+
sha,
374+
reverted_sha,
375+
)
352376
continue
353377

354-
logging.error(
355-
"%s claims to revert %s -- which isn't a commit -- %s",
356-
sha,
357-
object_type,
358-
reverted_sha,
359-
)
378+
all_reverts.append(Revert(sha, reverted_sha))
379+
360380

361381
# Since `all_reverts` contains reverts in log order (e.g., newer comes before
362382
# older), we need to reverse this to keep with our guarantee of older =

0 commit comments

Comments
 (0)