gitlog-to-changelog: support multi-author commits.
authorGary V. Vaughan <gary@gnu.org>
Tue, 1 Nov 2011 10:58:37 +0000 (17:58 +0700)
committerGary V. Vaughan <gary@gnu.org>
Thu, 17 Nov 2011 05:08:53 +0000 (12:08 +0700)
The FSF cares about keeping track of all authors of patches to its
projects, but Git doesn't provide obvious support for multi-author
changesets. Consensus seems to be forming around the use of extra
Signed-off-by inspired lines in the log message formatted as
`Co-authored-by: A U Thor <email@example.com>' for round-tripping
multi-author commits between version control systems.
* gitlog-to-changelog: Extract `Co-authored-by:' lines from the git
log message and output in standard ChangeLog multi-author format.
Reported by Peter Rosin <peda@lysator.liu.se>

ChangeLog
build-aux/gitlog-to-changelog

index eddc691..49ae5ca 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2011-11-01  Gary V. Vaughan  <gary@gnu.org>
+
+       gitlog-to-changelog: support multi-author commits.
+       The FSF cares about keeping track of all authors of patches to its
+       projects, but Git doesn't provide obvious support for multi-author
+       changesets. Consensus seems to be forming around the use of extra
+       Signed-off-by inspired lines in the log message formatted as
+       `Co-authored-by: A U Thor <email@example.com>' for round-tripping
+       multi-author commits between version control systems.
+       * gitlog-to-changelog: Extract `Co-authored-by:' lines from the git
+       log message and output in standard ChangeLog multi-author format.
+       Reported by Peter Rosin <peda@lysator.liu.se>
+
 2011-11-15  Ben Walton <bwalton@artsci.utoronto.ca>  (tiny change)
            Bruno Haible  <bruno@clisp.org>
 
index 56c7e4e..40a8035 100755 (executable)
@@ -200,6 +200,7 @@ sub parse_amend_file($)
             . "(Is your Git too old?  Version 1.5.1 or later is required.)\n");
 
   my $prev_date_line = '';
+  my @prev_coauthors = ();
   while (1)
     {
       defined (my $in = <PIPE>)
@@ -249,18 +250,36 @@ sub parse_amend_file($)
           . "(expected date/author/email):\n$author_line\n";
 
       my $date_line = sprintf "%s  $2\n", strftime ("%F", localtime ($1));
-      # If this line would be the same as the previous date/name/email
-      # line, then arrange not to print it.
-      if ($date_line ne $prev_date_line)
+
+      # Format 'Co-authored-by: A U Thor <email@example.com>' lines in
+      # standard multi-author ChangeLog format.
+      my @coauthors = grep /^Co-authored-by:.*$/, @line;
+      for (@coauthors)
+        {
+          s/^Co-authored-by:\s*/\t    /;
+          s/\s*</  </;
+
+          /<.*?@.*\..*>/
+            or warn "$ME: warning: missing email address for "
+              . substr ($_, 5) . "\n";
+        }
+
+      # If this header would be the same as the previous date/name/email/
+      # coauthors header, then arrange not to print it.
+      if ($date_line ne $prev_date_line or "@coauthors" ne "@prev_coauthors")
         {
           $prev_date_line eq ''
             or print "\n";
           print $date_line;
+          @coauthors
+            and print join ("\n", @coauthors), "\n";
         }
       $prev_date_line = $date_line;
+      @prev_coauthors = @coauthors;
 
-      # Omit "Signed-off-by..." lines.
+      # Omit "Co-authored-by..." and "Signed-off-by..." lines.
       @line = grep !/^Signed-off-by: .*>$/, @line;
+      @line = grep !/^Co-authored-by: /, @line;
 
       # Remove leading and trailing blank lines.
       if (@line)