From 0f6ee87457745f643c4a4bef200b22bcd0f28758 Mon Sep 17 00:00:00 2001 From: Viacheslav Klimov Date: Fri, 16 Oct 2026 14:50:31 +0300 Subject: [PATCH] Stop a license check rename chain where its path was added or deleted --- .../src/main/python/license-headers/README.md | 4 +++- .../license-headers/check_license_headers.py | 16 +++++++++----- .../test_check_license_headers.py | 21 +++++++++++++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/tools/src/main/python/license-headers/README.md b/tools/src/main/python/license-headers/README.md index f82dbea870..69f3215149 100644 --- a/tools/src/main/python/license-headers/README.md +++ b/tools/src/main/python/license-headers/README.md @@ -26,7 +26,9 @@ header equals a CE version of it, or a clean merge of its CE versions, and A file whose path does not exist in CE but that a commit after the CE commits renamed from a CE path is `ce-modified`. Renames come from Git's rename -detection in non-merge commits other than the relicensing commit. +detection in non-merge commits other than the relicensing commit. A chain of +renames stops where its path was added or deleted, so a file created at a path +that a CE file was once renamed to does not inherit that CE file. Any other file whose path does not exist in CE is `busl`, except when it needs a decision: its content is at least 50% similar to a CE file, or CE history once diff --git a/tools/src/main/python/license-headers/check_license_headers.py b/tools/src/main/python/license-headers/check_license_headers.py index d60cc08073..991da6b2cc 100644 --- a/tools/src/main/python/license-headers/check_license_headers.py +++ b/tools/src/main/python/license-headers/check_license_headers.py @@ -849,15 +849,21 @@ def ce_renames(repo, head, bases, ce_paths): # A merge diff pairs a deletion and an addition from different sides, and the relicensing squash pairs # deleted CE files with similar PE files: neither is a rename. raw = git(repo, "log", "--no-merges", "--topo-order", "--raw", "--no-abbrev", "-M", "-l0", "-z", - "--diff-filter=R", "--format=%x1e%H", head, "--not", *bases, "--") - names, renames = {}, {} + "--diff-filter=RAD", "--format=%x1e%H", head, "--not", *bases, "--") + names = {} for change in parse_history(raw): if change.commit == RELICENSING_COMMIT: continue + if change.status[0] != "R": + names[change.path] = None + continue name = names.pop(change.path, change.path) - names[change.source] = name - if change.source in ce_paths: - renames.setdefault(name, change.source) + if name is not None: + names[change.source] = name + renames = {} + for source, name in names.items(): + if name is not None and source in ce_paths: + renames.setdefault(name, source) return renames diff --git a/tools/src/main/python/license-headers/test_check_license_headers.py b/tools/src/main/python/license-headers/test_check_license_headers.py index 0510b64240..b7173752c9 100644 --- a/tools/src/main/python/license-headers/test_check_license_headers.py +++ b/tools/src/main/python/license-headers/test_check_license_headers.py @@ -525,6 +525,27 @@ class GitHistoryTests(unittest.TestCase): with patch.object(p, "RELICENSING_COMMIT", squash): self.assertEqual({"Final.java": "Base.java"}, p.Lineage.load(git.root, head, [base]).renames) + def test_lineage_stops_a_rename_chain_at_a_deletion_or_addition(self): + git = GitFixture(temporary_directory(self), "ce") + body = "".join(f"CE line {index}\n" for index in range(20)) + git.write("A.java", body) + git.write("Reused.java", "reused " + body) + base = git.commit("CE base") + git("checkout", "-b", "downstream") + git("mv", "A.java", "B.java") + git.commit("rename") + git("rm", "-q", "B.java") + git.commit("delete") + git.write("B.java", "".join(f"unrelated line {index}\n" for index in range(20))) + git.commit("unrelated file at the renamed path") + git("rm", "-q", "Reused.java") + git.commit("delete a CE path") + git.write("Reused.java", "".join(f"downstream line {index}\n" for index in range(20))) + git.commit("reuse the CE path") + git("mv", "Reused.java", "Moved.java") + git.commit("rename the reused path") + self.assertEqual({}, p.Lineage.load(git.root, git("rev-parse", "HEAD"), [base]).renames) + @requires_merge_file_object_id def test_merge_blobs_returns_only_clean_merges(self): git = GitFixture(temporary_directory(self), "main")