Skip to content

Commit

Permalink
Merge branch 'bw/get-tz-offset-perl' into maint
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gitster committed Feb 25, 2013
2 parents b79faa9 + 48c9162 commit 8552e2e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
5 changes: 4 additions & 1 deletion git-cvsimport.perl
Expand Up @@ -26,6 +26,7 @@
use IO::Pipe;
use POSIX qw(strftime tzset dup2 ENOENT);
use IPC::Open2;
use Git qw(get_tz_offset);

$SIG{'PIPE'}="IGNORE";
set_timezone('UTC');
Expand Down Expand Up @@ -864,7 +865,9 @@ sub commit {
}

set_timezone($author_tz);
my $commit_date = strftime("%s %z", localtime($date));
# $date is in the seconds since epoch format
my $tz_offset = get_tz_offset($date);
my $commit_date = "$date $tz_offset";
set_timezone('UTC');
$ENV{GIT_AUTHOR_NAME} = $author_name;
$ENV{GIT_AUTHOR_EMAIL} = $author_email;
Expand Down
23 changes: 23 additions & 0 deletions perl/Git.pm
Expand Up @@ -59,6 +59,7 @@ require Exporter;
command_bidi_pipe command_close_bidi_pipe
version exec_path html_path hash_object git_cmd_try
remote_refs prompt
get_tz_offset
temp_acquire temp_release temp_reset temp_path);


Expand Down Expand Up @@ -102,6 +103,7 @@ use Error qw(:try);
use Cwd qw(abs_path cwd);
use IPC::Open2 qw(open2);
use Fcntl qw(SEEK_SET SEEK_CUR);
use Time::Local qw(timegm);
}


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

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


=item get_tz_offset ( TIME )
Return the time zone offset from GMT in the form +/-HHMM where HH is
the number of hours from GMT and MM is the number of minutes. This is
the equivalent of what strftime("%z", ...) would provide on a GNU
platform.
If TIME is not supplied, the current local time is used.
=cut

sub get_tz_offset {
# some systmes don't handle or mishandle %z, so be creative.
my $t = shift || time;
my $gm = timegm(localtime($t));
my $sign = qw( + + - )[ $gm <=> $t ];
return sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
}


=item prompt ( PROMPT , ISPASSWORD )
Query user C<PROMPT> and return answer from user.
Expand Down
12 changes: 2 additions & 10 deletions perl/Git/SVN.pm
Expand Up @@ -11,7 +11,6 @@ use Carp qw/croak/;
use File::Path qw/mkpath/;
use File::Copy qw/copy/;
use IPC::Open3;
use Time::Local;
use Memoize; # core since 5.8.0, Jul 2002
use Memoize::Storable;
use POSIX qw(:signal_h);
Expand All @@ -22,6 +21,7 @@ use Git qw(
command_noisy
command_output_pipe
command_close_pipe
get_tz_offset
);
use Git::SVN::Utils qw(
fatal
Expand Down Expand Up @@ -1311,14 +1311,6 @@ sub get_untracked {
\@out;
}

sub get_tz {
# some systmes don't handle or mishandle %z, so be creative.
my $t = shift || time;
my $gm = timelocal(gmtime($t));
my $sign = qw( + + - )[ $t <=> $gm ];
return sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
}

# parse_svn_date(DATE)
# --------------------
# Given a date (in UTC) from Subversion, return a string in the format
Expand Down Expand Up @@ -1351,7 +1343,7 @@ sub parse_svn_date {
delete $ENV{TZ};
}

my $our_TZ = get_tz();
my $our_TZ = get_tz_offset();

# This converts $epoch_in_UTC into our local timezone.
my ($sec, $min, $hour, $mday, $mon, $year,
Expand Down
8 changes: 6 additions & 2 deletions perl/Git/SVN/Log.pm
Expand Up @@ -2,7 +2,11 @@ package Git::SVN::Log;
use strict;
use warnings;
use Git::SVN::Utils qw(fatal);
use Git qw(command command_oneline command_output_pipe command_close_pipe);
use Git qw(command
command_oneline
command_output_pipe
command_close_pipe
get_tz_offset);
use POSIX qw/strftime/;
use constant commit_log_separator => ('-' x 72) . "\n";
use vars qw/$TZ $limit $color $pager $non_recursive $verbose $oneline
Expand Down Expand Up @@ -119,7 +123,7 @@ sub run_pager {
sub format_svn_date {
my $t = shift || time;
require Git::SVN;
my $gmoff = Git::SVN::get_tz($t);
my $gmoff = get_tz_offset($t);
return strftime("%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)", localtime($t));
}

Expand Down

0 comments on commit 8552e2e

Please sign in to comment.