{"thread":{"id":"17970","subject":"[PATCH] git-svn fix for systems without strftime %z","startedAt":"2009-02-23T14:33:02Z","lastAt":"2009-02-23T22:44:00Z","messageCount":3,"participants":["Ben Walton","Eric Wong"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"105906","messageId":"1235399583-6043-1-git-send-email-bwalton@artsci.utoronto.ca","threadId":"17970","inReplyTo":null,"subject":"[PATCH] git-svn fix for systems without strftime %z","fromName":"Ben Walton","fromEmail":"bwalton@artsci.utoronto.ca","sentAt":"2009-02-23T14:33:02Z","receivedAt":"2009-02-23T14:33:02Z","isPatch":true,"sender":{"key":"bdwalton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/396061?v=4"},"body":"\nHi All,\n\nIn packaging the latest stable release for the OpenCSW project, I\nfound that some of the git-svn tests were failing.  After looking into\nit, I saw that strftime calls were passing %z.  While %z is available\non most modern systems, it's not universal.  The forthcoming patch\nimplements a workaround for this that detects when %z falls through\nand will insert the proper value when required.\n\nI've tested this on both Linux and Solaris and it seems to behave as\nexpected (the test suite is happy on both).\n\nI hope you find this useful.\n\nThanks\n-Ben\n"},{"id":"105905","messageId":"1235399583-6043-2-git-send-email-bwalton@artsci.utoronto.ca","threadId":"17970","inReplyTo":"1235399583-6043-1-git-send-email-bwalton@artsci.utoronto.ca","subject":"[PATCH] git-svn fix for systems without strftime %z","fromName":"Ben Walton","fromEmail":"bwalton@artsci.utoronto.ca","sentAt":"2009-02-23T14:33:03Z","receivedAt":"2009-02-23T14:33:03Z","isPatch":true,"sender":{"key":"bdwalton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/396061?v=4"},"body":"%z isn't available on all platforms in the date formatting\nroutines.  Detect when %z is ignored and insert the\nthe proper value if necessary.\n\nSigned-off-by: Ben Walton <bwalton@artsci.utoronto.ca>\n---\n git-svn.perl |   14 +++++++++++++-\n 1 files changed, 13 insertions(+), 1 deletions(-)\n\ndiff --git a/git-svn.perl b/git-svn.perl\nindex cbc5211..66f49b4 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -4615,6 +4615,7 @@ package Git::SVN::Log;\n use strict;\n use warnings;\n use POSIX qw/strftime/;\n+use Time::Local;\n use constant commit_log_separator => ('-' x 72) . \"\\n\";\n use vars qw/$TZ $limit $color $pager $non_recursive $verbose $oneline\n             %rusers $show_commit $incremental/;\n@@ -4721,7 +4722,18 @@ sub run_pager {\n }\n \n sub format_svn_date {\n-\treturn strftime(\"%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)\", localtime(shift));\n+\tmy $timestr = strftime(\"%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)\", localtime(shift));\n+\n+\t# for systems without %z (solaris 8, 9, etc)\n+\tif ($timestr =~ /%z/) {\n+\t\tmy $lt = time;\n+\t\tmy $gm = timelocal(gmtime($lt));\n+\t\tmy $sign = qw( + + - )[ $lt <=> $gm ];\n+\t\tmy $gmoff = sprintf(\"%s%02d%02d\", $sign, (gmtime(abs($lt - $gm)))[2,1]);\n+\t\t$timestr =~ s/%z/$gmoff/;\n+\t}\n+\n+\treturn $timestr;\n }\n \n sub parse_git_date {\n-- \n1.6.0.4\n"},{"id":"105939","messageId":"20090223224400.GA32193@dcvr.yhbt.net","threadId":"17970","inReplyTo":"1235399583-6043-2-git-send-email-bwalton@artsci.utoronto.ca","subject":"Re: [PATCH] git-svn fix for systems without strftime %z","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2009-02-23T22:44:00Z","receivedAt":"2009-02-23T22:44:00Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Ben Walton <bwalton@artsci.utoronto.ca> wrote:\n> %z isn't available on all platforms in the date formatting\n> routines.  Detect when %z is ignored and insert the\n> the proper value if necessary.\n> \n> Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>\n\nHi Ben,\n\nThanks for the patch.  What about just removing strftime() entirely and\nmaking the %z workaround the standard code path so it gets used/tested\nmore?  I don't think there'd be a discernable overhead on a modern\nsystem and the ancient ones tend to stay around forever...  I'd like\nto avoid rarely executed code paths if possible.\n\n> ---\n>  git-svn.perl |   14 +++++++++++++-\n>  1 files changed, 13 insertions(+), 1 deletions(-)\n> \n> diff --git a/git-svn.perl b/git-svn.perl\n> index cbc5211..66f49b4 100755\n> --- a/git-svn.perl\n> +++ b/git-svn.perl\n> @@ -4615,6 +4615,7 @@ package Git::SVN::Log;\n>  use strict;\n>  use warnings;\n>  use POSIX qw/strftime/;\n> +use Time::Local;\n>  use constant commit_log_separator => ('-' x 72) . \"\\n\";\n>  use vars qw/$TZ $limit $color $pager $non_recursive $verbose $oneline\n>              %rusers $show_commit $incremental/;\n> @@ -4721,7 +4722,18 @@ sub run_pager {\n>  }\n>  \n>  sub format_svn_date {\n> -\treturn strftime(\"%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)\", localtime(shift));\n> +\tmy $timestr = strftime(\"%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)\", localtime(shift));\n> +\n> +\t# for systems without %z (solaris 8, 9, etc)\n> +\tif ($timestr =~ /%z/) {\n> +\t\tmy $lt = time;\n> +\t\tmy $gm = timelocal(gmtime($lt));\n> +\t\tmy $sign = qw( + + - )[ $lt <=> $gm ];\n> +\t\tmy $gmoff = sprintf(\"%s%02d%02d\", $sign, (gmtime(abs($lt - $gm)))[2,1]);\n> +\t\t$timestr =~ s/%z/$gmoff/;\n> +\t}\n> +\n> +\treturn $timestr;\n>  }\n"}]}