Skip to content

Commit 0455ec0

Browse files
Aaron Cranegitster
authored andcommitted
cvsimport: new -R option: generate .git/cvs-revisions mapping
This option causes the creation or updating of a file mapping CVS (filename, revision number) pairs to Git commit IDs. This is expected to be useful if you have CVS revision numbers stored in commit messages, bug-tracking systems, email archives, and the like. Signed-off-by: Aaron Crane <git@aaroncrane.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b0883aa commit 0455ec0

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

Documentation/git-cvsimport.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SYNOPSIS
1313
[-A <author-conv-file>] [-p <options-for-cvsps>] [-P <file>]
1414
[-C <git_repository>] [-z <fuzz>] [-i] [-k] [-u] [-s <subst>]
1515
[-a] [-m] [-M <regex>] [-S <regex>] [-L <commitlimit>]
16-
[-r <remote>] [<CVS_module>]
16+
[-r <remote>] [-R] [<CVS_module>]
1717

1818

1919
DESCRIPTION
@@ -157,6 +157,22 @@ It is not recommended to use this feature if you intend to
157157
export changes back to CVS again later with
158158
'git cvsexportcommit'.
159159

160+
-R::
161+
Generate a `$GIT_DIR/cvs-revisions` file containing a mapping from CVS
162+
revision numbers to newly-created Git commit IDs. The generated file
163+
will contain one line for each (filename, revision) pair imported;
164+
each line will look like
165+
+
166+
---------
167+
src/widget.c 1.1 1d862f173cdc7325b6fa6d2ae1cfd61fd1b512b7
168+
---------
169+
+
170+
The revision data is appended to the file if it already exists, for use when
171+
doing incremental imports.
172+
+
173+
This option may be useful if you have CVS revision numbers stored in commit
174+
messages, bug-tracking systems, email archives, and the like.
175+
160176
-h::
161177
Print a short usage message and exit.
162178

git-cvsimport.perl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
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,$opt_A,$opt_S,$opt_L, $opt_a, $opt_r);
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,$opt_S,$opt_L, $opt_a, $opt_r, $opt_R);
3333
my (%conv_author_name, %conv_author_email);
3434

3535
sub usage(;$) {
@@ -40,7 +40,7 @@ (;$)
4040
[-o branch-for-HEAD] [-h] [-v] [-d CVSROOT] [-A author-conv-file]
4141
[-p opts-for-cvsps] [-P file] [-C GIT_repository] [-z fuzz] [-i] [-k]
4242
[-u] [-s subst] [-a] [-m] [-M regex] [-S regex] [-L commitlimit]
43-
[-r remote] [CVS_module]
43+
[-r remote] [-R] [CVS_module]
4444
END
4545
exit(1);
4646
}
@@ -110,7 +110,7 @@ sub read_repo_config {
110110
}
111111
}
112112

113-
my $opts = "haivmkuo:d:p:r:C:z:s:M:P:A:S:L:";
113+
my $opts = "haivmkuo:d:p:r:C:z:s:M:P:A:S:L:R";
114114
read_repo_config($opts);
115115
Getopt::Long::Configure( 'no_ignore_case', 'bundling' );
116116

@@ -659,6 +659,11 @@ sub munge_user_filename {
659659
write_author_info("$git_dir/cvs-authors");
660660
}
661661

662+
# open .git/cvs-revisions, if requested
663+
open my $revision_map, '>>', "$git_dir/cvs-revisions"
664+
or die "Can't open $git_dir/cvs-revisions for appending: $!\n"
665+
if defined $opt_R;
666+
662667

663668
#
664669
# run cvsps into a file unless we are getting
@@ -742,7 +747,7 @@ ()
742747
}
743748

744749
my ($patchset,$date,$author_name,$author_email,$branch,$ancestor,$tag,$logmsg);
745-
my (@old,@new,@skipped,%ignorebranch);
750+
my (@old,@new,@skipped,%ignorebranch,@commit_revisions);
746751

