Merge branch 'ap/svn'
authorJunio C Hamano <gitster@pobox.com>
Sun, 25 May 2008 20:37:25 +0000 (13:37 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 25 May 2008 20:37:25 +0000 (13:37 -0700)
* ap/svn:
git-svn: add test for --add-author-from and --use-log-author
git-svn: add documentation for --add-author-from option.
git-svn: Add --add-author-from option.
git-svn: add documentation for --use-log-author option.

Documentation/git-svn.txt
git-svn.perl
t/t9122-git-svn-author.sh [new file with mode: 0755]
index 3eae1ebb7dc104fd51c5e25d163ec33ab7b61ef1..c9e4efe7f4678ecc0beb87b387c71a7ebd0efc71 100644 (file)
@@ -61,6 +61,16 @@ COMMANDS
        Set the 'useSvnsyncProps' option in the [svn-remote] config.
 --rewrite-root=<URL>;;
        Set the 'rewriteRoot' option in the [svn-remote] config.
+--use-log-author;;
+       When retrieving svn commits into git (as part of fetch, rebase, or
+       dcommit operations), look for the first From: or Signed-off-by: line
+       in the log message and use that as the author string.
+--add-author-from;;
+       When committing to svn from git (as part of commit or dcommit
+       operations), if the existing log message doesn't already have a
+       From: or Signed-off-by: line, append a From: line based on the
+       git commit's author string.  If you use this, then --use-log-author
+       will retrieve a valid author string for all commits.
 --username=<USER>;;
        For transports that SVN handles authentication for (http,
        https, and plain svn), specify the username.  For other
index 2c53f39aefa0131cb15ab679e6b2633622c000a1..0e61897b9ecc255d3d22d016b46c90d3a30e9f38 100755 (executable)
@@ -83,6 +83,7 @@ BEGIN
                'repack-flags|repack-args|repack-opts=s' =>
                   \$Git::SVN::_repack_flags,
                'use-log-author' => \$Git::SVN::_use_log_author,
+               'add-author-from' => \$Git::SVN::_add_author_from,
                %remote_opts );
 
 my ($_trunk, $_tags, $_branches, $_stdlayout);
@@ -1012,17 +1013,28 @@ sub get_commit_entry {
                my ($msg_fh, $ctx) = command_output_pipe('cat-file',
                                                         $type, $treeish);
                my $in_msg = 0;
+               my $author;
+               my $saw_from = 0;
                while (<$msg_fh>) {
                        if (!$in_msg) {
                                $in_msg = 1 if (/^\s*$/);
+                               $author = $1 if (/^author (.*>)/);
                        } elsif (/^git-svn-id: /) {
                                # skip this for now, we regenerate the
                                # correct one on re-fetch anyways
                                # TODO: set *:merge properties or like...
                        } else {
+                               if (/^From:/ || /^Signed-off-by:/) {
+                                       $saw_from = 1;
+                               }
                                print $log_fh $_ or croak $!;
                        }
                }
+               if ($Git::SVN::_add_author_from && defined($author)
+                   && !$saw_from) {
+                       print $log_fh "\nFrom: $author\n"
+                             or croak $!;
+               }
                command_close_pipe($msg_fh, $ctx);
        }
        close $log_fh or croak $!;
@@ -1249,7 +1261,7 @@ package Git::SVN;
 use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
             $_repack $_repack_flags $_use_svm_props $_head
             $_use_svnsync_props $no_reuse_existing $_minimize_url
-           $_use_log_author/;
+           $_use_log_author $_add_author_from/;
 use Carp qw/croak/;
 use File::Path qw/mkpath/;
 use File::Copy qw/copy/;
diff --git a/t/t9122-git-svn-author.sh b/t/t9122-git-svn-author.sh
new file mode 100755 (executable)
index 0000000..8c58f0b
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/sh
+
+test_description='git svn authorship'
+. ./lib-git-svn.sh
+
+test_expect_success 'setup svn repository' '
+       svn checkout "$svnrepo" work.svn &&
+       (
+               cd work.svn &&
+               echo >file
+               svn add file
+               svn commit -m "first commit" file
+       )
+'
+
+test_expect_success 'interact with it via git-svn' '
+       mkdir work.git &&
+       (
+               cd work.git &&
+               git svn init "$svnrepo"
+               git svn fetch &&
+
+               echo modification >file &&
+               test_tick &&
+               git commit -a -m second &&
+
+               test_tick &&
+               git svn dcommit &&
+
+               echo "further modification" >file &&
+               test_tick &&
+               git commit -a -m third &&
+
+               test_tick &&
+               git svn --add-author-from dcommit &&
+
+               echo "yet further modification" >file &&
+               test_tick &&
+               git commit -a -m fourth &&
+
+               test_tick &&
+               git svn --add-author-from --use-log-author dcommit &&
+
+               git log &&
+
+               git show -s HEAD^^ >../actual.2 &&
+               git show -s HEAD^  >../actual.3 &&
+               git show -s HEAD   >../actual.4
+
+       ) &&
+
+       # Make sure that --add-author-from without --use-log-author
+       # did not affect the authorship information
+       myself=$(grep "^Author: " actual.2) &&
+       unaffected=$(grep "^Author: " actual.3) &&
+       test "z$myself" = "z$unaffected" &&
+
+       # Make sure lack of --add-author-from did not add cruft
+       ! grep "^    From: A U Thor " actual.2 &&
+
+       # Make sure --add-author-from added cruft
+       grep "^    From: A U Thor " actual.3 &&
+       grep "^    From: A U Thor " actual.4 &&
+
+       # Make sure --add-author-from with --use-log-author affected
+       # the authorship information
+       grep "^Author: A U Thor " actual.4
+'
+
+test_done