aboutsummaryrefslogtreecommitdiff
path: root/llvm_tools
diff options
context:
space:
mode:
authorGeorge Burgess IV <gbiv@google.com>2021-08-03 06:59:24 +0000
committerGeorge Burgess <gbiv@chromium.org>2021-08-03 19:48:02 +0000
commit14fda118b124a783297391c2a54e54d67009820d (patch)
treedb4451c8a8905c4d3eae722aa3692a920a636830 /llvm_tools
parent05c8210cc7bbf8041e5f66cbfe134ca0667c3a76 (diff)
downloadtoolchain-utils-14fda118b124a783297391c2a54e54d67009820d.tar.gz
git_llvm_rev: prefer upstream/* branches over non-upstream/ branches
It seems that LLVM has an old precedent of `release/${version}` branches, but has swapped to naming new branches `upstream/release/${version}`. This includes a retroactive addition of `upstream/release/${version}` for old versions, which makes the `ValueError` here get raised. Prefer the newer, shinier names. BUG=b:194731505 TEST=./git_llvm_rev_test.py Change-Id: If170c004eae0edf1a69792207e5c681deb10e50b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3068860 Reviewed-by: Bob Haarman <inglorion@chromium.org> Tested-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'llvm_tools')
-rwxr-xr-xllvm_tools/git_llvm_rev.py5
-rwxr-xr-xllvm_tools/git_llvm_rev_test.py6
2 files changed, 8 insertions, 3 deletions
diff --git a/llvm_tools/git_llvm_rev.py b/llvm_tools/git_llvm_rev.py
index c8c1505c..b62b26e2 100755
--- a/llvm_tools/git_llvm_rev.py
+++ b/llvm_tools/git_llvm_rev.py
@@ -183,6 +183,11 @@ def translate_sha_to_rev(llvm_config: LLVMConfig, sha_or_ref: str) -> Rev:
raise ValueError(
f'No viable branches found from {llvm_config.remote} with {sha}')
+ # It seems that some `origin/release/.*` branches have
+ # `origin/upstream/release/.*` equivalents, which is... awkward to deal with.
+ # Prefer the latter, since that seems to have newer commits than the former.
+ # Technically n^2, but len(elements) should be like, tens in the worst case.
+ candidates = [x for x in candidates if f'upstream/{x}' not in candidates]
if len(candidates) != 1:
raise ValueError(
f'Ambiguity: multiple branches from {llvm_config.remote} have {sha}: '
diff --git a/llvm_tools/git_llvm_rev_test.py b/llvm_tools/git_llvm_rev_test.py
index 74280c5d..d05093a8 100755
--- a/llvm_tools/git_llvm_rev_test.py
+++ b/llvm_tools/git_llvm_rev_test.py
@@ -93,7 +93,7 @@ class Test(unittest.TestCase):
def test_zz_branch_revs_work_after_merge_points_and_svn_cutoff(self) -> None:
# Arbitrary 9.x commit without an attached llvm-svn: value.
sha = self.rev_to_sha_with_round_trip(
- git_llvm_rev.Rev(branch='release/9.x', number=366670))
+ git_llvm_rev.Rev(branch='upstream/release/9.x', number=366670))
self.assertEqual(sha, '4e858e4ac00b59f064da4e1f7e276916e7d296aa')
def test_zz_branch_revs_work_at_merge_points(self) -> None:
@@ -108,7 +108,7 @@ class Test(unittest.TestCase):
# branch, we'll pick main for this. That's fine.
sha = git_llvm_rev.translate_rev_to_sha(
get_llvm_config(),
- git_llvm_rev.Rev(branch='release/9.x', number=rev_number))
+ git_llvm_rev.Rev(branch='upstream/release/9.x', number=rev_number))
self.assertEqual(sha, backing_sha)
def test_zz_branch_revs_work_after_merge_points(self) -> None:
@@ -117,7 +117,7 @@ class Test(unittest.TestCase):
# ours, and are therefore untrustworthy. The commit for this *does* have a
# different `llvm-svn:` string than we should have.
sha = self.rev_to_sha_with_round_trip(
- git_llvm_rev.Rev(branch='release/9.x', number=366427))
+ git_llvm_rev.Rev(branch='upstream/release/9.x', number=366427))
self.assertEqual(sha, '2cf681a11aea459b50d712abc7136f7129e4d57f')