Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 8552e2e

Browse files
committed
Merge branch 'bw/get-tz-offset-perl' into maint
* bw/get-tz-offset-perl: cvsimport: format commit timestamp ourselves without using strftime perl/Git.pm: fix get_tz_offset to properly handle DST boundary cases Move Git::SVN::get_tz to Git::get_tz_offset
2 parents b79faa9 + 48c9162 commit 8552e2e

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

git-cvsimport.perl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use IO::Pipe;
2727
use POSIX qw(strftime tzset dup2 ENOENT);
2828
use IPC::Open2;
29+
use Git qw(get_tz_offset);
2930

3031
$SIG{'PIPE'}="IGNORE";
3132
set_timezone('UTC');
@@ -864,7 +865,9 @@ sub commit {
864865
}
865866

866867
set_timezone($author_tz);
867-
my $commit_date = strftime("%s %z", localtime($date));
868+
# $date is in the seconds since epoch format
869+
my $tz_offset = get_tz_offset($date);
870+
my $commit_date = "$date $tz_offset";
868871
set_timezone('UTC');
869872
$ENV{GIT_AUTHOR_NAME} = $author_name;
870873
$ENV{GIT_AUTHOR_EMAIL} = $author_email;

perl/Git.pm

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ require Exporter;
5959
command_bidi_pipe command_close_bidi_pipe
6060
version exec_path html_path hash_object git_cmd_try
6161
remote_refs prompt
62+
get_tz_offset
6263
temp_acquire temp_release temp_reset temp_path);
6364

6465

@@ -102,6 +103,7 @@ use Error qw(:try);
102103
use Cwd qw(abs_path cwd);
103104
use IPC::Open2 qw(open2);
104105
use Fcntl qw(SEEK_SET SEEK_CUR);
106+
use Time::Local qw(timegm);
105107
}
106108

107109

@@ -511,6 +513,27 @@ C<git --html-path>). Useful mostly only internally.
511513

512514
sub html_path { command_oneline('--html-path') }
513515

516+
517+
=item get_tz_offset ( TIME )
518+
519+
Return the time zone offset from GMT in the form +/-HHMM where HH is
520+
the number of hours from GMT and MM is the number of minutes. This is
521+
the equivalent of what strftime("%z", ...) would provide on a GNU
522+
platform.
523+
524+
If TIME is not supplied, the current local time is used.
525+
526+
=cut
527+
528+
sub get_tz_offset {
529+
# some systmes don't handle or mishandle %z, so be creative.
530+
my $t = shift || time;
531+
my $gm = timegm(localtime($t));
532+
my $sign = qw( + + - )[ $gm <=> $t ];
533+
return sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
534+
}
535+
536+
514537
=item prompt ( PROMPT , ISPASSWORD )
515538
516539
Query user C<PROMPT> and return answer from user.

perl/Git/SVN.pm

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use Carp qw/croak/;
1111
use File::Path qw/mkpath/;
1212
use File::Copy qw/copy/;
1313
use IPC::Open3;
14-
use Time::Local;
1514
use Memoize; # core since 5.8.0, Jul 2002
1615
use Memoize::Storable;
1716
use POSIX qw(:signal_h);
@@ -22,6 +21,7 @@ use Git qw(
2221
command_noisy
2322
command_output_pipe
2423
command_close_pipe
24+
get_tz_offset
2525
);
2626
use Git::SVN::Utils qw(
2727
fatal
@@ -1311,14 +1311,6 @@ sub get_untracked {
13111311
\@out;
13121312
}
13131313

1314-
sub get_tz {
1315-
# some systmes don't handle or mishandle %z, so be creative.
1316-
my $t = shift || time;
1317-
my $gm = timelocal(gmtime($t));
1318-
my $sign = qw( + + - )[ $t <=> $gm ];
1319-
return sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
1320-
}
1321-
13221314
# parse_svn_date(DATE)
13231315
# --------------------
13241316
# Given a date (in UTC) from Subversion, return a string in the format
@@ -1351,7 +1343,7 @@ sub parse_svn_date {
13511343
delete $ENV{TZ};
13521344
}
13531345

1354-
my $our_TZ = get_tz();
1346+
my $our_TZ = get_tz_offset();
13551347

13561348
# This converts $epoch_in_UTC into our local timezone.
13571349
my ($sec, $min, $hour, $mday, $mon, $year,

perl/Git/SVN/Log.pm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ package Git::SVN::Log;
22
use strict;
33
use warnings;
44
use Git::SVN::Utils qw(fatal);
5-
use Git qw(command command_oneline command_output_pipe command_close_pipe);
5+
use Git qw(command
6+
command_oneline
7+
command_output_pipe
8+
command_close_pipe
9+
get_tz_offset);
610
use POSIX qw/strftime/;
711
use constant commit_log_separator => ('-' x 72) . "\n";
812
use vars qw/$TZ $limit $color $pager $non_recursive $verbose $oneline
@@ -119,7 +123,7 @@ sub run_pager {
119123
sub format_svn_date {
120124
my $t = shift || time;
121125
require Git::SVN;
122-
my $gmoff = Git::SVN::get_tz($t);
126+
my $gmoff = get_tz_offset($t);
123127
return strftime("%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)", localtime($t));
124128
}
125129

0 commit comments

Comments
 (0)