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>

Chris Rorvick committed Oct 16, 2012 at 22:53 UTC fb2c984148a344781833b25361154619230d9dd4
6 files changed +361 -7
Documentation/git-cvsimport.txt
+5 -3
@@ -137,17 +137,19 @@ This option can be used several times to provide several detection regexes.
137 -A <author-conv-file>::
138 CVS by default uses the Unix username when writing its
139 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:
142 +
143 ---------
144 exon=Andreas Ericsson <ae@op5.se>
144 - spawn=Simon Pawn <spawn@frog-pond.org>
145 + spawn=Simon Pawn <spawn@frog-pond.org> America/Chicago
146
147 ---------
148 +
149 'git cvsimport' will make it appear as those authors had
150 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.
153 +
154 For convenience, this data is saved to `$GIT_DIR/cvs-authors`
155 each time the '-A' option is provided and read from that same
git-cvsimport.perl
+18 -4
@@ -31,7 +31,7 @@ $SIG{'PIPE'}="IGNORE";
31 $ENV{'TZ'}="UTC";
32
33 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);
35
36 sub usage(;$) {
37 my $msg = shift;
@@ -59,6 +59,14 @@ sub read_author_info($) {
59 $conv_author_name{$user} = $2;
60 $conv_author_email{$user} = $3;
61 }
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 + }
70 # However, we also read from CVSROOT/users format
71 # to ease migration.
72 elsif (/^(\w+):(['"]?)(.+?)\2\s*$/) {
@@ -84,7 +92,9 @@ sub write_author_info($) {
92 die("Failed to open $file for writing: $!");
93
94 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";
98 }
99 close ($f);
100 }
@@ -795,7 +805,7 @@ sub write_tree () {
805 return $tree;
806 }
807
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);
809 my (@old,@new,@skipped,%ignorebranch,@commit_revisions);
810
811 # commits that cvsps cannot place anywhere...
@@ -844,7 +854,9 @@ sub commit {
854 }
855 }
856
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";
860 $ENV{GIT_AUTHOR_NAME} = $author_name;
861 $ENV{GIT_AUTHOR_EMAIL} = $author_email;
862 $ENV{GIT_AUTHOR_DATE} = $commit_date;
@@ -945,12 +957,14 @@ while (<CVS>) {
957 }
958 $state=3;
959 } elsif ($state == 3 and s/^Author:\s+//) {
960 + $author_tz = "UTC";
961 s/\s+$//;
962 if (/^(.*?)\s+<(.*)>/) {
963 ($author_name, $author_email) = ($1, $2);
964 } elsif ($conv_author_name{$_}) {
965 $author_name = $conv_author_name{$_};
966 $author_email = $conv_author_email{$_};
967 + $author_tz = $conv_author_tz{$_} if ($conv_author_tz{$_});
968 } else {
969 $author_name = $author_email = $_;
970 }
t/t9604-cvsimport-timestamps.sh new
+71
@@ -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 new
+1
@@ -0,0 +1 @@
1 +* -whitespace
t/t9604/cvsroot/CVSROOT/.gitignore new
+2
@@ -0,0 +1,2 @@
1 +history
2 +val-tags
t/t9604/cvsroot/module/a,v new
+264
@@ -0,0 +1,264 @@
1 +head 1.16;
2 +access;
3 +symbols;
4 +locks; strict;
5 +comment @# @;
6 +
7 +
8 +1.16
9 +date 2006.10.29.07.00.01; author user2; state Exp;
10 +branches;
11 +next 1.15;
12 +
13 +1.15
14 +date 2006.10.29.06.59.59; author user2; state Exp;
15 +branches;
16 +next 1.14;
17 +
18 +1.14
19 +date 2006.04.02.08.00.01; author user2; state Exp;
20 +branches;
21 +next 1.13;
22 +
23 +1.13
24 +date 2006.04.02.07.59.59; author user2; state Exp;
25 +branches;
26 +next 1.12;
27 +
28 +1.12
29 +date 2005.12.01.00.00.00; author user4; state Exp;
30 +branches;
31 +next 1.11;
32 +
33 +1.11
34 +date 2005.11.01.00.00.00; author user3; state Exp;
35 +branches;
36 +next 1.10;
37 +
38 +1.10
39 +date 2005.10.01.00.00.00; author user2; state Exp;
40 +branches;
41 +next 1.9;
42 +
43 +1.9
44 +date 2005.09.01.00.00.00; author user1; state Exp;
45 +branches;
46 +next 1.8;
47 +
48 +1.8
49 +date 2005.08.01.00.00.00; author user4; state Exp;
50 +branches;
51 +next 1.7;
52 +
53 +1.7
54 +date 2005.07.01.00.00.00; author user3; state Exp;
55 +branches;
56 +next 1.6;
57 +
58 +1.6
59 +date 2005.06.01.00.00.00; author user2; state Exp;
60 +branches;
61 +next 1.5;
62 +
63 +1.5
64 +date 2005.05.01.00.00.00; author user1; state Exp;
65 +branches;
66 +next 1.4;
67 +
68 +1.4
69 +date 2005.04.01.00.00.00; author user4; state Exp;
70 +branches;
71 +next 1.3;
72 +
73 +1.3
74 +date 2005.03.01.00.00.00; author user3; state Exp;
75 +branches;
76 +next 1.2;
77 +
78 +1.2
79 +date 2005.02.01.00.00.00; author user2; state Exp;
80 +branches;
81 +next 1.1;
82 +
83 +1.1
84 +date 2005.01.01.00.00.00; author user1; state Exp;
85 +branches;
86 +next ;
87 +
88 +
89 +desc
90 +@@
91 +
92 +
93 +1.16
94 +log
95 +@Rev 16
96 +@
97 +text
98 +@Rev 16
99 +@
100 +
101 +
102 +1.15
103 +log
104 +@Rev 15
105 +@
106 +text
107 +@d1 1
108 +a1 1
109 +Rev 15
110 +@
111 +
112 +
113 +1.14
114 +log
115 +@Rev 14
116 +@
117 +text
118 +@d1 1
119 +a1 1
120 +Rev 14
121 +@
122 +
123 +
124 +1.13
125 +log
126 +@Rev 13
127 +@
128 +text
129 +@d1 1
130 +a1 1
131 +Rev 13
132 +@
133 +
134 +
135 +1.12
136 +log
137 +@Rev 12
138 +@
139 +text
140 +@d1 1
141 +a1 1
142 +Rev 12
143 +@
144 +
145 +
146 +1.11
147 +log
148 +@Rev 11
149 +@
150 +text
151 +@d1 1
152 +a1 1
153 +Rev 11
154 +@
155 +
156 +
157 +1.10
158 +log
159 +@Rev 10
160 +@
161 +text
162 +@d1 1
163 +a1 1
164 +Rev 10
165 +@
166 +
167 +
168 +1.9
169 +log
170 +@Rev 9
171 +@
172 +text
173 +@d1 1
174 +a1 1
175 +Rev 9
176 +@
177 +
178 +
179 +1.8
180 +log
181 +@Rev 8
182 +@
183 +text
184 +@d1 1
185 +a1 1
186 +Rev 8
187 +@
188 +
189 +
190 +1.7
191 +log
192 +@Rev 7
193 +@
194 +text
195 +@d1 1
196 +a1 1
197 +Rev 7
198 +@
199 +
200 +
201 +1.6
202 +log
203 +@Rev 6
204 +@
205 +text
206 +@d1 1
207 +a1 1
208 +Rev 6
209 +@
210 +
211 +
212 +1.5
213 +log
214 +@Rev 5
215 +@
216 +text
217 +@d1 1
218 +a1 1
219 +Rev 5
220 +@
221 +
222 +
223 +1.4
224 +log
225 +@Rev 4
226 +@
227 +text
228 +@d1 1
229 +a1 1
230 +Rev 4
231 +@
232 +
233 +
234 +1.3
235 +log
236 +@Rev 3
237 +@
238 +text
239 +@d1 1
240 +a1 1
241 +Rev 3
242 +@
243 +
244 +
245 +1.2
246 +log
247 +@Rev 2
248 +@
249 +text
250 +@d1 1
251 +a1 1
252 +Rev 2
253 +@
254 +
255 +
256 +1.1
257 +log
258 +@Rev 1
259 +@
260 +text
261 +@d1 1
262 +a1 1
263 +Rev 1
264 +@