Skip to content

Commit 7511983

Browse files
committed
tests: kdoc: use git to find modified files
Using the patch directly fails when the patch formatting isn't done with git. Also I think it fails for pull requests. Signed-off-by: Jakub Kicinski <[email protected]>
1 parent be4d642 commit 7511983

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

tests/patch/kdoc/test.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -146,33 +146,27 @@ def run_kernel_doc(tree, commitish, files, logs) -> List[KdocWarning]:
146146

147147
return parse_warnings(lines, logs)
148148

149-
def extract_files(patch):
150-
"""Extract paths added or modified by the patch."""
149+
def extract_files(tree):
150+
"""Extract paths added or modified by the commit."""
151151

152-
before_files = set()
153-
after_files = set()
154-
lines = patch.raw_patch.split("\n")
152+
# Get files that existed before (modified or deleted)
153+
cmd = ["git", "diff", "--name-only", "--diff-filter=MD", "HEAD~.."]
154+
result = subprocess.run(cmd, cwd=tree.path, capture_output=True,
155+
text=True, check=True)
156+
before_files = [f for f in result.stdout.strip().split('\n') if f]
155157

156-
# Walk lines, skip last since it doesn't have next
157-
for i, line in enumerate(lines[:-1]):
158-
next_line = lines[i + 1]
158+
# Get files that exist after (added or modified)
159+
cmd = ["git", "diff", "--name-only", "--diff-filter=AM", "HEAD~.."]
160+
result = subprocess.run(cmd, cwd=tree.path, capture_output=True,
161+
text=True, check=True)
162+
after_files = [f for f in result.stdout.strip().split('\n') if f]
159163

160-
if not next_line.startswith("+++ b/"):
161-
continue
162-
163-
file_path = next_line[6:]
164-
165-
if "/dev/null" not in line:
166-
before_files.add(file_path)
167-
if "/dev/null" not in next_line:
168-
after_files.add(file_path)
169-
170-
return list(before_files), list(after_files)
164+
return before_files, after_files
171165

172-
def kdoc(tree, patch, _result_dir) -> Tuple[int, str, str]:
166+
def kdoc(tree, _patch, _result_dir) -> Tuple[int, str, str]:
173167
""" Main function / entry point """
174168

175-
before_files, after_files = extract_files(patch)
169+
before_files, after_files = extract_files(tree)
176170

177171
if not before_files and not after_files:
178172
return 1, "Patch has no modified files?", ""

0 commit comments

Comments
 (0)