summaryrefslogtreecommitdiff
path: root/git-cvsimport.perl
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2012-11-04 12:25:36 (GMT)
committerJeff King <peff@peff.net>2012-11-04 13:02:41 (GMT)
commitc2b3af0537e0b2c7624913b0f26191e992beb12c (patch)
tree668259ecf1719a81c6f18f6027fd711b0c2e42ce /git-cvsimport.perl
parentfb2c984148a344781833b25361154619230d9dd4 (diff)
downloadgit-c2b3af0537e0b2c7624913b0f26191e992beb12c.zip
git-c2b3af0537e0b2c7624913b0f26191e992beb12c.tar.gz
git-c2b3af0537e0b2c7624913b0f26191e992beb12c.tar.bz2
cvsimport: work around perl tzset issue
On many platforms, the first invocation of localtime_r will check $TZ in the environment, but subsequent invocations will use a cached value. That means that setting $ENV{TZ} in the middle of the program may or may not have an effect on later calls to localtime. Perl 5.10.0 and later handles this automatically for us, but we try to remain portable back to 5.8. Work around it by calling tzset ourselves.
Diffstat (limited to 'git-cvsimport.perl')
-rwxr-xr-xgit-cvsimport.perl17
1 files changed, 13 insertions, 4 deletions
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index ceb119d..0a31ebd 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -24,11 +24,11 @@ use File::Basename qw(basename dirname);
use Time::Local;
use IO::Socket;
use IO::Pipe;
-use POSIX qw(strftime dup2 ENOENT);
+use POSIX qw(strftime tzset dup2 ENOENT);
use IPC::Open2;
$SIG{'PIPE'}="IGNORE";
-$ENV{'TZ'}="UTC";
+set_timezone('UTC');
our ($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P, $opt_s,$opt_m,@opt_M,$opt_A,$opt_S,$opt_L, $opt_a, $opt_r, $opt_R);
my (%conv_author_name, %conv_author_email, %conv_author_tz);
@@ -99,6 +99,15 @@ sub write_author_info($) {
close ($f);
}
+# Versions of perl before 5.10.0 may not automatically check $TZ each
+# time localtime is run (most platforms will do so only the first time).
+# We can work around this by using tzset() to update the internal
+# variable whenever we change the environment.
+sub set_timezone {
+ $ENV{TZ} = shift;
+ tzset();
+}
+
# convert getopts specs for use by git config
my %longmap = (
'A:' => 'authors-file',
@@ -854,9 +863,9 @@ sub commit {
}
}
- $ENV{'TZ'}=$author_tz;
+ set_timezone($author_tz);
my $commit_date = strftime("%s %z", localtime($date));
- $ENV{'TZ'}="UTC";
+ set_timezone('UTC');
$ENV{GIT_AUTHOR_NAME} = $author_name;
$ENV{GIT_AUTHOR_EMAIL} = $author_email;
$ENV{GIT_AUTHOR_DATE} = $commit_date;