threads / patch / 17994

patchgit-svn fix to avoid using strftime %z

Subject: [PATCH] git-svn fix to avoid using strftime %z

## tl;dr

2 messages between Feb 24, 2009 and Feb 24, 2009. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Ben Walton· Feb 24, 2009, 19:44 UTC · lore

%z isn't available on all platforms in the date formatting routines. Provide a workalike capability that should be more portable.

Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>
---
This is the reworked version that was requested.  It drops %z completely
from the strftime call in favour of the hand rolled version.  All tests
still pass on Linux and Solaris.
 git-svn.perl |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
Show changes to git-svn.perl +7 −1
diff --git a/git-svn.perl b/git-svn.perl
index cbc5211..24180eb 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -4615,6 +4615,7 @@ package Git::SVN::Log;
 use strict;
 use warnings;
 use POSIX qw/strftime/;
+use Time::Local;
 use constant commit_log_separator => ('-' x 72) . "\n";
 use vars qw/$TZ $limit $color $pager $non_recursive $verbose $oneline
             %rusers $show_commit $incremental/;
@@ -4721,7 +4722,12 @@ sub run_pager {
 }
 
 sub format_svn_date {
-	return strftime("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)", localtime(shift));
+	# some systmes don't handle or mishandle %z, so be creative.
+	my $t = shift;
+	my $gm = timelocal(gmtime($t));
+	my $sign = qw( + + - )[ $t <=> $gm ];
+	my $gmoff = sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
+	return strftime("%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)", localtime($t));
 }
 
 sub parse_git_date {
-- 
1.6.0.4
Eric Wong· Feb 24, 2009, 21:46 UTC · re: Ben Walton · lore

Re: [PATCH] git-svn fix to avoid using strftime %z

Ben Walton <bwalton@artsci.utoronto.ca> wrote:
Show 5 quoted lines
> %z isn't available on all platforms in the date formatting
> routines.  Provide a workalike capability that should be
> more portable.
> 
> Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>
Thanks Ben, acked and pushed out to git://git.bogomips.org/git-svn
Show 34 quoted lines
> ---
> This is the reworked version that was requested.  It drops %z completely
> from the strftime call in favour of the hand rolled version.  All tests
> still pass on Linux and Solaris.
> 
>  git-svn.perl |    8 +++++++-
>  1 files changed, 7 insertions(+), 1 deletions(-)
> 
> diff --git a/git-svn.perl b/git-svn.perl
> index cbc5211..24180eb 100755
> --- a/git-svn.perl
> +++ b/git-svn.perl
> @@ -4615,6 +4615,7 @@ package Git::SVN::Log;
>  use strict;
>  use warnings;
>  use POSIX qw/strftime/;
> +use Time::Local;
>  use constant commit_log_separator => ('-' x 72) . "\n";
>  use vars qw/$TZ $limit $color $pager $non_recursive $verbose $oneline
>              %rusers $show_commit $incremental/;
> @@ -4721,7 +4722,12 @@ sub run_pager {
>  }
>  
>  sub format_svn_date {
> -	return strftime("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)", localtime(shift));
> +	# some systmes don't handle or mishandle %z, so be creative.
> +	my $t = shift;
> +	my $gm = timelocal(gmtime($t));
> +	my $sign = qw( + + - )[ $t <=> $gm ];
> +	my $gmoff = sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
> +	return strftime("%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)", localtime($t));
>  }
>  
>  sub parse_git_date {

← back to recent threads