@matheusbsbs / matheus-bagliano / commits / ffd97f3a35
Fork 0

git-cvsimport: Add -A <author-conv-file> option

This patch adds the option to specify an author name/email conversion file in the format exon=Andreas Ericsson <ae@op5.se> spawn=Simon Pawn <spawn@frog-pond.org> which will translate the ugly cvs authornames to the more informative git style. The info is saved in $GIT_DIR/cvs-authors, so that subsequent incremental imports will use the same author-info even if no -A option is specified. If an -A option *is* specified, the info in $GIT_DIR/cvs-authors is appended/updated appropriately. Docs updated accordingly. Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Junio C Hamano <junkio@cox.net>

Andreas Ericsson committed Jan 13, 2006 at 00:38 UTC ffd97f3a35d8394773409f17d58156b32ca911cf
2 files changed +70 -6
Documentation/git-cvsimport.txt
+20
@@ -89,6 +89,26 @@ If you need to pass multiple options, separate them with a comma.
89 -s <subst>::
90 Substitute the character "/" in branch names with <subst>
91
92 +-A <author-conv-file>::
93 + CVS by default uses the unix username when writing its
94 + commit logs. Using this option and an author-conv-file
95 + in this format
96 +
97 + exon=Andreas Ericsson <ae@op5.se>
98 + spawn=Simon Pawn <spawn@frog-pond.org>
99 +
100 + git-cvsimport will make it appear as those authors had
101 + their GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL set properly
102 + all along.
103 +
104 + For convenience, this data is saved to $GIT_DIR/cvs-authors
105 + each time the -A option is provided and read from that same
106 + file each time git-cvsimport is run.
107 +
108 + It is not recommended to use this feature if you intend to
109 + export changes back to CVS again later with
110 + git-link[1]::git-cvsexportcommit.
111 +
112 OUTPUT
113 ------
114 If '-v' is specified, the script reports what it is doing.
git-cvsimport.perl
+50 -6
@@ -29,19 +29,52 @@ use IPC::Open2;
29 $SIG{'PIPE'}="IGNORE";
30 $ENV{'TZ'}="UTC";
31
32 -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);
32 +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);
33 +my (%conv_author_name, %conv_author_email);
34
35 sub usage() {
36 print STDERR <<END;
37 Usage: ${\basename $0} # fetch/update GIT from CVS
37 - [-o branch-for-HEAD] [-h] [-v] [-d CVSROOT]
38 - [-p opts-for-cvsps] [-C GIT_repository] [-z fuzz]
39 - [-i] [-k] [-u] [-s subst] [-m] [-M regex] [CVS_module]
38 + [-o branch-for-HEAD] [-h] [-v] [-d CVSROOT] [-A author-conv-file]
39 + [-p opts-for-cvsps] [-C GIT_repository] [-z fuzz] [-i] [-k] [-u]
40 + [-s subst] [-m] [-M regex] [CVS_module]
41 END
42 exit(1);
43 }
44
44 -getopts("hivmkuo:d:p:C:z:s:M:P:") or usage();
45 +sub read_author_info($) {
46 + my ($file) = @_;
47 + my $user;
48 + open my $f, '<', "$file" or die("Failed to open $file: $!\n");
49 +
50 + while (<$f>) {
51 + chomp;
52 + # Expected format is this;
53 + # exon=Andreas Ericsson <ae@op5.se>
54 + if (m/^([^ \t=]*)[ \t=]*([^<]*)(<.*$)\s*/) {
55 + $user = $1;
56 + $conv_author_name{$1} = $2;
57 + $conv_author_email{$1} = $3;
58 + # strip trailing whitespace from author name
59 + $conv_author_name{$1} =~ s/\s*$//;
60 + }
61 + }
62 + close ($f);
63 +}
64 +
65 +sub write_author_info($) {
66 + my ($file) = @_;
67 + open my $f, '>', $file or
68 + die("Failed to open $file for writing: $!");
69 +
70 + foreach (keys %conv_author_name) {
71 + print $f "$_=" . $conv_author_name{$_} .
72 + " " . $conv_author_email{$_} . "\n";
73 + }
74 + close ($f);
75 +}
76 +
77 +getopts("hivmkuo:d:p:C:z:s:M:P:A:") or usage();
78 usage if $opt_h;
79
80 @ARGV <= 1 or usage();
@@ -453,7 +486,7 @@ CVS2GIT_HEAD exists.
486 Make sure your working directory corresponds to HEAD and remove CVS2GIT_HEAD.
487 You may need to run
488
456 - git-read-tree -m -u CVS2GIT_HEAD HEAD
489 + git read-tree -m -u CVS2GIT_HEAD HEAD
490 EOM
491 }
492 system('cp', "$git_dir/HEAD", "$git_dir/CVS2GIT_HEAD");
@@ -489,6 +522,14 @@ EOM
522 -d $git_dir
523 or die "Could not create git subdir ($git_dir).\n";
524
525 +# now we read (and possibly save) author-info as well
526 +-f "$git_dir/cvs-authors" and
527 + read_author_info("$git_dir/cvs-authors");
528 +if ($opt_A) {
529 + read_author_info($opt_A);
530 + write_author_info("$git_dir/cvs-authors");
531 +}
532 +
533 my $pid = open(CVS,"-|");
534 die "Cannot fork: $!\n" unless defined $pid;
535 unless($pid) {
@@ -702,6 +743,9 @@ while(<CVS>) {
743 s/\s+$//;
744 if (/^(.*?)\s+<(.*)>/) {
745 ($author_name, $author_email) = ($1, $2);
746 + } elsif ($conv_author_name{$_}) {
747 + $author_name = $conv_author_name{$_};
748 + $author_email = $conv_author_email{$_};
749 } else {
750 $author_name = $author_email = $_;
751 }