summaryrefslogtreecommitdiff
path: root/git-svn.perl
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2007-12-16 03:08:22 (GMT)
committerEric Wong <normalperson@yhbt.net>2007-12-19 08:04:21 (GMT)
commitad94802a7bc599ade73ec0b04c61b2f80b3c1b23 (patch)
treed80b965c187a60d225f09ea83ce432250ca0aafe /git-svn.perl
parentce85b053d827e2f7c2ee2683cc09393e4768cc22 (diff)
downloadgit-ad94802a7bc599ade73ec0b04c61b2f80b3c1b23.zip
git-ad94802a7bc599ade73ec0b04c61b2f80b3c1b23.tar.gz
git-ad94802a7bc599ade73ec0b04c61b2f80b3c1b23.tar.bz2
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>
Diffstat (limited to 'git-svn.perl')
-rwxr-xr-xgit-svn.perl50
1 files changed, 39 insertions, 11 deletions
diff --git a/git-svn.perl b/git-svn.perl
index d411a34..7cd62fc 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -2052,18 +2052,16 @@ sub full_url {
$self->{url} . (length $self->{path} ? '/' . $self->{path} : '');
}
-sub do_git_commit {
- my ($self, $log_entry) = @_;
- my $lr = $self->last_rev;
- if (defined $lr && $lr >= $log_entry->{revision}) {
- die "Last fetched revision of ", $self->refname,
- " was r$lr, but we are about to fetch: ",
- "r$log_entry->{revision}!\n";
- }
- if (my $c = $self->rev_map_get($log_entry->{revision})) {
- croak "$log_entry->{revision} = $c already exists! ",
- "Why are we refetching it?\n";
+
+sub set_commit_header_env {
+ my ($log_entry) = @_;
+ my %env;
+ foreach my $ned (qw/NAME EMAIL DATE/) {
+ foreach my $ac (qw/AUTHOR COMMITTER/) {
+ $env{"GIT_${ac}_${ned}"} = $ENV{"GIT_${ac}_${ned}"};
+ }
}
+
$ENV{GIT_AUTHOR_NAME} = $log_entry->{name};
$ENV{GIT_AUTHOR_EMAIL} = $log_entry->{email};
$ENV{GIT_AUTHOR_DATE} = $ENV{GIT_COMMITTER_DATE} = $log_entry->{date};
@@ -2074,7 +2072,36 @@ sub do_git_commit {
$ENV{GIT_COMMITTER_EMAIL} = (defined $log_entry->{commit_email})
? $log_entry->{commit_email}
: $log_entry->{email};
+ \%env;
+}
+sub restore_commit_header_env {
+ my ($env) = @_;
+ foreach my $ned (qw/NAME EMAIL DATE/) {
+ foreach my $ac (qw/AUTHOR COMMITTER/) {
+ my $k = "GIT_${ac}_${ned}";
+ if (defined $env->{$k}) {
+ $ENV{$k} = $env->{$k};
+ } else {
+ delete $ENV{$k};
+ }
+ }
+ }
+}
+
+sub do_git_commit {
+ my ($self, $log_entry) = @_;
+ my $lr = $self->last_rev;
+ if (defined $lr && $lr >= $log_entry->{revision}) {
+ die "Last fetched revision of ", $self->refname,
+ " was r$lr, but we are about to fetch: ",
+ "r$log_entry->{revision}!\n";
+ }
+ if (my $c = $self->rev_map_get($log_entry->{revision})) {
+ croak "$log_entry->{revision} = $c already exists! ",
+ "Why are we refetching it?\n";
+ }
+ my $old_env = set_commit_header_env($log_entry);
my $tree = $log_entry->{tree};
if (!defined $tree) {
$tree = $self->tmp_index_do(sub {
@@ -2089,6 +2116,7 @@ sub do_git_commit {
defined(my $pid = open3(my $msg_fh, my $out_fh, '>&STDERR', @exec))
or croak $!;
print $msg_fh $log_entry->{log} or croak $!;
+ restore_commit_header_env($old_env);
unless ($self->no_metadata) {
print $msg_fh "\ngit-svn-id: $log_entry->{metadata}\n"
or croak $!;