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

[PATCH] Fix "cvs log" to use UTC timezone instead of local

From
JBJonas Berlin <xkr47@outerspace.dyndns.org>
Date
Sep 4, 2007, 12:31 UTC
Message-ID
<11889090932256-git-send-email-xkr47@outerspace.dyndns.org>

The timestamp format used in "cvs log" output does not include a timezone, and must thus be in UTC timezone. The timestamps from git on the other hand contain timezone information for each commit timestamp, but git-cvsserver discarded this information and used the timestamps without adjusting the time accordingly. The patch adds code to apply the timezone offset to produce a UTC timestamp.

Signed-off-by: Jonas Berlin <xkr47@outerspace.dyndns.org>
---
    Could it perhaps be that git previously reported timestamps in UTC
    instead of including a timezone?
 git-cvsserver.perl              |   11 ++++++++++-
 t/t9400-git-cvsserver-server.sh |   24 ++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletions(-)
diff --git a/git-cvsserver.perl b/git-cvsserver.perl
index 13dbd27..5ae9933 100755
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
@@ -23,6 +23,7 @@ use Fcntl;
 use File::Temp qw/tempdir tempfile/;
 use File::Basename;
 use Getopt::Long qw(:config require_order no_ignore_case);
+use Time::Local;
 
 my $VERSION = '@@GIT_VERSION@@';
 
@@ -1686,7 +1687,15 @@ sub req_log
             print "M ----------------------------\n";
             print "M revision 1.$revision->{revision}\n";
             # reformat the date for log output
-            $revision->{modified} = sprintf('%04d/%02d/%02d %s', $3, $DATE_LIST->{$2}, $1, $4 ) if ( $revision->{modified} =~ /(\d+)\s+(\w+)\s+(\d+)\s+(\S+)/ and defined($DATE_LIST->{$2}) );
+            if ( $revision->{modified} =~ /(\d+)\s+(\w+)\s+(\d+)\s+(\d\d):(\d\d):(\d\d) ([-+])(\d\d)(\d\d)/ and defined($DATE_LIST->{$2}) )
+            {
+                my $off = $8 * 3600 + $9 * 60;
+                my $time = timegm($6, $5, $4, $1, $DATE_LIST->{$2}-1, $3 - 1900);
+                $off = -$off if ( $7 eq "-" );
+                $time -= $off;
+                my ( $sec, $min, $hour, $mday, $mon, $year ) = gmtime($time);
+                $revision->{modified} = sprintf('%04d/%02d/%02d %02d:%02d:%02d', $year + 1900, $mon + 1, $mday, $hour, $min, $sec);
+            }
             $revision->{author} =~ s/\s+.*//;
             $revision->{author} =~ s/^(.{8}).*/$1/;
             print "M date: $revision->{modified};  author: $revision->{author};  state: " . ( $revision->{filehash} eq "deleted" ? "dead" : "Exp" ) . ";  lines: +2 -3\n";
diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh
index 641303e..254eab7 100755
--- a/t/t9400-git-cvsserver-server.sh
+++ b/t/t9400-git-cvsserver-server.sh
@@ -405,4 +405,28 @@ test_expect_success 'cvs update (merge no-op)' \
     GIT_CONFIG="$git_config" cvs -Q update &&
     diff -q merge ../merge'
 
+#------------
+# CVS LOG
+#------------
+
+cd "$WORKDIR"
+test_expect_success 'cvs log (check that timestamps are in UTC)' \
+  'echo stamp > stamp &&
+   git add stamp &&
+   TZ=GMT-01 git commit -q -m "Add stamp" &&
+   git push gitcvs.git >/dev/null &&
+   GIT_STAMP=$(git-show --pretty=format:%ct --name-only stamp | grep -v stamp) &&
+   [ "$GIT_STAMP" ] &&
+   cd cvswork &&
+   GIT_CONFIG="$git_config" cvs -Q update &&
+   CVS_STAMP=$(GIT_CONFIG="$git_config" cvs log stamp | perl -e '\''
+      use Time::Local;
+      while(<>) {
+        last if(/^date:/);
+      }
+      my ($dummy,$y,$m,$d,$H,$M,$S) = split(m!\D+!);
+      print timegm($S,$M,$H,$d,$m-1,$y-1900);
+   '\'') &&
+   test "$CVS_STAMP" = "$GIT_STAMP"'
+
 test_done
-- 
1.5.1.6
Next: Linus Torvalds
Message 1 of 4 in “Fix "cvs log" to use UTC timezone instead of local”
  1. Fix "cvs log" to use UTC timezone instead of localJonas Berlin, Sep 4, 2007
  2. Linus TorvaldsSep 4, 2007
  3. Jonas BerlinSep 5, 2007
  4. Jonas BerlinSep 5, 2007

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.