linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Matteo Croce <mcroce@redhat.com>, LKML <linux-kernel@vger.kernel.org>
Cc: Andy Whitcroft <apw@canonical.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] checkpatch.pl: warn on invalid commit hash
Date: Wed, 10 Jul 2019 16:42:17 -0700	[thread overview]
Message-ID: <1918c98b8f25207dc45d46492944f2bcb464cd5d.camel@perches.com> (raw)
In-Reply-To: <20190710231919.9631-1-mcroce@redhat.com>

On Thu, 2019-07-11 at 01:19 +0200, Matteo Croce wrote:
> It can happen that a commit message refers to an invalid hash, because
> the referenced hash changed following a rebase, or simply by mistake.
> Add a check in checkpatch.pl which checks that an hash referenced by a Fixes
> tag or just cited in the commit message is a valid commit hash.

Hi Matteo

>     $ scripts/checkpatch.pl <<'EOF'
>     Subject: [PATCH] test commit
> 
>     Sample test commit to test checkpatch.pl
>     Commit 1da177e4c3f4 ("Linux-2.6.12-rc2") really exists,
>     commit 0bba044c4ce7 ("tree") is valid but not a commit,
>     while commit b4cc0b1c0cca ("unknown") is invalid.
> 
>     Fixes: f0cacc14cade ("unknown")
>     Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>     EOF
>     WARNING: Invalid hash 0bba044c4ce7
>     WARNING: Invalid hash b4cc0b1c0cca
>     WARNING: Invalid hash f0cacc14cade
>     total: 0 errors, 3 warnings, 4 lines checked

[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -2898,6 +2898,13 @@ sub process {
>  			}
>  		}
>  
> +# check for invalid hashes
> +		if ($in_commit_log && $line =~ /(^fixes:|commit)\s+([0-9a-f]{6,40})\b/i) {
> +			if (`git cat-file -t $2 2>/dev/null` ne "commit\n") {
> +				WARN('INVALID_COMMIT_HASH', "Invalid commit hash $2");

This seems fine as a concept, but this should use a
'\n' and . $herecurr like:

> 				WARN('INVALID_COMMIT_HASH', "Invalid commit hash $2\n" . $herecurr);

And while a single quote around the identifier works, please
use the double quote style like all the other uses of WARN.

Maybe call it "UNKNOWN_COMMIT_ID" too as it might be valid
for someone else's tree that has not yet been pulled and all
other references in checkpatch use ID rather than hash.

				WARN("UNKNOWN_COMMIT_HASH",
				     "Unknown commit id '$2', maybe rebased or not pulled?\n" . $herecurr);

Finally, why wouldn't the existing git_commit_info subroutine
be used instead of an independent 'git cat-file' which may not
even run if git is not available?

Perhaps use something like:

		my $id;
		my $description;
		($id, $description) = git_commit_info($2, undef, undef);
		if (!defined($id)) {
			WARN(etc...);
		}



      reply	other threads:[~2019-07-10 23:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-10 23:19 [PATCH] checkpatch.pl: warn on invalid commit hash Matteo Croce
2019-07-10 23:42 ` Joe Perches [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1918c98b8f25207dc45d46492944f2bcb464cd5d.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcroce@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).