Merge branch 'ap/svn'

* 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.
This commit is contained in:
Junio C Hamano 2008-05-25 13:37:25 -07:00
commit 834836bd3f
3 changed files with 93 additions and 1 deletions

View File

@ -61,6 +61,16 @@ COMMANDS
Set the 'useSvnsyncProps' option in the [svn-remote] config. Set the 'useSvnsyncProps' option in the [svn-remote] config.
--rewrite-root=<URL>;; --rewrite-root=<URL>;;
Set the 'rewriteRoot' option in the [svn-remote] config. 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>;; --username=<USER>;;
For transports that SVN handles authentication for (http, For transports that SVN handles authentication for (http,
https, and plain svn), specify the username. For other https, and plain svn), specify the username. For other

View File

@ -83,6 +83,7 @@ my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
'repack-flags|repack-args|repack-opts=s' => 'repack-flags|repack-args|repack-opts=s' =>
\$Git::SVN::_repack_flags, \$Git::SVN::_repack_flags,
'use-log-author' => \$Git::SVN::_use_log_author, 'use-log-author' => \$Git::SVN::_use_log_author,
'add-author-from' => \$Git::SVN::_add_author_from,
%remote_opts ); %remote_opts );
my ($_trunk, $_tags, $_branches, $_stdlayout); my ($_trunk, $_tags, $_branches, $_stdlayout);
@ -1012,17 +1013,28 @@ sub get_commit_entry {
my ($msg_fh, $ctx) = command_output_pipe('cat-file', my ($msg_fh, $ctx) = command_output_pipe('cat-file',
$type, $treeish); $type, $treeish);
my $in_msg = 0; my $in_msg = 0;
my $author;
my $saw_from = 0;
while (<$msg_fh>) { while (<$msg_fh>) {
if (!$in_msg) { if (!$in_msg) {
$in_msg = 1 if (/^\s*$/); $in_msg = 1 if (/^\s*$/);
$author = $1 if (/^author (.*>)/);
} elsif (/^git-svn-id: /) { } elsif (/^git-svn-id: /) {
# skip this for now, we regenerate the # skip this for now, we regenerate the
# correct one on re-fetch anyways # correct one on re-fetch anyways
# TODO: set *:merge properties or like... # TODO: set *:merge properties or like...
} else { } else {
if (/^From:/ || /^Signed-off-by:/) {
$saw_from = 1;
}
print $log_fh $_ or croak $!; 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); command_close_pipe($msg_fh, $ctx);
} }
close $log_fh or croak $!; close $log_fh or croak $!;
@ -1249,7 +1261,7 @@ use constant rev_map_fmt => 'NH40';
use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
$_repack $_repack_flags $_use_svm_props $_head $_repack $_repack_flags $_use_svm_props $_head
$_use_svnsync_props $no_reuse_existing $_minimize_url $_use_svnsync_props $no_reuse_existing $_minimize_url
$_use_log_author/; $_use_log_author $_add_author_from/;
use Carp qw/croak/; use Carp qw/croak/;
use File::Path qw/mkpath/; use File::Path qw/mkpath/;
use File::Copy qw/copy/; use File::Copy qw/copy/;

70
t/t9122-git-svn-author.sh Executable file
View File

@ -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