Skip to contentSkip to conversation

git-cvsimport: allow author-specific timezones

PATCH Superseded Chris Rorvick 1 participant 1 message Jun 15, 2016 Documentation

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 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.

---

Cleaned up unit tests and added more detail to documentation.

Unit test is inherently platform dependent due to dependency on zoneinfo database. Is there a way to improve this situation?

 Documentation/git-cvsimport.txt    |   8 +-
 git-cvsimport.perl                 |  22 ++-
 t/t9604-cvsimport-timestamps.sh    |  71 ++++++++++
 t/t9604/cvsroot/.gitattributes     |   1 +
 t/t9604/cvsroot/CVSROOT/.gitignore |   2 +
 t/t9604/cvsroot/module/a,v         | 265 +++++++++++++++++++++++++++++++++++++
 6 files changed, 362 insertions(+), 7 deletions(-)
 create mode 100755 t/t9604-cvsimport-timestamps.sh
 create mode 100644 t/t9604/cvsroot/.gitattributes
 create mode 100644 t/t9604/cvsroot/CVSROOT/.gitignore
 create mode 100644 t/t9604/cvsroot/module/a,v
Documentation/git-cvsimport.txt +5 -3
index 6695ab3..9ea8bb5 100644
@@ -137,17 +137,19 @@ This option can be used several times to provide several detection regexes.
 -A <author-conv-file>::
 	CVS by default uses the Unix username when writing its
 	commit logs. Using this option and an author-conv-file
-	in this format
+	maps the name recorded in CVS to author name, e-mail and
+	and optional timezone:
 +
 ---------
 	exon=Andreas Ericsson <[email protected]>
-	spawn=Simon Pawn <[email protected]>
+	spawn=Simon Pawn <[email protected]> America/Chicago
 
 ---------
 +
 'git cvsimport' will make it appear as those authors had
 their GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL set properly
-all along.
+all along.  If a timezone is specified, GIT_AUTHOR_DATE will
+have the corresponding offset applied.
 +
 For convenience, this data is saved to `$GIT_DIR/cvs-authors`
 each time the '-A' option is provided and read from that same
git-cvsimport.perl +18 -4
index 8032f23..ceb119d 100755
@@ -31,7 +31,7 @@ $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);
-my (%conv_author_name, %conv_author_email);
+my (%conv_author_name, %conv_author_email, %conv_author_tz);
 
 sub usage(;$) {
 	my $msg = shift;
@@ -59,6 +59,14 @@ sub read_author_info($) {
 			$conv_author_name{$user} = $2;
 			$conv_author_email{$user} = $3;
 		}
+		# or with an optional timezone:
+		#   spawn=Simon Pawn <[email protected]> America/Chicago
+		elsif (m/^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*(\S+?)\s*$/) {
+			$user = $1;
+			$conv_author_name{$user} = $2;
+			$conv_author_email{$user} = $3;
+			$conv_author_tz{$user} = $4;
+		}
 		# However, we also read from CVSROOT/users format
 		# to ease migration.
 		elsif (/^(\w+):(['"]?)(.+?)\2\s*$/) {
@@ -84,7 +92,9 @@ sub write_author_info($) {
 	  die("Failed to open $file for writing: $!");
 
 	foreach (keys %conv_author_name) {
-		print $f "$_=$conv_author_name{$_} <$conv_author_email{$_}>\n";
+		print $f "$_=$conv_author_name{$_} <$conv_author_email{$_}>";
+		print $f " $conv_author_tz{$_}" if ($conv_author_tz{$_});
+		print $f "\n";
 	}
 	close ($f);
 }
@@ -795,7 +805,7 @@ sub write_tree () {
 	return $tree;
 }
 
-my ($patchset,$date,$author_name,$author_email,$branch,$ancestor,$tag,$logmsg);
+my ($patchset,$date,$author_name,$author_email,$author_tz,$branch,$ancestor,$tag,$logmsg);
 my (@old,@new,@skipped,%ignorebranch,@commit_revisions);
 
 # commits that cvsps cannot place anywhere...
@@ -844,7 +854,9 @@ sub commit {
 		}
 	}
 
-	my $commit_date = strftime("+0000 %Y-%m-%d %H:%M:%S",gmtime($date));
+	$ENV{'TZ'}=$author_tz;
+	my $commit_date = strftime("%s %z", localtime($date));
+	$ENV{'TZ'}="UTC";
 	$ENV{GIT_AUTHOR_NAME} = $author_name;
 	$ENV{GIT_AUTHOR_EMAIL} = $author_email;
 	$ENV{GIT_AUTHOR_DATE} = $commit_date;
@@ -945,12 +957,14 @@ while (<CVS>) {
 		}
 		$state=3;
 	} elsif ($state == 3 and s/^Author:\s+//) {
+		$author_tz = "UTC";
 		s/\s+$//;
 		if (/^(.*?)\s+<(.*)>/) {
 		    ($author_name, $author_email) = ($1, $2);
 		} elsif ($conv_author_name{$_}) {
 			$author_name = $conv_author_name{$_};
 			$author_email = $conv_author_email{$_};
+			$author_tz = $conv_author_tz{$_} if ($conv_author_tz{$_});
 		} else {
 		    $author_name = $author_email = $_;
 		}
t/t9604-cvsimport-timestamps.sh new file +71 -0

71 lines not on this page · raw message

t/t9604/cvsroot/.gitattributes new file +1 -0
new file mode 100644
index 0000000..562b12e
@@ -0,0 +1 @@
+* -whitespace
t/t9604/cvsroot/CVSROOT/.gitignore new file +2 -0
new file mode 100644
index 0000000..3bb9b34
@@ -0,0 +1,2 @@
+history
+val-tags
t/t9604/cvsroot/module/a,v new file +265 -0

265 lines not on this page · raw message

Signature · 1 line
1.8.0.rc1.19.gbecacc0