On 10/30/2026 10:30 AM, Alex Bennée wrote: > The current check for a referenced fix commit relies on the developer > keeping their master branch up to date which is not always guaranteed. > If you create your branches directly from the upstream repo this will > keep failing. Besides the local master could be anything. > > Improve the logic to divine which remote is pointing at the upstream > repo and use the remote master to check the fixes. > > checkpatch complains about the line lengths but this seems to be > standard for the perl script so I didn't try and fix it. > > Signed-off-by: Alex Bennée <[email protected]> > --- > v2 > - drop hard coding of remote in favour discovering it > --- > scripts/checkpatch.pl | 40 +++++++++++++++++++++++++++++++++++++--- > 1 file changed, 37 insertions(+), 3 deletions(-) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 4984a258ee5..cc311684d66 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -586,6 +586,37 @@ sub git_commit_info { > return ($id, $desc); > } > > +my $git_upstream_branch_checked = 0; > +my $git_upstream_branch_cached = undef; > + > +sub git_upstream_branch { > + return $git_upstream_branch_cached if ($git_upstream_branch_checked); > + $git_upstream_branch_checked = 1; > + > + return undef if ((which("git") eq "") || !(-e "$gitroot")); > + > + my $url_regex = > + qr{(?:gitlab\.com[/: ]qemu-project|github\.com[/: > ]qemu)/qemu(?:\.git)?$}i; > + > + # Scan configured remotes for the upstream repository > + my $output = `git remote -v 2>/dev/null`; > + for my $line (split(/\n/, $output)) { > + if ($line =~ /^\s*(\S+)\s+(\S+)\s+\(fetch\)/) { > + my ($remote, $url) = ($1, $2); > + if ($url =~ $url_regex) { > + my $ref = "$remote/master"; > + `git rev-parse --verify --quiet $ref > 2>/dev/null`; > + if ($? == 0) { > + $git_upstream_branch_cached = $ref; > + return $git_upstream_branch_cached; > + } > + } > + } > + } > + > + return undef; > +} > + > sub expand_tabs { > my ($str) = @_; > > @@ -1914,9 +1945,12 @@ sub process { > } > if (which("git") ne "" && -e "$gitroot") { > my $hash = defined($cid) ? $cid : > $orig_commit; > - `git merge-base --is-ancestor $hash > master 2>/dev/null`; > - if ($? != 0) { > - WARN("Fixes: commit $hash is > not an ancestor of master\n" . $herecurr); > + my $upstream = git_upstream_branch(); > + if (defined($upstream)) { > + `git merge-base --is-ancestor > $hash $upstream 2>/dev/null`; > + if ($? != 0) { > + WARN("Fixes: commit > $hash is not an ancestor of $upstream\n" . $herecurr); > + } > } > } > }
The gitlab/github is a bit arbitrary, but should work as it is. Acked-by: Pierrick Bouvier <[email protected]> Regards, Pierrick
