threads / patch / 31792

patchgit-cvsimport: support local timezone

Subject: [PATCH] git-cvsimport: support local timezone

## tl;dr

4 messages between Oct 11, 2012 and Oct 12, 2012. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Chris Rorvick· Oct 11, 2012, 20:48 UTC · lore

CVS patches are unconditionally imported with a UTC timezone. Allow the local timezone by adding -l to the command line or specifying cvsimport.l in the config.

This could be made the default behavior, as setting TZ=UTC in the environment before doing the import is equivalent to the current behavior. But since a new default may be an unwelcome surprise to some, make this new behavior available os an option.

Signed-off-by: Chris Rorvick <chris@rorvick.com>
---

I have tested this with various TZ values (including "UTC") and confirmed that the <fuzz> + 5min timeout is observed correctly in each case.

Chris Rorvick
 Documentation/git-cvsimport.txt |   11 ++++++++---
 git-cvsimport.perl              |   13 +++++++------
 2 files changed, 15 insertions(+), 9 deletions(-)
Show changes to 2 files +15 −9

Documentation/git-cvsimport.txt, git-cvsimport.perl

diff --git a/Documentation/git-cvsimport.txt b/Documentation/git-cvsimport.txt
index 6695ab3..41cd289 100644
--- a/Documentation/git-cvsimport.txt
+++ b/Documentation/git-cvsimport.txt
@@ -11,9 +11,9 @@ SYNOPSIS
 [verse]
 'git cvsimport' [-o <branch-for-HEAD>] [-h] [-v] [-d <CVSROOT>]
 	      [-A <author-conv-file>] [-p <options-for-cvsps>] [-P <file>]
-	      [-C <git_repository>] [-z <fuzz>] [-i] [-k] [-u] [-s <subst>]
-	      [-a] [-m] [-M <regex>] [-S <regex>] [-L <commitlimit>]
-	      [-r <remote>] [-R] [<CVS_module>]
+	      [-C <git_repository>] [-z <fuzz>] [-i] [-k] [-l] [-u]
+	      [-s <subst>] [-a] [-m] [-M <regex>] [-S <regex>]
+	      [-L <commitlimit>] [-r <remote>] [-R] [<CVS_module>]
 
 
 DESCRIPTION
@@ -89,6 +89,11 @@ the old cvs2git tool.
 	to avoid noisy changesets. Highly recommended, but off by default
 	to preserve compatibility with early imported trees.
 
+-l::
+	Apply the local timezone to timestamps.  The `TZ` environment
+	variable can be used to override the default, possibly useful
+	if you are importing a non-local repository.
+
 -u::
 	Convert underscores in tag and branch names to dots.
 
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 8032f23..927d75c 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -28,9 +28,8 @@ use POSIX qw(strftime dup2 ENOENT);
 use IPC::Open2;
 
 $SIG{'PIPE'}="IGNORE";
-$ENV{'TZ'}="UTC";
 
