# [PATCH] git-svn fix for systems without strftime %z

3 messages from 2009-02-23 to 2009-02-23. Participants: Ben Walton, Eric Wong.
Thread: https://gitlist.dev/t/17970

## Ben Walton, 2009-02-23 14:33

Subject: [PATCH] git-svn fix for systems without strftime %z
Message-ID: <1235399583-6043-1-git-send-email-bwalton@artsci.utoronto.ca>
URL: https://gitlist.dev/e/1235399583-6043-1-git-send-email-bwalton%40artsci.utoronto.ca

```

Hi All,

In packaging the latest stable release for the OpenCSW project, I
found that some of the git-svn tests were failing.  After looking into
it, I saw that strftime calls were passing %z.  While %z is available
on most modern systems, it's not universal.  The forthcoming patch
implements a workaround for this that detects when %z falls through
and will insert the proper value when required.

I've tested this on both Linux and Solaris and it seems to behave as
expected (the test suite is happy on both).

I hope you find this useful.

Thanks
-Ben

```

## Ben Walton, 2009-02-23 14:33

Subject: [PATCH] git-svn fix for systems without strftime %z
Message-ID: <1235399583-6043-2-git-send-email-bwalton@artsci.utoronto.ca>
URL: https://gitlist.dev/e/1235399583-6043-2-git-send-email-bwalton%40artsci.utoronto.ca
In-Reply-To: <1235399583-6043-1-git-send-email-bwalton@artsci.utoronto.ca>

```
%z isn't available on all platforms in the date formatting
routines.  Detect when %z is ignored and insert the
the proper value if necessary.

Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>
---
 git-svn.perl |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index cbc5211..66f49b4 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,18 @@ sub run_pager {
 }
 
 sub format_svn_date {
-	return strftime("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)", localtime(shift));
+	my $timestr = strftime("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)", localtime(shift));
+
+	# for systems without %z (solaris 8, 9, etc)
+	if ($timestr =~ /%z/) {
+		my $lt = time;
+		my $gm = timelocal(gmtime($lt));
+		my $sign = qw( + + - )[ $lt <=> $gm ];
+		my $gmoff = sprintf("%s%02d%02d", $sign, (gmtime(abs($lt - $gm)))[2,1]);
+		$timestr =~ s/%z/$gmoff/;
+	}
+
+	return $timestr;
 }
 
 sub parse_git_date {
-- 
1.6.0.4

```

## Eric Wong, 2009-02-23 22:44

Subject: Re: [PATCH] git-svn fix for systems without strftime %z
Message-ID: <20090223224400.GA32193@dcvr.yhbt.net>
URL: https://gitlist.dev/e/20090223224400.GA32193%40dcvr.yhbt.net
In-Reply-To: <1235399583-6043-2-git-send-email-bwalton@artsci.utoronto.ca>

```
Ben Walton <bwalton@artsci.utoronto.ca> wrote:
> %z isn't available on all platforms in the date formatting
> routines.  Detect when %z is ignored and insert the
> the proper value if necessary.
> 
> Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>

Hi Ben,

Thanks for the patch.  What about just removing strftime() entirely and
making the %z workaround the standard code path so it gets used/tested
more?  I don't think there'd be a discernable overhead on a modern
system and the ancient ones tend to stay around forever...  I'd like
to avoid rarely executed code paths if possible.

> ---
>  git-svn.perl |   14 +++++++++++++-
>  1 files changed, 13 insertions(+), 1 deletions(-)
> 
> diff --git a/git-svn.perl b/git-svn.perl
> index cbc5211..66f49b4 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,18 @@ sub run_pager {
>  }
>  
>  sub format_svn_date {
> -	return strftime("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)", localtime(shift));
> +	my $timestr = strftime("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)", localtime(shift));
> +
> +	# for systems without %z (solaris 8, 9, etc)
> +	if ($timestr =~ /%z/) {
> +		my $lt = time;
> +		my $gm = timelocal(gmtime($lt));
> +		my $sign = qw( + + - )[ $lt <=> $gm ];
> +		my $gmoff = sprintf("%s%02d%02d", $sign, (gmtime(abs($lt - $gm)))[2,1]);
> +		$timestr =~ s/%z/$gmoff/;
> +	}
> +
> +	return $timestr;
>  }

```
