From: Jacob Keller <jacob.e.keller@intel.com>
To: intel-wired-lan@osuosl.org
Subject: [Intel-wired-lan] [PATCH] checkpatch.pl: allow commit descriptions to include date
Date: Wed, 4 Oct 2017 17:33:58 -0700 [thread overview]
Message-ID: <20171005003358.3879-1-jacob.e.keller@intel.com> (raw)
Since commit d311cd44545f ("checkpatch: add test for commit id
formatting style in commit log") checkpatch has supported a check that
git commit references are done in a standardized way.
Some communities (the Git mailing list, among others) advocate the
addition of a date to the end of the description, converting
d311cd44545f ("checkpatch: add test for commit id formatting style in commit log")
into
d311cd44545f ("checkpatch: add test for commit id formatting style in commit log", 2014-08-06)
Extend checkpatch.pl to allow such a date, and add verification that the
date matches the commit author date, if it exists.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
scripts/checkpatch.pl | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index ebea4f078246..2076e9833025 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -871,15 +871,15 @@ sub seed_camelcase_includes {
}
sub git_commit_info {
- my ($commit, $id, $desc) = @_;
+ my ($commit, $id, $date, $desc) = @_;
- return ($id, $desc) if ((which("git") eq "") || !(-e ".git"));
+ return ($id, $date, $desc) if ((which("git") eq "") || !(-e ".git"));
- my $output = `git log --no-color --format='%H %s' -1 $commit 2>&1`;
+ my $output = `git log --date=short --no-color --format='%H %ad %s' -1 $commit 2>&1`;
$output =~ s/^\s*//gm;
my @lines = split("\n", $output);
- return ($id, $desc) if ($#lines < 0);
+ return ($id, $date, $desc) if ($#lines < 0);
if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous\./) {
# Maybe one day convert this block of bash into something that returns
@@ -895,10 +895,11 @@ sub git_commit_info {
$id = undef;
} else {
$id = substr($lines[0], 0, 12);
- $desc = substr($lines[0], 41);
+ $date = substr($lines[0], 41, 10);
+ $desc = substr($lines[0], 52);
}
- return ($id, $desc);
+ return ($id, $date, $desc);
}
$chk_signoff = 0 if ($file);
@@ -2597,6 +2598,8 @@ sub process {
my $hasdesc = 0;
my $hasparens = 0;
my $id = '0123456789ab';
+ my $orig_date = undef;
+ my $date = "";
my $orig_desc = "commit description";
my $description = "";
@@ -2611,29 +2614,32 @@ sub process {
$long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i);
$space = 0 if ($line =~ /\bcommit [0-9a-f]/i);
$case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
- if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) {
+ if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"(,\s*([-0-9]+))?\)/i) {
$orig_desc = $1;
+ $orig_date = $3;
$hasparens = 1;
} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
defined $rawlines[$linenr] &&
- $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) {
+ $rawlines[$linenr] =~ /^\s*\("([^"]+)"(,\s*([-0-9]+))?\)/) {
$orig_desc = $1;
+ $orig_date = $3;
$hasparens = 1;
} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
defined $rawlines[$linenr] &&
- $rawlines[$linenr] =~ /^\s*[^"]+"\)/) {
+ $rawlines[$linenr] =~ /^\s*[^"]+"(,\s*([-0-9]+))?\)/) {
$line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
$orig_desc = $1;
- $rawlines[$linenr] =~ /^\s*([^"]+)"\)/;
+ $rawlines[$linenr] =~ /^\s*([^"]+)"(,\s*([-0-9]+))?\)/;
$orig_desc .= " " . $1;
+ $orig_date = $3;
$hasparens = 1;
}
- ($id, $description) = git_commit_info($orig_commit,
- $id, $orig_desc);
+ ($id, $date, $description) = git_commit_info($orig_commit,
+ $id, $orig_date, $orig_desc);
if (defined($id) &&
- ($short || $long || $space || $case || ($orig_desc ne $description) || !$hasparens)) {
+ ($short || $long || $space || $case || ($orig_desc ne $description) || ($orig_date && $orig_date ne $date) || !$hasparens)) {
ERROR("GIT_COMMIT_ID",
"Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herecurr);
}
--
2.14.1.436.g33e61a4f0239
next reply other threads:[~2017-10-05 0:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-05 0:33 Jacob Keller [this message]
2019-04-03 2:09 ` [Intel-wired-lan] [PATCH] checkpatch.pl: allow commit descriptions to include date Brown, Aaron F
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=20171005003358.3879-1-jacob.e.keller@intel.com \
--to=jacob.e.keller@intel.com \
--cc=intel-wired-lan@osuosl.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.