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

[PATCH 3/3] Avoid non-portable strftime format specifiers in git-cvsimport

From
Ben Walton <bdwalton@gmail.com>
Date
Feb 9, 2013, 21:46 UTC
Message-ID
<1360446418-12280-4-git-send-email-bdwalton@gmail.com>
In-Reply-To
<1360446418-12280-1-git-send-email-bdwalton@gmail.com>

Neither %s or %z are portable strftime format specifiers. There is no need for %s in git-cvsimport as the supplied time is already in seconds since the epoch. For %z, use the function get_tz_offset provided by Git.pm instead.

Signed-off-by: Ben Walton <bdwalton@gmail.com>
---
 git-cvsimport.perl |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 0a31ebd..344f120 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -26,6 +26,7 @@ use IO::Socket;
 use IO::Pipe;
 use POSIX qw(strftime tzset dup2 ENOENT);
 use IPC::Open2;
+use Git qw(get_tz_offset);
 
 $SIG{'PIPE'}="IGNORE";
 set_timezone('UTC');
@@ -864,7 +865,9 @@ sub commit {
 	}
 
 	set_timezone($author_tz);
-	my $commit_date = strftime("%s %z", localtime($date));
+	# $date is in the seconds since epoch format
+	my $tz_offset = get_tz_offset($date);
+	my $commit_date = "$date $tz_offset";
 	set_timezone('UTC');
 	$ENV{GIT_AUTHOR_NAME} = $author_name;
 	$ENV{GIT_AUTHOR_EMAIL} = $author_email;
-- 
1.7.10.4
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 6 in “Fix a portability issue with git-cvsimport”
  1. 0/3 Fix a portability issue with git-cvsimportBen Walton, Feb 9, 2013
  2. 1/3 Move Git::SVN::get_tz to Git::get_tz_offsetBen Walton, Feb 9, 2013
  3. 2/3 Fix get_tz_offset to properly handle DST boundary casesBen Walton, Feb 9, 2013
  4. Junio C HamanoFeb 9, 2013
  5. 3/3 Avoid non-portable strftime format specifiers in git-cvsimportBen Walton, Feb 9, 2013
  6. Junio C HamanoFeb 9, 2013

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.