Browse Source

Stop a license check rename chain where its path was added or deleted

pull/16341/head
Viacheslav Klimov 2 months ago
parent
commit
0f6ee87457
Failed to extract signature
  1. 4
      tools/src/main/python/license-headers/README.md
  2. 16
      tools/src/main/python/license-headers/check_license_headers.py
  3. 21
      tools/src/main/python/license-headers/test_check_license_headers.py

4
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

16
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

21
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")

Loading…
Cancel
Save