Optionally parse author information
authorRamkumar Ramachandra <artagnon@gmail.com>
Fri, 14 Jan 2011 10:16:38 +0000 (14 15:46 +0530)
committerLove Hörnquist Åstrand <lha@kth.se>
Fri, 14 Jan 2011 11:15:17 +0000 (14 12:15 +0100)
When creating a new commit, instead of picking up the SVN author from
the committer's email, pick it up from the author's email, when
possible. Also add a new command-line switch '--ignore-author' to
force older behavior for backward compatibilty.

Noticed-by: Joe Corneli <holtzermann17@gmail.com>
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Love Hörnquist Åstrand <lha@kth.se>
git2svn

diff --git a/git2svn b/git2svn
index 2380775..8ef55f1 100755 (executable)
--- a/git2svn
+++ b/git2svn
@@ -36,7 +36,7 @@ use Pod::Usage;
 my $IN;
 my $OUT;
 
-my ($help, $verbose, $keeplogs, $no_load);
+my ($help, $verbose, $keeplogs, $no_load, $ignore_author);
 
 # svn
 my $svntree = "repro";
@@ -200,6 +200,7 @@ $result = GetOptions ("git-branch=s" => \$branch,
                      "svn-prefix=s" => \$basedir,
                      "keep-logs" => \$keeplogs,
                      "no-load" => \$no_load,
+                     "ignore-author" => \$ignore_author,
                      "verbose+" => \$verbose,
                      "help" => \$help) or pod2usage(2);
 
@@ -261,12 +262,15 @@ COMMAND: while (!eof(IN)) {
            $commit{Mark} = $1;
            $next = next_line($IN);
        }
-       if ($next =~ m/author +(.*)/) {
-           $commit{Author} = $1;
+       if ($next =~ m/author +(.+) +<([^>]+)> +(\d+) +[+-](\d+)$/) {
+           $commit{AuthorName} = $1;
+           $commit{AuthorEmail} = $2;
+           $commit{AuthorWhen} = $3;
+           $commit{AuthorTZ} = $4;
            $next = next_line($IN);
        }
        unless ($next =~ m/committer +(.+) +<([^>]+)> +(\d+) +[+-](\d+)$/) {
-           die "missing comitter: $_";
+           die "missing committer: $_";
        }
 
        $commit{CommitterName} = $1;
@@ -291,11 +295,15 @@ COMMAND: while (!eof(IN)) {
            strftime("%Y-%m-%dT%H:%M:%S.000000Z", 
                     gmtime($commit{CommitterWhen}));
 
-       my $author = "(no author)";
+       my $author = "git2svn-dump";
        if ($commit{CommitterEmail} =~ m/([^@]+)/) {
            $author = $1;
        }
-       $author = "git2svn-dump" if ($author eq "(no author)");
+       unless ($ignore_author) {
+           if ($commit{AuthorEmail} =~ m/([^@]+)/) {
+               $author = $1;
+           }
+       }
 
        my $props = "";
        $props .= prop("svn:author", $author);
@@ -486,6 +494,11 @@ match the default GIT branch (master).
 
 Don't load the svn repository or update the syncpoint tagname.
 
+=item B<--ignore-author>
+
+Ignore "author" lines in the fast-import stream. Use "committer"
+information instead.
+
 =item B<--keep-logs>
 
 Don't delete the logs in $CWD/.data on success.