Skip to content

Commit 0f5d826

Browse files
committed
check_kernel_commits: Show only fix commits that are not part of the pr_branch
Add a check before printing the fix commits (that contain Fixes tags) in case the commit is already present in the pr_branch. If so, nothing will be printed. If the commit is not present, then the warning will be shown and the reviewer has to fix it.
1 parent b651e1b commit 0f5d826

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

check_kernel_commits.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def hash_exists_in_mainline(repo, upstream_ref, hash_):
4646
except RuntimeError:
4747
return False
4848

49-
def find_fixes_in_mainline(repo, upstream_ref, hash_):
49+
def find_fixes_in_mainline(repo, pr_branch, upstream_ref, hash_):
5050
"""
5151
Return unique commits in upstream_ref that have Fixes: <N chars of hash_> in their message, case-insensitive.
5252
Start from 12 chars and work down to 6, but do not include duplicates if already found at a longer length.
@@ -77,12 +77,24 @@ def find_fixes_in_mainline(repo, upstream_ref, hash_):
7777
if m:
7878
for prefix in hash_prefixes:
7979
if m.group(1).lower().startswith(prefix.lower()):
80-
results.append(' '.join(header.split()[1:]))
80+
if not commit_exists_in_branch(repo, pr_branch, full_hash):
81+
results.append(' '.join(header.split()[1:]))
8182
break
8283
else:
8384
continue
8485
return "\n".join(results)
8586

87+
def commit_exists_in_branch(repo, pr_branch, upstream_hash_):
88+
"""
89+
Return True if upstream_hash_ has been backported and it exists in the
90+
pr branch
91+
"""
92+
output = run_git(repo, ['log', pr_branch, '--grep', 'commit ' + upstream_hash_])
93+
if not output:
94+
return False
95+
96+
return True
97+
8698
def wrap_paragraph(text, width=80, initial_indent='', subsequent_indent=''):
8799
"""Wrap a paragraph of text to the specified width and indentation."""
88100
wrapper = textwrap.TextWrapper(width=width,
@@ -153,7 +165,7 @@ def main():
153165
)
154166
out_lines.append("") # blank line
155167
continue
156-
fixes = find_fixes_in_mainline(args.repo, upstream_ref, uhash)
168+
fixes = find_fixes_in_mainline(args.repo, args.pr_branch, upstream_ref, uhash)
157169
if fixes:
158170
any_findings = True
159171
if args.markdown:

0 commit comments

Comments
 (0)