git-svn: avoid leaving leftover committer/author info in rebase
We set the 6 environment variables for controlling committer/author email/name/time for every commit. We do this in the parent process to be passed to git-commit-tree, because open3() doesn't afford us the control of doing it only in the child process. This means we leave them hanging around in the main process until the next revision comes around and all 6 environment variables are overwridden again. Unfortunately, for the last commit, leaving them hanging around means the git-rebase invocation will pick it up, rewriting the rebased commit with incorrect author information. This should fix it. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Dec 15, 2007 at 19:08 UTC
ad94802a7bc599ade73ec0b04c61b2f80b3c1b23
1 file changed
+39
-11
git-svn.perl
+39
-11
@@ -2052,18 +2052,16 @@ sub full_url {
2052
$self->{url} . (length $self->{path} ? '/' . $self->{path} : '');
2053
}
2054
2055
-sub do_git_commit {
2056
- my ($self, $log_entry) = @_;
2057
- my $lr = $self->last_rev;
2058
- if (defined $lr && $lr >= $log_entry->{revision}) {
2059
- die "Last fetched revision of ", $self->refname,
2060
- " was r$lr, but we are about to fetch: ",
2061
- "r$log_entry->{revision}!\n";
2062
- }
2063
- if (my $c = $self->rev_map_get($log_entry->{revision})) {
2064
- croak "$log_entry->{revision} = $c already exists! ",
2065
- "Why are we refetching it?\n";
2055
+
2056
+sub set_commit_header_env {
2057
+ my ($log_entry) = @_;
2058
+ my %env;
2059
+ foreach my $ned (qw/NAME EMAIL DATE/) {
2060
+ foreach my $ac (qw/AUTHOR COMMITTER/) {
2061
+ $env{"GIT_${ac}_${ned}"} = $ENV{"GIT_${ac}_${ned}"};
2062
+ }
2063
}
2064
+
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};
@@ -2074,7 +2072,36 @@ sub do_git_commit {
2072
$ENV{GIT_COMMITTER_EMAIL} = (defined $log_entry->{commit_email})
2073
? $log_entry->{commit_email}
2074
: $log_entry->{email};
2075
+ \%env;
2076
+}
2077
2078
+sub restore_commit_header_env {
2079
+ my ($env) = @_;
2080
+ foreach my $ned (qw/NAME EMAIL DATE/) {
2081
+ foreach my $ac (qw/AUTHOR COMMITTER/) {
2082
+ my $k = "GIT_${ac}_${ned}";
2083
+ if (defined $env->{$k}) {
2084
+ $ENV{$k} = $env->{$k};
2085
+ } else {
2086
+ delete $ENV{$k};
2087
+ }
2088
+ }
2089
+ }
2090
+}
2091
+
2092
+sub do_git_commit {
2093
+ my ($self, $log_entry) = @_;
2094
+ my $lr = $self->last_rev;
2095
+ if (defined $lr && $lr >= $log_entry->{revision}) {
2096
+ die "Last fetched revision of ", $self->refname,
2097
+ " was r$lr, but we are about to fetch: ",
2098
+ "r$log_entry->{revision}!\n";
2099
+ }
2100
+ if (my $c = $self->rev_map_get($log_entry->{revision})) {
2101
+ croak "$log_entry->{revision} = $c already exists! ",
2102
+ "Why are we refetching it?\n";
2103
+ }
2104
+ my $old_env = set_commit_header_env($log_entry);
2105
my $tree = $log_entry->{tree};
2106
if (!defined $tree) {
2107
$tree = $self->tmp_index_do(sub {
@@ -2089,6 +2116,7 @@ sub do_git_commit {
2116
defined(my $pid = open3(my $msg_fh, my $out_fh, '>&STDERR', @exec))
2117
or croak $!;
2118
print $msg_fh $log_entry->{log} or croak $!;
2119
+ restore_commit_header_env($old_env);
2120
unless ($self->no_metadata) {
2121
print $msg_fh "\ngit-svn-id: $log_entry->{metadata}\n"
2122
or croak $!;