git-svn: restore original LC_ALL setting (or unset) for commit
svn forces UTF-8 for commit messages, and with LC_ALL set to 'C' it is unable to determine encoding of the git commit message. Now we'll just assume the user has set LC_* correctly for the commit message they're using. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Jun 2, 2006 at 15:16 UTC
ce475dfcb5021339d8545a020e8697dd35a1bbea
1 file changed
+23
-11
contrib/git-svn/git-svn.perl
+23
-11
@@ -14,6 +14,7 @@ use Cwd qw/abs_path/;
14
$GIT_DIR = abs_path($ENV{GIT_DIR} || '.git');
15
$ENV{GIT_DIR} = $GIT_DIR;
16
17
+my $LC_ALL = $ENV{LC_ALL};
18
# make sure the svn binary gives consistent output between locales and TZs:
19
$ENV{TZ} = 'UTC';
20
$ENV{LC_ALL} = 'C';
@@ -704,23 +705,34 @@ sub svn_commit_tree {
705
my ($oneline) = ($log_msg{msg} =~ /([^\n\r]+)/);
706
print "Committing $commit: $oneline\n";
707
708
+ if (defined $LC_ALL) {
709
+ $ENV{LC_ALL} = $LC_ALL;
710
+ } else {
711
+ delete $ENV{LC_ALL};
712
+ }
713
my @ci_output = safe_qx(qw(svn commit -F),$commit_msg);
708
- my ($committed) = grep(/^Committed revision \d+\./,@ci_output);
714
+ $ENV{LC_ALL} = 'C';
715
unlink $commit_msg;
710
- defined $committed or croak
716
+ my ($committed) = ($ci_output[$#ci_output] =~ /(\d+)/);
717
+ if (!defined $committed) {
718
+ my $out = join("\n",@ci_output);
719
+ print STDERR "W: Trouble parsing \`svn commit' output:\n\n",
720
+ $out, "\n\nAssuming English locale...";
721
+ ($committed) = ($out =~ /^Committed revision \d+\./sm);
722
+ defined $committed or die " FAILED!\n",
723
"Commit output failed to parse committed revision!\n",
712
- join("\n",@ci_output),"\n";
713
- my ($rev_committed) = ($committed =~ /^Committed revision (\d+)\./);
724
+ print STDERR " OK\n";
725
+ }
726
727
my @svn_up = qw(svn up);
728
push @svn_up, '--ignore-externals' unless $_no_ignore_ext;
717
- if ($rev_committed == ($svn_rev + 1)) {
718
- push @svn_up, "-r$rev_committed";
729
+ if ($committed == ($svn_rev + 1)) {
730
+ push @svn_up, "-r$committed";
731
sys(@svn_up);
732
my $info = svn_info('.');
733
my $date = $info->{'Last Changed Date'} or die "Missing date\n";
722
- if ($info->{'Last Changed Rev'} != $rev_committed) {
723
- croak "$info->{'Last Changed Rev'} != $rev_committed\n"
734
+ if ($info->{'Last Changed Rev'} != $committed) {
735
+ croak "$info->{'Last Changed Rev'} != $committed\n"
736
}
737
my ($Y,$m,$d,$H,$M,$S,$tz) = ($date =~
738
/(\d{4})\-(\d\d)\-(\d\d)\s
@@ -728,16 +740,16 @@ sub svn_commit_tree {
740
or croak "Failed to parse date: $date\n";
741
$log_msg{date} = "$tz $Y-$m-$d $H:$M:$S";
742
$log_msg{author} = $info->{'Last Changed Author'};
731
- $log_msg{revision} = $rev_committed;
743
+ $log_msg{revision} = $committed;
744
$log_msg{msg} .= "\n";
745
my $parent = file_to_s("$REV_DIR/$svn_rev");
746
git_commit(\%log_msg, $parent, $commit);
735
- return $rev_committed;
747
+ return $committed;
748
}
749
# resync immediately
750
push @svn_up, "-r$svn_rev";
751
sys(@svn_up);
740
- return fetch("$rev_committed=$commit")->{revision};
752
+ return fetch("$committed=$commit")->{revision};
753
}
754
755
# read the entire log into a temporary file (which is removed ASAP)