[PATCH] Munge ChangeLog-style commit messages, and grab author name and email.
From: Carl Worth <hidden>
Date: 2016-06-15 22:42:18
Subsystem:
the rest · Maintainer:
Linus Torvalds
The cairo project has been using ChangeLog-style commit messages, such as: 2006-01-18 Carl Worth [off-list ref] * src/cairo-pdf-surface.c: (cairo_pdf_surface_create_for_stream), (cairo_pdf_surface_create): Fix compilation-breaking typo. This patch recognizes that style and munges it up into: Fix compilation-breaking typo. which results in a much more useful headline within git. It also grabs the name and email address from the first line and commits with those as GIT_AUTHOR_NAME and GIT_AUTHOR_MAIL. It would probably make sense to hide all this munging behind an appropriate command-line parameter, but I'm offering this up as is in case it's useful for anyone with similar commit messages. Signed-off-by: Carl Worth <redacted> Signed-off-by: Keith Packard <keithp@keithp.com> --- git-cvsimport.perl | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 71 insertions(+), 0 deletions(-) 2f2002fe619c45cb1be1c0f063416ede242f3552
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 00fc3ba..6b63aa2 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl@@ -658,6 +658,12 @@ my $commit = sub { } } + # Look for name and email from ChangeLog-style commit message + if ($logmsg =~ /^\s*\d\d\d\d-\d\d-\d\d\s*(.*)\s*<(.*)>/) { + $author_name = $1; + $author_email = $2; + } + exec("env", "GIT_AUTHOR_NAME=$author_name", "GIT_AUTHOR_EMAIL=$author_email",
@@ -673,8 +679,73 @@ my $commit = sub { # compatibility with git2cvs substr($logmsg,32767) = "" if length($logmsg) > 32767; + + # We do a bunch of munging on the log message here, + # particularly for logs that are formatted in a ChangeLog + # style. + + my $origlog = $logmsg; + + # Kill initial date/name stamp: YYYY-MM-DD First Last <email@example.com> + + $logmsg =~ s|^\s*\d\d*-\d\d*-\d\d*\s*[^<\n]*<[^>\n]*>\s*$|* \n|mg; + + # Strip out nickle version numbers + $logmsg =~ s|^(version )?2.\d\d*$||mg; + + # Remove initial space for each line + $logmsg =~ s|^[ \t]+||mg; + + # Collapse space sequences + $logmsg =~ s|[ \t]+| |g; + + # Un-fold paragraphs + $logmsg =~ s|([^\n])\n([^*+\-\n])|$1 $2|g; + + my @lines = split (/\n/, $logmsg); + + $logmsg = ""; + + my $reviews = ""; + + foreach my $line (@lines) { + # Pull out any reviewed-by name + if ($line =~ /^reviewed by:\s*/i) { + if ($line !~ /<delete if not using/) { + $reviews = $reviews . "\n" . $line; + } + } else { + # find lines begining with '*' + if ($line =~ s/^\*\s\s*//) { + # strip off filenames + while ($line =~ s/^[^ :,]*([,:]| (?=\())\s*// ) { + } + # strip off function names + while ($line =~ s/^\([^)]*\)[,:]*\s*// ) { + } + } + $logmsg = $logmsg . $line . "\n"; + } + } + $logmsg = $logmsg . $reviews; + + # Trim initial newlines + $logmsg =~ s|^\n+||; + + # Remove initial space for each line + $logmsg =~ s|^[ \t]+||mg; + + # Collapse space sequences + $logmsg =~ s|[ \t]+| |g; + + # collapse sequences of newlines + $logmsg =~ s/\n\n*/\n/g; + + # Remove trailing whitespace $logmsg =~ s/[\s\n]+\z//; +# print "<<<< Original\n$origlog\n---- Rewritten\n$logmsg\n<<<<\n"; + if (@skipped) { $logmsg .= "\n\n\nSKIPPED:\n\t"; $logmsg .= join("\n\t", @skipped) . "\n";
--
1.1.6.g9da5