git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
EWEric Wong <normalperson@yhbt.net>
Date
Feb 23, 2009, 22:44 UTC
Message-ID
<20090223224400.GA32193@dcvr.yhbt.net>
In-Reply-To
<1235399583-6043-2-git-send-email-bwalton@artsci.utoronto.ca>
Ben Walton <bwalton@artsci.utoronto.ca> wrote:
Show 5 quoted lines
> %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.

Show 34 quoted lines
> ---
>  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;
>  }
Previous: Ben Walton
Message 3 of 3 in “git-svn fix for systems without strftime %z”
  1. git-svn fix for systems without strftime %zBen Walton, Feb 23, 2009
  2. git-svn fix for systems without strftime %zBen Walton, Feb 23, 2009
  3. Eric WongFeb 23, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.