@matheusbsbs / matheus-bagliano / commits / 70ae04e4e8
Fork 0

git-svn: add support for pulling author from From: and Signed-off-by:

Add support for pulling the real author of a commit from the From: and first Signed-off-by: fields of the SVN commit message. Signed-off-by: Andy Whitcroft <apw@shadowen.org> Acked-by: Eric Wong <normalperson@yhbt.net>

Andy Whitcroft committed Nov 22, 2007 at 13:44 UTC 70ae04e4e8ef49ede31b77ca0e70c641dfff6d01
1 file changed +30 -7
git-svn.perl
+30 -7
@@ -81,6 +81,7 @@ my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
81 'quiet|q' => \$_q,
82 'repack-flags|repack-args|repack-opts=s' =>
83 \$Git::SVN::_repack_flags,
84 + 'use-log-author' => \$Git::SVN::_use_log_author,
85 %remote_opts );
86
87 my ($_trunk, $_tags, $_branches, $_stdlayout);
@@ -1220,7 +1221,8 @@ use strict;
1221 use warnings;
1222 use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
1223 $_repack $_repack_flags $_use_svm_props $_head
1223 - $_use_svnsync_props $no_reuse_existing $_minimize_url/;
1224 + $_use_svnsync_props $no_reuse_existing $_minimize_url
1225 + $_use_log_author/;
1226 use Carp qw/croak/;
1227 use File::Path qw/mkpath/;
1228 use File::Copy qw/copy/;
@@ -2060,11 +2062,17 @@ sub do_git_commit {
2062 croak "$log_entry->{revision} = $c already exists! ",
2063 "Why are we refetching it?\n";
2064 }
2063 - $ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} = $log_entry->{name};
2064 - $ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} =
2065 - $log_entry->{email};
2065 + $ENV{GIT_AUTHOR_NAME} = $log_entry->{name};
2066 + $ENV{GIT_AUTHOR_EMAIL} = $log_entry->{email};
2067 $ENV{GIT_AUTHOR_DATE} = $ENV{GIT_COMMITTER_DATE} = $log_entry->{date};
2068
2069 + $ENV{GIT_COMMITTER_NAME} = (defined $log_entry->{commit_name})
2070 + ? $log_entry->{commit_name}
2071 + : $log_entry->{name};
2072 + $ENV{GIT_COMMITTER_EMAIL} = (defined $log_entry->{commit_email})
2073 + ? $log_entry->{commit_email}
2074 + : $log_entry->{email};
2075 +
2076 my $tree = $log_entry->{tree};
2077 if (!defined $tree) {
2078 $tree = $self->tmp_index_do(sub {
@@ -2352,7 +2360,17 @@ sub make_log_entry {
2360 $log_entry{log} .= "\n";
2361 my $author = $log_entry{author} = check_author($log_entry{author});
2362 my ($name, $email) = defined $::users{$author} ? @{$::users{$author}}
2355 - : ($author, undef);
2363 + : ($author, undef);
2364 +
2365 + my ($commit_name, $commit_email) = ($name, $email);
2366 + if ($_use_log_author) {
2367 + if ($log_entry{log} =~ /From:\s+(.*?)\s+<(.*)>\s*\n/) {
2368 + ($name, $email) = ($1, $2);
2369 + } elsif ($log_entry{log} =~
2370 + /Signed-off-by:\s+(.*?)\s+<(.*)>\s*\n/) {
2371 + ($name, $email) = ($1, $2);
2372 + }
2373 + }
2374 if (defined $headrev && $self->use_svm_props) {
2375 if ($self->rewrite_root) {
2376 die "Can't have both 'useSvmProps' and 'rewriteRoot' ",
@@ -2375,23 +2393,28 @@ sub make_log_entry {
2393 remove_username($full_url);
2394 $log_entry{metadata} = "$full_url\@$r $uuid";
2395 $log_entry{svm_revision} = $r;
2378 - $email ||= "$author\@$uuid"
2396 + $email ||= "$author\@$uuid";
2397 + $commit_email ||= "$author\@$uuid";
2398 } elsif ($self->use_svnsync_props) {
2399 my $full_url = $self->svnsync->{url};
2400 $full_url .= "/$self->{path}" if length $self->{path};
2401 remove_username($full_url);
2402 my $uuid = $self->svnsync->{uuid};
2403 $log_entry{metadata} = "$full_url\@$rev $uuid";
2385 - $email ||= "$author\@$uuid"
2404 + $email ||= "$author\@$uuid";
2405 + $commit_email ||= "$author\@$uuid";
2406 } else {
2407 my $url = $self->metadata_url;
2408 remove_username($url);
2409 $log_entry{metadata} = "$url\@$rev " .
2410 $self->ra->get_uuid;
2411 $email ||= "$author\@" . $self->ra->get_uuid;
2412 + $commit_email ||= "$author\@" . $self->ra->get_uuid;
2413 }
2414 $log_entry{name} = $name;
2415 $log_entry{email} = $email;
2416 + $log_entry{commit_name} = $commit_name;
2417 + $log_entry{commit_email} = $commit_email;
2418 \%log_entry;
2419 }
2420