@matheusbsbs / matheus-bagliano / commits / 6aa9ba14a0
Fork 0

git-svn: Add --add-author-from option.

This option adds a From: line (based on the commit's author information) at the beginning of the body of the commit log message when sending to svn, if a From: or Signed-off-by: header does not exist. This, combined with --use-log-author, can retain the author field of commits through a round trip from git to svn and back. Signed-off-by: Avery Pennarun <apenwarr@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Avery Pennarun committed Apr 15, 2008 at 21:04 UTC 6aa9ba14a0259d86eec2077308358caf891c162a
1 file changed +13 -1
git-svn.perl
+13 -1
@@ -82,6 +82,7 @@ my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
82 'repack-flags|repack-args|repack-opts=s' =>
83 \$Git::SVN::_repack_flags,
84 'use-log-author' => \$Git::SVN::_use_log_author,
85 + 'add-author-from' => \$Git::SVN::_add_author_from,
86 %remote_opts );
87
88 my ($_trunk, $_tags, $_branches, $_stdlayout);
@@ -1011,17 +1012,28 @@ sub get_commit_entry {
1012 my ($msg_fh, $ctx) = command_output_pipe('cat-file',
1013 $type, $treeish);
1014 my $in_msg = 0;
1015 + my $author;
1016 + my $saw_from = 0;
1017 while (<$msg_fh>) {
1018 if (!$in_msg) {
1019 $in_msg = 1 if (/^\s*$/);
1020 + $author = $1 if (/^author (.*>)/);
1021 } elsif (/^git-svn-id: /) {
1022 # skip this for now, we regenerate the
1023 # correct one on re-fetch anyways
1024 # TODO: set *:merge properties or like...
1025 } else {
1026 + if (/^From:/ || /^Signed-off-by:/) {
1027 + $saw_from = 1;
1028 + }
1029 print $log_fh $_ or croak $!;
1030 }
1031 }
1032 + if ($Git::SVN::_add_author_from && defined($author)
1033 + && !$saw_from) {
1034 + print $log_fh "\nFrom: $author\n"
1035 + or croak $!;
1036 + }
1037 command_close_pipe($msg_fh, $ctx);
1038 }
1039 close $log_fh or croak $!;
@@ -1248,7 +1260,7 @@ use constant rev_map_fmt => 'NH40';
1260 use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
1261 $_repack $_repack_flags $_use_svm_props $_head
1262 $_use_svnsync_props $no_reuse_existing $_minimize_url
1251 - $_use_log_author/;
1263 + $_use_log_author $_add_author_from/;
1264 use Carp qw/croak/;
1265 use File::Path qw/mkpath/;
1266 use File::Copy qw/copy/;