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>
Aaron Crane committed
Feb 6, 2010 at 18:26 UTC
0455ec0330fd29146d6e16189cc9262566cc566d
3 files changed
+67
-8
Documentation/git-cvsimport.txt
+17
-1
@@ -13,7 +13,7 @@ SYNOPSIS
13
[-A <author-conv-file>] [-p <options-for-cvsps>] [-P <file>]
14
[-C <git_repository>] [-z <fuzz>] [-i] [-k] [-u] [-s <subst>]
15
[-a] [-m] [-M <regex>] [-S <regex>] [-L <commitlimit>]
16
- [-r <remote>] [<CVS_module>]
16
+ [-r <remote>] [-R] [<CVS_module>]
17
18
19
DESCRIPTION
@@ -157,6 +157,22 @@ It is not recommended to use this feature if you intend to
157
export changes back to CVS again later with
158
'git cvsexportcommit'.
159
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
+
176
-h::
177
Print a short usage message and exit.
178
git-cvsimport.perl
+17
-4
@@ -29,7 +29,7 @@ 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,$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);
33
my (%conv_author_name, %conv_author_email);
34
35
sub usage(;$) {
@@ -40,7 +40,7 @@ Usage: git cvsimport # fetch/update GIT from CVS
40
[-o branch-for-HEAD] [-h] [-v] [-d CVSROOT] [-A author-conv-file]
41
[-p opts-for-cvsps] [-P file] [-C GIT_repository] [-z fuzz] [-i] [-k]
42
[-u] [-s subst] [-a] [-m] [-M regex] [-S regex] [-L commitlimit]
43
- [-r remote] [CVS_module]
43
+ [-r remote] [-R] [CVS_module]
44
END
45
exit(1);
46
}
@@ -110,7 +110,7 @@ sub read_repo_config {
110
}
111
}
112
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";
114
read_repo_config($opts);
115
Getopt::Long::Configure( 'no_ignore_case', 'bundling' );
116
@@ -659,6 +659,11 @@ if ($opt_A) {
659
write_author_info("$git_dir/cvs-authors");
660
}
661
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
+
667
668
#
669
# run cvsps into a file unless we are getting
@@ -742,7 +747,7 @@ sub write_tree () {
747
}
748
749
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);
751
752
# commits that cvsps cannot place anywhere...
753
$ignorebranch{'#CVSPS_NO_BRANCH'} = 1;
@@ -825,6 +830,11 @@ sub commit {
830
system('git' , 'update-ref', "$remote/$branch", $cid) == 0
831
or die "Cannot write branch $branch for update: $!\n";
832
833
+ if ($revision_map) {
834
+ print $revision_map "@$_ $cid\n" for @commit_revisions;
835
+ }
836
+ @commit_revisions = ();
837
+
838
if ($tag) {
839
my ($xtag) = $tag;
840
$xtag =~ s/\s+\*\*.*$//; # Remove stuff like ** INVALID ** and ** FUNKY **
@@ -959,6 +969,7 @@ while (<CVS>) {
969
push(@skipped, $fn);
970
next;
971
}
972
+ push @commit_revisions, [$fn, $rev];
973
print "Fetching $fn v $rev\n" if $opt_v;
974
my ($tmpname, $size) = $cvs->file($fn,$rev);
975
if ($size == -1) {
@@ -981,7 +992,9 @@ while (<CVS>) {
992
unlink($tmpname);
993
} elsif ($state == 9 and /^\s+(.+?):\d+(?:\.\d+)+->(\d+(?:\.\d+)+)\(DEAD\)\s*$/) {
994
my $fn = $1;
995
+ my $rev = $2;
996
$fn =~ s#^/+##;
997
+ push @commit_revisions, [$fn, $rev];
998
push(@old,$fn);
999
print "Delete $fn\n" if $opt_v;
1000
} elsif ($state == 9 and /^\s*$/) {
t/t9600-cvsimport.sh
+33
-3
@@ -47,13 +47,20 @@ EOF
47
48
test_expect_success 'import a trivial module' '
49
50
- git cvsimport -a -z 0 -C module-git module &&
50
+ git cvsimport -a -R -z 0 -C module-git module &&
51
test_cmp module-cvs/o_fortuna module-git/o_fortuna
52
53
'
54
55
test_expect_success 'pack refs' 'cd module-git && git gc && cd ..'
56
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
+
64
test_expect_success 'update cvs module' '
65
66
cd module-cvs &&
@@ -86,13 +93,21 @@ EOF
93
test_expect_success 'update git module' '
94
95
cd module-git &&
89
- git cvsimport -a -z 0 module &&
96
+ git cvsimport -a -R -z 0 module &&
97
git merge origin &&
98
cd .. &&
99
test_cmp module-cvs/o_fortuna module-git/o_fortuna
100
101
'
102
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
+
111
test_expect_success 'update cvs module' '
112
113
cd module-cvs &&
@@ -107,13 +122,22 @@ test_expect_success 'cvsimport.module config works' '
122
123
cd module-git &&
124
git config cvsimport.module module &&
110
- git cvsimport -a -z0 &&
125
+ git cvsimport -a -R -z0 &&
126
git merge origin &&
127
cd .. &&
128
test_cmp module-cvs/tick module-git/tick
129
130
'
131
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
+
141
test_expect_success 'import from a CVS working tree' '
142
143
$CVS co -d import-from-wt module &&
@@ -126,6 +150,12 @@ test_expect_success 'import from a CVS working tree' '
150
151
'
152
153
+test_expect_success 'no .git/cvs-revisions created by default' '
154
+
155
+ ! test -e import-from-wt/.git/cvs-revisions
156
+
157
+'
158
+
159
test_expect_success 'test entire HEAD' 'test_cmp_branch_tree master'
160
161
test_done