upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-23 17:43:03 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-23 17:43:03 -0500
commit3faeaf2ca68b4459f6f922244e7ef2ef2ab680dc (patch)
tree71d4969e4be077a96ea6d1d212863124c8c7fe62 /scripts
parenta9b505f98e72ab2096cd8016ff054173a4fe9fb5 (diff)
parent21016cf7aeefad9ed96b9bb8c4e76069b7eb0bb5 (diff)
Merge remote-tracking branch 'origin/pr/8980'
# Conflicts: # scripts/merge_check.py
Diffstat (limited to 'scripts')
-rw-r--r--scripts/merge_check.py66
1 files changed, 38 insertions, 28 deletions
diff --git a/scripts/merge_check.py b/scripts/merge_check.py
index e93a45a9e..9070aa3d6 100644
--- a/scripts/merge_check.py
+++ b/scripts/merge_check.py
@@ -104,12 +104,13 @@ def duplicates(repo, main, tree, min_length, block=3):
104 table or function body merged twice. A single repeated line is not reported: code and tables repeat lines 104 table or function body merged twice. A single repeated line is not reported: code and tables repeat lines
105 legitimately.""" 105 legitimately."""
106 found = {} 106 found = {}
107 hunks, path, added = {}, None, None 107 additions, path, added = {}, None, None
108 new_file = False 108 new_file = False
109 # Gitlink updates describe submodule commits and have no file text to compare. 109 # Gitlink updates describe submodule commits and have no file text to compare.
110 patch = git(repo, "-c", "core.quotePath=true", "diff", "--unified=0", "--no-color", "--no-renames", 110 patch = git(repo, "-c", "core.quotePath=true", "diff", "--unified=0", "--no-color", "--no-renames",
111 "--src-prefix=a/", "--dst-prefix=b/", "--no-relative", "--no-ext-diff", "--no-textconv", 111 "--inter-hunk-context=0", "--src-prefix=a/", "--dst-prefix=b/", "--no-relative",
112 "--ignore-submodules=all", main, tree).stdout 112 "--no-ext-diff", "--no-textconv", "--ignore-submodules=all",
113 main, tree).stdout
113 for line in patch.split("\n"): 114 for line in patch.split("\n"):
114 if line.startswith("diff --git "): 115 if line.startswith("diff --git "):
115 path, added = None, None 116 path, added = None, None
@@ -119,33 +120,42 @@ def duplicates(repo, main, tree, min_length, block=3):
119 elif added is None and line.startswith("+++ "): 120 elif added is None and line.startswith("+++ "):
120 path = None if new_file else patch_destination(line) 121 path = None if new_file else patch_destination(line)
121 elif line.startswith("@@ ") and path: 122 elif line.startswith("@@ ") and path:
122 added = [] 123 # The new-file range is +start[,count]. With zero context, only added lines advance it.
123 hunks.setdefault(path, []).append(added) 124 line_number = int(line.split()[2][1:].split(",")[0])
125 added = additions.setdefault(path, set())
124 elif added is not None and line.startswith("+"): 126 elif added is not None and line.startswith("+"):
125 text = line[1:].strip() 127 added.add(line_number)
126 if text: 128 line_number += 1
127 added.append(text) 129
128 def windows(rev, path): 130 def windows(rev, path):
129 out = git(repo, "show", f"{rev}:{path}").stdout 131 r = git(repo, "show", f"{rev}:{path}", check=False)
130 lines = [l.strip() for l in out.split("\n") if l.strip()] 132 if r.returncode:
131 return Counter(tuple(lines[i:i + block]) for i in range(len(lines) - block + 1)) 133 return None, Counter()
132 134 lines = [(number, text) for number, raw in enumerate(r.stdout.split("\n"), 1) if (text := raw.strip())]
133 for path, groups in hunks.items(): 135 content = [text for _, text in lines]
134 before = windows(main, path) 136 return lines, Counter(tuple(content[i:i + block]) for i in range(len(content) - block + 1))
135 after = windows(tree, path) 137
136 same = [] 138 for path, added in additions.items():
137 for added in groups: 139 if not added:
138 marked = [False] * len(added) 140 continue
139 for i in range(len(added) - block + 1): 141 before_lines, before = windows(main, path)
140 run = tuple(added[i:i + block]) 142 if before_lines is None:
141 # Doubled: on main already, and more copies after the merge. A block the PR moves (deleted where 143 continue # a new file: nothing to duplicate
142 # it was, added elsewhere) keeps its count and is not reported. 144 after_lines, after = windows(tree, path)
143 if all(len(x) >= min_length for x in run) and before[run] and after[run] > before[run]: 145 if after_lines is None:
144 for j in range(i, i + block): 146 continue
145 marked[j] = True 147 marked = set()
146 same += [x for x, m in zip(added, marked) if m] 148 for i in range(len(after_lines) - block + 1):
147 if same: 149 window = after_lines[i:i + block]
148 found[path] = same 150 # Blank lines are skipped, but each nonblank line in the window must be new.
151 if not all(number in added and len(text) >= min_length for number, text in window):
152 continue
153 run = tuple(text for _, text in window)
154 # Moving a block instead of duplicating it keeps the count unchanged.
155 if before[run] and after[run] > before[run]:
156 marked.update(number for number, _ in window)
157 if marked:
158 found[path] = [text for number, text in after_lines if number in marked]
149 return found 159 return found
150 160
151 161