Skip to content

Commit fb2c984

Browse files
crorvickgitster
authored andcommitted
git-cvsimport: allow author-specific timezones
CVS patchsets are imported with timestamps having an offset of +0000 (UTC). The cvs-authors file is already used to translate the CVS username to full name and email in the corresponding commit. Extend this file to support an optional timezone for calculating a user- specific timestamp offset. Signed-off-by: Chris Rorvick <chris@rorvick.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 42e55a5 commit fb2c984

File tree

6 files changed

+361
-7
lines changed

6 files changed

+361
-7
lines changed

Documentation/git-cvsimport.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,19 @@ This option can be used several times to provide several detection regexes.
137137
-A <author-conv-file>::
138138
CVS by default uses the Unix username when writing its
139139
commit logs. Using this option and an author-conv-file
140-
in this format
140+
maps the name recorded in CVS to author name, e-mail and
141+
optional timezone:
141142
+
142143
---------
143144
exon=Andreas Ericsson <ae@op5.se>
144-
spawn=Simon Pawn <spawn@frog-pond.org>
145+
spawn=Simon Pawn <spawn@frog-pond.org> America/Chicago
145146

146147
---------
147148
+
148149
'git cvsimport' will make it appear as those authors had
149150
their GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL set properly
150-
all along.
151+
all along. If a timezone is specified, GIT_AUTHOR_DATE will
152+
have the corresponding offset applied.
151153
+
152154
For convenience, this data is saved to `$GIT_DIR/cvs-authors`
153155
each time the '-A' option is provided and read from that same

git-cvsimport.perl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
$ENV{'TZ'}="UTC";
3232

3333
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);
34-
my (%conv_author_name, %conv_author_email);
34+
my (%conv_author_name, %conv_author_email, %conv_author_tz);
3535

3636
sub usage(;$) {
3737
my $msg = shift;
@@ -59,6 +59,14 @@ ($)
5959
$conv_author_name{$user} = $2;
6060
$conv_author_email{$user} = $3;
6161
}
62+
# or with an optional timezone:
63+
# spawn=Simon Pawn <spawn@frog-pond.org> America/Chicago
64+
elsif (m/^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*(\S+?)\s*$/) {
65+
$user = $1;
66+
$conv_author_name{$user} = $2;
67+
$conv_author_email{$user} = $3;
68+
$conv_author_tz{$user} = $4;
69+
}
6270
# However, we also read from CVSROOT/users format
6371
# to ease migration.
6472
elsif (/^(\w+):(['"]?)(.+?)\2\s*$/) {
@@ -84,7 +92,9 @@ ($)
8492
die("Failed to open $file for writing: $!");
8593

8694
foreach (keys %conv_author_name) {
87-
print $f "$_=$conv_author_name{$_} <$conv_author_email{$_}>\n";
95+
print $f "$_=$conv_author_name{$_} <$conv_author_email{$_}>";
96+
print $f " $conv_author_tz{$_}" if ($conv_author_tz{$_});
97+
print $f "\n";
8898
}
8999
close ($f);
90100
}
@@ -795,7 +805,7 @@ ()
795805
return $tree;
796806
}
797807

798-
my ($patchset,$date,$author_name,$author_email,$branch,$ancestor,$tag,$logmsg);
808+
my ($patchset,$date,$author_name,$author_email,$author_tz,$branch,$ancestor,$tag,$logmsg);
799809
my (@old,@new,@skipped,%ignorebranch,@commit_revisions);
800810

801811
# commits that cvsps cannot place anywhere...
@@ -844,7 +854,9 @@ sub commit {
844854
}
845855
}
846856

