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

[PATCH v2 1/2] git-cvsimport: use localtime for converting timestamps

From
Chris Rorvick <chris@rorvick.com>
Date
Oct 13, 2012, 04:11 UTC
Message-ID
<35710ee78133792f4c79b0afeb56804d745c1de5.1350100320.git.chris@rorvick.com>
In-Reply-To
<cover.1350100320.git.chris@rorvick.com>

cvsps formats timestamps for the local timezone in its output. Using timegm() to convert to epoch-relative only works because cvsimport overrides TZ to "UTC". Using timelocal() does not change the behavior of the script as is, but it does ensure cvsimport behaves sanely if run with another TZ value.

Also, use localtime() for generating the commit timestamp instead of gmtime(). Again, this has no affect on the script as is since TZ is hard-wired to "UTC". But using localtime() would allow someone to change the value of TZ with what is likely the desired effect (i.e., timestamps are written to the Git commit with local timezone offset.)

Signed-off-by: Chris Rorvick <chris@rorvick.com>
---
 git-cvsimport.perl |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 8032f23..2f5da9e 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -582,7 +582,7 @@ sub pdate($) {
 	m#(\d{2,4})/(\d\d)/(\d\d)\s(\d\d):(\d\d)(?::(\d\d))?#
 		or die "Unparseable date: $d\n";
 	my $y=$1; $y-=1900 if $y>1900;
-	return timegm($6||0,$5,$4,$3,$2-1,$y);
+	return timelocal($6||0,$5,$4,$3,$2-1,$y);
 }
 
 sub pmode($) {
@@ -844,7 +844,7 @@ sub commit {
 		}
 	}
 
-	my $commit_date = strftime("+0000 %Y-%m-%d %H:%M:%S",gmtime($date));
+	my $commit_date = strftime("%z %Y-%m-%d %H:%M:%S",localtime($date));
 	$ENV{GIT_AUTHOR_NAME} = $author_name;
 	$ENV{GIT_AUTHOR_EMAIL} = $author_email;
 	$ENV{GIT_AUTHOR_DATE} = $commit_date;
-- 
1.7.1
Previous: Chris RorvickNext: Chris Rorvick
Message 2 of 5 in “git-cvsimport: support local timezone”
  1. 0/2 git-cvsimport: support local timezoneChris Rorvick, Oct 13, 2012
  2. 1/2 git-cvsimport: use localtime for converting timestampsChris Rorvick, Oct 13, 2012
  3. 2/2 git-cvsimport: allow local timezone for commitsChris Rorvick, Oct 13, 2012
  4. Junio C HamanoOct 14, 2012
  5. Christopher RorvickOct 14, 2012

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.