Skip to content

Commit

Permalink
Merge branch 'ap/svn'
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
gitster committed May 25, 2008
2 parents 6c99f18 + 27554e9 commit 834836b
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Documentation/git-svn.txt
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion git-svn.perl
Expand Up @@ -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);
Expand Down Expand Up @@ -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 $!;
Expand Down Expand Up @@ -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/;
Expand Down
70 changes: 70 additions & 0 deletions t/t9122-git-svn-author.sh
@@ -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

0 comments on commit 834836b

Please sign in to comment.