-our ($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P, $opt_s,$opt_m,@opt_M,$opt_A,$opt_S,$opt_L, $opt_a, $opt_r, $opt_R);
+our ($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_l,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P, $opt_s,$opt_m,@opt_M,$opt_A,$opt_S,$opt_L, $opt_a, $opt_r, $opt_R);
 my (%conv_author_name, %conv_author_email);
 
 sub usage(;$) {
@@ -40,7 +39,7 @@ sub usage(;$) {
 Usage: git cvsimport     # fetch/update GIT from CVS
        [-o branch-for-HEAD] [-h] [-v] [-d CVSROOT] [-A author-conv-file]
        [-p opts-for-cvsps] [-P file] [-C GIT_repository] [-z fuzz] [-i] [-k]
-       [-u] [-s subst] [-a] [-m] [-M regex] [-S regex] [-L commitlimit]
+       [-l] [-u] [-s subst] [-a] [-m] [-M regex] [-S regex] [-L commitlimit]
        [-r remote] [-R] [CVS_module]
 END
 	exit(1);
@@ -128,7 +127,7 @@ sub read_repo_config {
 	}
 }
 
-my $opts = "haivmkuo:d:p:r:C:z:s:M:P:A:S:L:R";
+my $opts = "haivmkulo:d:p:r:C:z:s:M:P:A:S:L:R";
 read_repo_config($opts);
 Getopt::Long::Configure( 'no_ignore_case', 'bundling' );
 
@@ -138,6 +137,8 @@ GetOptions( map { s/:/=s/; /M/ ? "$_\@" : $_ } split( /(?!:)/, $opts ) )
     or usage();
 usage if $opt_h;
 
+$ENV{'TZ'}="UTC" unless $opt_l;
+
 if (@ARGV == 0) {
 		chomp(my $module = `git config --get cvsimport.module`);
 		push(@ARGV, $module) if $? == 0;
@@ -582,7 +583,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 +845,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
Michael Haggerty· Oct 11, 2012, 22:43 UTC · re: Chris Rorvick · lore

Re: [PATCH] git-cvsimport: support local timezone

On 10/11/2012 10:48 PM, Chris Rorvick wrote:
Show 8 quoted lines
> CVS patches are unconditionally imported with a UTC timezone.  Allow
> the local timezone by adding -l to the command line or specifying
> cvsimport.l in the config.
> 
> This could be made the default behavior, as setting TZ=UTC in the
> environment before doing the import is equivalent to the current
> behavior.  But since a new default may be an unwelcome surprise to
> some, make this new behavior available os an option.
According to rcsfile(7), all times in RCS/CVS files are recorded in UTC.
 So why do you need this feature?
Michael
-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
Christopher Rorvick· Oct 12, 2012, 00:14 UTC · re: Michael Haggerty · lore

Re: [PATCH] git-cvsimport: support local timezone

On Thu, Oct 11, 2012 at 5:43 PM, Michael Haggerty <mhagger@alum.mit.edu> wrote:
Show 14 quoted lines
> On 10/11/2012 10:48 PM, Chris Rorvick wrote:
>> CVS patches are unconditionally imported with a UTC timezone.  Allow
>> the local timezone by adding -l to the command line or specifying
>> cvsimport.l in the config.
>>
>> This could be made the default behavior, as setting TZ=UTC in the
>> environment before doing the import is equivalent to the current
>> behavior.  But since a new default may be an unwelcome surprise to
>> some, make this new behavior available os an option.
>
> According to rcsfile(7), all times in RCS/CVS files are recorded in UTC.
>  So why do you need this feature?
>
> Michael
Hi Michael,

Precisely because of this limitation. RCS files are not as expressive as a Git commit so I need a way to fill in the blanks.

This is analogous to the cvs-authors file. The RCS files in a CVS repository say the author of my commits is "crorvick" but that is neither my name nor email. cvsimport allows me to overcome this limitation by specifying a mapping from author username to full name and email.

Likewise, just because the RCS file has a UTC timestamp does not mean the commit originated in Greenwich, UK. Git includes the timezone offset in its timestamps, so it is reasonable to allow me to specify what is appropriate.

This is not a big deal for a one-time import as a simple filter-branch run can fix this pretty quickly. But this feature would be nice when running cvsimport incrementally.

Thanks!
Chris Rorvick
Michael Haggerty· Oct 12, 2012, 07:57 UTC · re: Christopher Rorvick · lore

Re: [PATCH] git-cvsimport: support local timezone

On 10/12/2012 02:14 AM, Christopher Rorvick wrote:
Show 19 quoted lines
> On Thu, Oct 11, 2012 at 5:43 PM, Michael Haggerty <mhagger@alum.mit.edu> wrote:
>> On 10/11/2012 10:48 PM, Chris Rorvick wrote:
>>> CVS patches are unconditionally imported with a UTC timezone.  Allow
>>> the local timezone by adding -l to the command line or specifying
>>> cvsimport.l in the config.
>>>
>>> This could be made the default behavior, as setting TZ=UTC in the
>>> environment before doing the import is equivalent to the current
>>> behavior.  But since a new default may be an unwelcome surprise to
>>> some, make this new behavior available os an option.
>>
>> According to rcsfile(7), all times in RCS/CVS files are recorded in UTC.
>>  So why do you need this feature?
> 
> [...]
> Likewise, just because the RCS file has a UTC timestamp does not mean
> the commit originated in Greenwich, UK.  Git includes the timezone
> offset in its timestamps, so it is reasonable to allow me to specify
> what is appropriate.

Ahh, OK, I hadn't realized that git stores (UTC time + time zone). I mistakenly thought you wanted to use a time zone to transform CVS-time to git-time, i.e., as if the CVS time were recorded in local time. Your actual goal makes sense.

[And it is something I should consider building into cvs2git.]
Michael
-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/

← back to recent threads