Skip to content

Commit ffd97f3

Browse files
Andreas EricssonJunio C Hamano
authored andcommitted
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>
1 parent d425142 commit ffd97f3

File tree

2 files changed

+70
-6
lines changed

2 files changed

+70
-6
lines changed

Documentation/git-cvsimport.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,26 @@ If you need to pass multiple options, separate them with a comma.
8989
-s <subst>::
9090
Substitute the character "/" in branch names with <subst>
9191

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+
92112
OUTPUT
93113
------
94114
If '-v' is specified, the script reports what it is doing.

git-cvsimport.perl

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,52 @@
2929
$SIG{'PIPE'}="IGNORE";
3030
$ENV{'TZ'}="UTC";
3131

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);
3334

3435
sub usage() {
3536
print STDERR <<END;
3637
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]
4041
END
4142
exit(1);
4243
}
4344

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();
4578
usage if $opt_h;
4679

4780
@ARGV <= 1 or usage();
@@ -453,7 +486,7 @@ ($$)
453486
Make sure your working directory corresponds to HEAD and remove CVS2GIT_HEAD.
454487
You may need to run
455488
456-
git-read-tree -m -u CVS2GIT_HEAD HEAD
489+
git read-tree -m -u CVS2GIT_HEAD HEAD
457490
EOM
458491
}
459492
system('cp', "$git_dir/HEAD", "$git_dir/CVS2GIT_HEAD");
@@ -489,6 +522,14 @@ ($$)
489522
-d $git_dir
490523
or die "Could not create git subdir ($git_dir).\n";
491524

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+
492533
my $pid = open(CVS,"-|");
493534
die "Cannot fork: $!\n" unless defined $pid;
494535
unless($pid) {
@@ -702,6 +743,9 @@ ($$)
702743
s/\s+$//;
703744
if (/^(.*?)\s+<(.*)>/) {
704745
($author_name, $author_email) = ($1, $2);
746+
} elsif ($conv_author_name{$_}) {
747+
$author_name = $conv_author_name{$_};
748+
$author_email = $conv_author_email{$_};
705749
} else {
706750
$author_name = $author_email = $_;
707751
}

0 commit comments

Comments
 (0)