threads / patch / 3294

patchMunge ChangeLog-style commit messages, and grab author name and email.

Subject: [PATCH] Munge ChangeLog-style commit messages, and grab author name and email.

## tl;dr

2 messages between Feb 11, 2006 and Feb 11, 2006. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Carl Worth· Feb 11, 2006, 01:19 UTC · lore
The cairo project has been using ChangeLog-style commit messages, such as:
	2006-01-18  Carl Worth  <cworth@cworth.org>
		* 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 <cworth@cworth.org>
Signed-off-by: Keith Packard <keithp@keithp.com>
---
 git-cvsimport.perl |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)
2f2002fe619c45cb1be1c0f063416ede242f3552
Show changes to git-cvsimport.perl +71 −0
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
Junio C Hamano· Feb 11, 2006, 05:39 UTC · re: Carl Worth · lore

Re: [PATCH] Munge ChangeLog-style commit messages, and grab author name and email.

Carl Worth <cworth@cworth.org> writes:
Show 12 quoted lines
> The cairo project has been using ChangeLog-style commit messages, such as:
>
> 	2006-01-18  Carl Worth  <cworth@cworth.org>
>
> 		* 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.

I welcome discussion on this patch, but as its in current shape, it looks a bit too specific to one particular style.

I think the one you quoted above is the GNU official style which is used in many projects. I suspect your patch would help people converting other projects as well. Having said that, as you said it yourself, it would make more sense to make a more generalized log munging interface.

Even though there might be many different schools of style, hopefully each project consistently sticks to one style. Log messages out of SVN repository tend to have their own styles. We could define a common command line option, say --log-filter, that are available across importers. E.g.

	git-cvsimport --log-filter=gnu-log-style
	git-svnimport --log-filter=gnu-log-style

'gnu-log-style' would be the massager you have hardcoded in the patch, but made into a traditional UNIXy filter. We could create contrib/commit-filters directory in git.git repository and ship collections of such log massagers.

← back to recent threads