On 7/23/26 09:53, Cédric Le Goater wrote:
Adapt the kernel's checkpatch Fixes: tag validation for QEMU.
Add a git_commit_info() helper to resolve commit hashes and validate
the Fixes: tag in commit messages. The canonical form is:
Fixes: <12+ chars of sha1> ("<title line>")
The check validates capitalization, spacing, hash length, lowercase
hex, and quoted title. When the format is wrong and the commit can
be resolved, suggest the corrected Fixes: line.
When running inside a git repository, also verify that the referenced
commit is an ancestor of master.
Lines matching "Fixes: CVE-*" are skipped. The check can be disabled
with --no-fixes-tag.
Thank you for introducing this!
A comment below.
+sub git_commit_info {
+ my ($commit, $id, $desc) = @_;
+
+ return ($id, $desc) if ((which("git") eq "") || !(-e "$gitroot"));
+
+ my $output = `git log --no-color --format='%H %s' -1 $commit 2>&1`;
+ $output =~ s/^\s*//gm;
+ my @lines = split("\n", $output);
+
+ return ($id, $desc) if ($#lines < 0);
+
+ if ($lines[0] =~ /^fatal: ambiguous argument '$commit': unknown
revision or path not in the working tree\./ ||
+ $lines[0] =~ /^fatal: bad object $commit/) {
This is the first place in this script which depends on the C/EN
locale being in effect. With different locales, git will produce
different messages here.
Instead of relying on the exact wording, I think it's okay to check
for the exit status of git command, and only assume we found the
reference if git command finished successfully.
An alternative would be to export LC_ALL=C, but I think relying on
the git exit code is more reliable.
Thanks,
/mjt
+ $id = undef;
+ } else {
+ $id = substr($lines[0], 0, 12);
+ $desc = substr($lines[0], 41);
+ }
+
+ return ($id, $desc);
+}
+