Move Git::SVN::get_tz to Git::get_tz_offset

This function has utility outside of the SVN module for any routine that needs the equivalent of GNU strftime's %z formatting option. Move it to the top-level Git.pm so that non-SVN modules don't need to import the SVN module to use it. The rename makes the purpose of the function clearer. Signed-off-by: Ben Walton <bdwalton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ben Walton committed Feb 9, 2013 at 21:46 UTC 68868ff57348b7ae351890b3599949422d2e6001
3 files changed +31 -12
perl/Git.pm
+23
@@ -59,6 +59,7 @@ require Exporter;
59 command_bidi_pipe command_close_bidi_pipe
60 version exec_path html_path hash_object git_cmd_try
61 remote_refs prompt
62 + get_tz_offset
63 temp_acquire temp_release temp_reset temp_path);
64
65
@@ -102,6 +103,7 @@ use Error qw(:try);
103 use Cwd qw(abs_path cwd);
104 use IPC::Open2 qw(open2);
105 use Fcntl qw(SEEK_SET SEEK_CUR);
106 +use Time::Local qw(timelocal);
107 }
108
109
@@ -511,6 +513,27 @@ C<git --html-path>). Useful mostly only internally.
513
514 sub html_path { command_oneline('--html-path') }
515
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 = timelocal(gmtime($t));
532 + my $sign = qw( + + - )[ $t <=> $gm ];
533 + return sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
534 +}
535 +
536 +
537 =item prompt ( PROMPT , ISPASSWORD )
538
539 Query user C<PROMPT> and return answer from user.
perl/Git/SVN.pm
+2 -10
@@ -11,7 +11,6 @@ use Carp qw/croak/;
11 use File::Path qw/mkpath/;
12 use File::Copy qw/copy/;
13 use IPC::Open3;
14 -use Time::Local;
14 use Memoize; # core since 5.8.0, Jul 2002
15 use Memoize::Storable;
16 use POSIX qw(:signal_h);
@@ -22,6 +21,7 @@ use Git qw(
21 command_noisy
22 command_output_pipe
23 command_close_pipe
24 + get_tz_offset
25 );
26 use Git::SVN::Utils qw(
27 fatal
@@ -1311,14 +1311,6 @@ sub get_untracked {
1311 \@out;
1312 }
1313
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 -
1314 # parse_svn_date(DATE)
1315 # --------------------
1316 # Given a date (in UTC) from Subversion, return a string in the format
@@ -1351,7 +1343,7 @@ sub parse_svn_date {
1343 delete $ENV{TZ};
1344 }
1345
1354 - my $our_TZ = get_tz();
1346 + my $our_TZ = get_tz_offset();
1347
1348 # This converts $epoch_in_UTC into our local timezone.
1349 my ($sec, $min, $hour, $mday, $mon, $year,
perl/Git/SVN/Log.pm
+6 -2
@@ -2,7 +2,11 @@ package Git::SVN::Log;
2 use strict;
3 use warnings;
4 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);
10 use POSIX qw/strftime/;
11 use constant commit_log_separator => ('-' x 72) . "\n";
12 use vars qw/$TZ $limit $color $pager $non_recursive $verbose $oneline
@@ -119,7 +123,7 @@ sub run_pager {
123 sub format_svn_date {
124 my $t = shift || time;
125 require Git::SVN;
122 - my $gmoff = Git::SVN::get_tz($t);
126 + my $gmoff = get_tz_offset($t);
127 return strftime("%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)", localtime($t));
128 }
129