747752
# commits that cvsps cannot place anywhere...
748753
$ignorebranch{'#CVSPS_NO_BRANCH'} = 1;
@@ -825,6 +830,11 @@ sub commit {
825830
system('git' , 'update-ref', "$remote/$branch", $cid) == 0
826831
or die "Cannot write branch $branch for update: $!\n";
827832

833+
if ($revision_map) {
834+
print $revision_map "@$_ $cid\n" for @commit_revisions;
835+
}
836+
@commit_revisions = ();
837+
828838
if ($tag) {
829839
my ($xtag) = $tag;
830840
$xtag =~ s/\s+\*\*.*$//; # Remove stuff like ** INVALID ** and ** FUNKY **
@@ -959,6 +969,7 @@ sub commit {
959969
push(@skipped, $fn);
960970
next;
961971
}
972+
push @commit_revisions, [$fn, $rev];
962973
print "Fetching $fn v $rev\n" if $opt_v;
963974
my ($tmpname, $size) = $cvs->file($fn,$rev);
964975
if ($size == -1) {
@@ -981,7 +992,9 @@ sub commit {
981992
unlink($tmpname);
982993
} elsif ($state == 9 and /^\s+(.+?):\d+(?:\.\d+)+->(\d+(?:\.\d+)+)\(DEAD\)\s*$/) {
983994
my $fn = $1;
995+
my $rev = $2;
984996
$fn =~ s#^/+##;
997+
push @commit_revisions, [$fn, $rev];
985998
push(@old,$fn);
986999
print "Delete $fn\n" if $opt_v;
9871000
} elsif ($state == 9 and /^\s*$/) {

t/t9600-cvsimport.sh

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,20 @@ EOF
4747

4848
test_expect_success 'import a trivial module' '
4949
50-
git cvsimport -a -z 0 -C module-git module &&
50+
git cvsimport -a -R -z 0 -C module-git module &&
5151
test_cmp module-cvs/o_fortuna module-git/o_fortuna
5252
5353
'
5454

5555
test_expect_success 'pack refs' 'cd module-git && git gc && cd ..'
5656

57+
test_expect_success 'initial import has correct .git/cvs-revisions' '
58+
59+
(cd module-git &&
60+
git log --format="o_fortuna 1.1 %H" -1) > expected &&
61+
test_cmp expected module-git/.git/cvs-revisions
62+
'
63+
5764
test_expect_success 'update cvs module' '
5865
5966
cd module-cvs &&
@@ -86,13 +93,21 @@ EOF
8693
test_expect_success 'update git module' '
8794
8895
cd module-git &&
89-
git cvsimport -a -z 0 module &&
96+
git cvsimport -a -R -z 0 module &&
9097
git merge origin &&
9198
cd .. &&
9299
test_cmp module-cvs/o_fortuna module-git/o_fortuna
93100
94101
'
95102

103+
test_expect_success 'update has correct .git/cvs-revisions' '
104+
105+
(cd module-git &&
106+
git log --format="o_fortuna 1.1 %H" -1 HEAD^ &&
107+
git log --format="o_fortuna 1.2 %H" -1 HEAD) > expected &&
108+
test_cmp expected module-git/.git/cvs-revisions
109+
'
110+
96111
test_expect_success 'update cvs module' '
97112
98113
cd module-cvs &&
@@ -107,13 +122,22 @@ test_expect_success 'cvsimport.module config works' '
107122
108123
cd module-git &&
109124
git config cvsimport.module module &&
110-
git cvsimport -a -z0 &&
125+
git cvsimport -a -R -z0 &&
111126
git merge origin &&
112127
cd .. &&
113128
test_cmp module-cvs/tick module-git/tick
114129
115130
'
116131

132+
test_expect_success 'second update has correct .git/cvs-revisions' '
133+
134+
(cd module-git &&
135+
git log --format="o_fortuna 1.1 %H" -1 HEAD^^ &&
136+
git log --format="o_fortuna 1.2 %H" -1 HEAD^
137+
git log --format="tick 1.1 %H" -1 HEAD) > expected &&
138+
test_cmp expected module-git/.git/cvs-revisions
139+
'
140+
117141
test_expect_success 'import from a CVS working tree' '
118142
119143
$CVS co -d import-from-wt module &&
@@ -126,6 +150,12 @@ test_expect_success 'import from a CVS working tree' '
126150
127151
'
128152

153+
test_expect_success 'no .git/cvs-revisions created by default' '
154+
155+
! test -e import-from-wt/.git/cvs-revisions
156+
157+
'
158+
129159
test_expect_success 'test entire HEAD' 'test_cmp_branch_tree master'
130160

131161
test_done

0 commit comments

Comments
 (0)