847-
my $commit_date = strftime("+0000 %Y-%m-%d %H:%M:%S",gmtime($date));
857+
$ENV{'TZ'}=$author_tz;
858+
my $commit_date = strftime("%s %z", localtime($date));
859+
$ENV{'TZ'}="UTC";
848860
$ENV{GIT_AUTHOR_NAME} = $author_name;
849861
$ENV{GIT_AUTHOR_EMAIL} = $author_email;
850862
$ENV{GIT_AUTHOR_DATE} = $commit_date;
@@ -945,12 +957,14 @@ sub commit {
945957
}
946958
$state=3;
947959
} elsif ($state == 3 and s/^Author:\s+//) {
960+
$author_tz = "UTC";
948961
s/\s+$//;
949962
if (/^(.*?)\s+<(.*)>/) {
950963
($author_name, $author_email) = ($1, $2);
951964
} elsif ($conv_author_name{$_}) {
952965
$author_name = $conv_author_name{$_};
953966
$author_email = $conv_author_email{$_};
967+
$author_tz = $conv_author_tz{$_} if ($conv_author_tz{$_});
954968
} else {
955969
$author_name = $author_email = $_;
956970
}

t/t9604-cvsimport-timestamps.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/sh
2+
3+
test_description='git cvsimport timestamps'
4+
. ./lib-cvs.sh
5+
6+
setup_cvs_test_repository t9604
7+
8+
test_expect_success 'check timestamps are UTC (TZ=CST6CDT)' '
9+
10+
TZ=CST6CDT git cvsimport -p"-x" -C module-1 module &&
11+
git cvsimport -p"-x" -C module-1 module &&
12+
(
13+
cd module-1 &&
14+
git log --format="%s %ai"
15+
) >actual-1 &&
16+
cat >expect-1 <<-EOF &&
17+
Rev 16 2006-10-29 07:00:01 +0000
18+
Rev 15 2006-10-29 06:59:59 +0000
19+
Rev 14 2006-04-02 08:00:01 +0000
20+
Rev 13 2006-04-02 07:59:59 +0000
21+
Rev 12 2005-12-01 00:00:00 +0000
22+
Rev 11 2005-11-01 00:00:00 +0000
23+
Rev 10 2005-10-01 00:00:00 +0000
24+
Rev 9 2005-09-01 00:00:00 +0000
25+
Rev 8 2005-08-01 00:00:00 +0000
26+
Rev 7 2005-07-01 00:00:00 +0000
27+
Rev 6 2005-06-01 00:00:00 +0000
28+
Rev 5 2005-05-01 00:00:00 +0000
29+
Rev 4 2005-04-01 00:00:00 +0000
30+
Rev 3 2005-03-01 00:00:00 +0000
31+
Rev 2 2005-02-01 00:00:00 +0000
32+
Rev 1 2005-01-01 00:00:00 +0000
33+
EOF
34+
test_cmp actual-1 expect-1
35+
'
36+
37+
test_expect_success 'check timestamps with author-specific timezones' '
38+
39+
cat >cvs-authors <<-EOF &&
40+
user1=User One <user1@domain.org>
41+
user2=User Two <user2@domain.org> CST6CDT
42+
user3=User Three <user3@domain.org> EST5EDT
43+
user4=User Four <user4@domain.org> MST7MDT
44+
EOF
45+
git cvsimport -p"-x" -A cvs-authors -C module-2 module &&
46+
(
47+
cd module-2 &&
48+
git log --format="%s %ai %an"
49+
) >actual-2 &&
50+
cat >expect-2 <<-EOF &&
51+
Rev 16 2006-10-29 01:00:01 -0600 User Two
52+
Rev 15 2006-10-29 01:59:59 -0500 User Two
53+
Rev 14 2006-04-02 03:00:01 -0500 User Two
54+
Rev 13 2006-04-02 01:59:59 -0600 User Two
55+
Rev 12 2005-11-30 17:00:00 -0700 User Four
56+
Rev 11 2005-10-31 19:00:00 -0500 User Three
57+
Rev 10 2005-09-30 19:00:00 -0500 User Two
58+
Rev 9 2005-09-01 00:00:00 +0000 User One
59+
Rev 8 2005-07-31 18:00:00 -0600 User Four
60+
Rev 7 2005-06-30 20:00:00 -0400 User Three
61+
Rev 6 2005-05-31 19:00:00 -0500 User Two
62+
Rev 5 2005-05-01 00:00:00 +0000 User One
63+
Rev 4 2005-03-31 17:00:00 -0700 User Four
64+
Rev 3 2005-02-28 19:00:00 -0500 User Three
65+
Rev 2 2005-01-31 18:00:00 -0600 User Two
66+
Rev 1 2005-01-01 00:00:00 +0000 User One
67+
EOF
68+
test_cmp actual-2 expect-2
69+
'
70+
71+
test_done

t/t9604/cvsroot/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* -whitespace

t/t9604/cvsroot/CVSROOT/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
history
2+
val-tags

0 commit comments

Comments
 (0)