{"thread":{"id":"22547","subject":"[PATCH v2] cvsimport: new -R option: generate .git/cvs-revisions mapping","startedAt":"2010-02-06T18:26:24Z","lastAt":"2010-02-07T05:10:53Z","messageCount":2,"participants":["Aaron Crane","Jeff King"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"133816","messageId":"bc341e101002061026t2e7fa4cfte9119bf7fc2d2ddc@mail.gmail.com","threadId":"22547","inReplyTo":null,"subject":"[PATCH v2] cvsimport: new -R option: generate .git/cvs-revisions mapping","fromName":"Aaron Crane","fromEmail":"git@aaroncrane.co.uk","sentAt":"2010-02-06T18:26:24Z","receivedAt":"2010-02-06T18:26:24Z","isPatch":true,"sender":{"key":"git@aaroncrane.co.uk","avatar":null},"body":"This option causes the creation or updating of a file mapping CVS\n(filename, revision number) pairs to Git commit IDs.  This is expected\nto be useful if you have CVS revision numbers stored in commit messages,\nbug-tracking systems, email archives, and the like.\n\nSigned-off-by: Aaron Crane <git@aaroncrane.co.uk>\n---\nSee also the thread beginning at\nhttp://thread.gmane.org/gmane.comp.version-control.git/138079\n\nThanks to Peff for his review at\nhttp://article.gmane.org/gmane.comp.version-control.git/138544\n\nI believe this revised patch takes account of all his comments.  In\nparticular, compared to the previous version:\n\n- Tests are included\n- Now works with incremental import\n- The file is always generated as .git/cvs-revisions, rather than\n  letting the user pick the name\n\n Documentation/git-cvsimport.txt |   18 +++++++++++++++++-\n git-cvsimport.perl              |   21 +++++++++++++++++----\n t/t9600-cvsimport.sh            |   36 +++++++++++++++++++++++++++++++++---\n 3 files changed, 67 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/git-cvsimport.txt b/Documentation/git-cvsimport.txt\nindex ddfcb3d..8bcd875 100644\n--- a/Documentation/git-cvsimport.txt\n+++ b/Documentation/git-cvsimport.txt\n@@ -13,7 +13,7 @@ SYNOPSIS\n \t      [-A <author-conv-file>] [-p <options-for-cvsps>] [-P <file>]\n \t      [-C <git_repository>] [-z <fuzz>] [-i] [-k] [-u] [-s <subst>]\n \t      [-a] [-m] [-M <regex>] [-S <regex>] [-L <commitlimit>]\n-\t      [-r <remote>] [<CVS_module>]\n+\t      [-r <remote>] [-R] [<CVS_module>]\n\n\n DESCRIPTION\n@@ -157,6 +157,22 @@ It is not recommended to use this feature if you intend to\n export changes back to CVS again later with\n 'git cvsexportcommit'.\n\n+-R::\n+\tGenerate a `$GIT_DIR/cvs-revisions` file containing a mapping from CVS\n+\trevision numbers to newly-created Git commit IDs.  The generated file\n+\twill contain one line for each (filename, revision) pair imported;\n+\teach line will look like\n++\n+---------\n+src/widget.c 1.1 1d862f173cdc7325b6fa6d2ae1cfd61fd1b512b7\n+---------\n++\n+The revision data is appended to the file if it already exists, for use when\n+doing incremental imports.\n++\n+This option may be useful if you have CVS revision numbers stored in commit\n+messages, bug-tracking systems, email archives, and the like.\n+\n -h::\n \tPrint a short usage message and exit.\n\ndiff --git a/git-cvsimport.perl b/git-cvsimport.perl\nindex 4853bf7..9e03eee 100755\n--- a/git-cvsimport.perl\n+++ b/git-cvsimport.perl\n@@ -29,7 +29,7 @@ use IPC::Open2;\n $SIG{'PIPE'}=\"IGNORE\";\n $ENV{'TZ'}=\"UTC\";\n\n-our ($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P,\n$opt_s,$opt_m,@opt_M,$opt_A,$opt_S,$opt_L, $opt_a, $opt_r);\n+our ($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P,\n$opt_s,$opt_m,@opt_M,$opt_A,$opt_S,$opt_L, $opt_a, $opt_r, $opt_R);\n my (%conv_author_name, %conv_author_email);\n\n sub usage(;$) {\n@@ -40,7 +40,7 @@ Usage: git cvsimport     # fetch/update GIT from CVS\n        [-o branch-for-HEAD] [-h] [-v] [-d CVSROOT] [-A author-conv-file]\n        [-p opts-for-cvsps] [-P file] [-C GIT_repository] [-z fuzz] [-i] [-k]\n        [-u] [-s subst] [-a] [-m] [-M regex] [-S regex] [-L commitlimit]\n-       [-r remote] [CVS_module]\n+       [-r remote] [-R] [CVS_module]\n END\n \texit(1);\n }\n@@ -110,7 +110,7 @@ sub read_repo_config {\n \t}\n }\n\n-my $opts = \"haivmkuo:d:p:r:C:z:s:M:P:A:S:L:\";\n+my $opts = \"haivmkuo:d:p:r:C:z:s:M:P:A:S:L:R\";\n read_repo_config($opts);\n Getopt::Long::Configure( 'no_ignore_case', 'bundling' );\n\n@@ -659,6 +659,11 @@ if ($opt_A) {\n \twrite_author_info(\"$git_dir/cvs-authors\");\n }\n\n+# open .git/cvs-revisions, if requested\n+open my $revision_map, '>>', \"$git_dir/cvs-revisions\"\n+    or die \"Can't open $git_dir/cvs-revisions for appending: $!\\n\"\n+\tif defined $opt_R;\n+\n\n #\n # run cvsps into a file unless we are getting\n@@ -742,7 +747,7 @@ sub write_tree () {\n }\n\n my ($patchset,$date,$author_name,$author_email,$branch,$ancestor,$tag,$logmsg);\n-my (@old,@new,@skipped,%ignorebranch);\n+my (@old,@new,@skipped,%ignorebranch,@commit_revisions);\n\n # commits that cvsps cannot place anywhere...\n $ignorebranch{'#CVSPS_NO_BRANCH'} = 1;\n@@ -825,6 +830,11 @@ sub commit {\n \tsystem('git' , 'update-ref', \"$remote/$branch\", $cid) == 0\n \t\tor die \"Cannot write branch $branch for update: $!\\n\";\n\n+\tif ($revision_map) {\n+\t\tprint $revision_map \"@$_ $cid\\n\" for @commit_revisions;\n+\t}\n+\t@commit_revisions = ();\n+\n \tif ($tag) {\n \t        my ($xtag) = $tag;\n \t\t$xtag =~ s/\\s+\\*\\*.*$//; # Remove stuff like ** INVALID ** and ** FUNKY **\n@@ -959,6 +969,7 @@ while (<CVS>) {\n \t\t    push(@skipped, $fn);\n \t\t    next;\n \t\t}\n+\t\tpush @commit_revisions, [$fn, $rev];\n \t\tprint \"Fetching $fn   v $rev\\n\" if $opt_v;\n \t\tmy ($tmpname, $size) = $cvs->file($fn,$rev);\n \t\tif ($size == -1) {\n@@ -981,7 +992,9 @@ while (<CVS>) {\n \t\tunlink($tmpname);\n \t} elsif ($state == 9 and\n/^\\s+(.+?):\\d+(?:\\.\\d+)+->(\\d+(?:\\.\\d+)+)\\(DEAD\\)\\s*$/) {\n \t\tmy $fn = $1;\n+\t\tmy $rev = $2;\n \t\t$fn =~ s#^/+##;\n+\t\tpush @commit_revisions, [$fn, $rev];\n \t\tpush(@old,$fn);\n \t\tprint \"Delete $fn\\n\" if $opt_v;\n \t} elsif ($state == 9 and /^\\s*$/) {\ndiff --git a/t/t9600-cvsimport.sh b/t/t9600-cvsimport.sh\nindex 363345f..b572ce3 100755\n--- a/t/t9600-cvsimport.sh\n+++ b/t/t9600-cvsimport.sh\n@@ -47,13 +47,20 @@ EOF\n\n test_expect_success 'import a trivial module' '\n\n-\tgit cvsimport -a -z 0 -C module-git module &&\n+\tgit cvsimport -a -R -z 0 -C module-git module &&\n \ttest_cmp module-cvs/o_fortuna module-git/o_fortuna\n\n '\n\n test_expect_success 'pack refs' 'cd module-git && git gc && cd ..'\n\n+test_expect_success 'initial import has correct .git/cvs-revisions' '\n+\n+\t(cd module-git &&\n+\t git log --format=\"o_fortuna 1.1 %H\" -1) > expected &&\n+\ttest_cmp expected module-git/.git/cvs-revisions\n+'\n+\n test_expect_success 'update cvs module' '\n\n \tcd module-cvs &&\n@@ -86,13 +93,21 @@ EOF\n test_expect_success 'update git module' '\n\n \tcd module-git &&\n-\tgit cvsimport -a -z 0 module &&\n+\tgit cvsimport -a -R -z 0 module &&\n \tgit merge origin &&\n \tcd .. &&\n \ttest_cmp module-cvs/o_fortuna module-git/o_fortuna\n\n '\n\n+test_expect_success 'update has correct .git/cvs-revisions' '\n+\n+\t(cd module-git &&\n+\t git log --format=\"o_fortuna 1.1 %H\" -1 HEAD^ &&\n+\t git log --format=\"o_fortuna 1.2 %H\" -1 HEAD) > expected &&\n+\ttest_cmp expected module-git/.git/cvs-revisions\n+'\n+\n test_expect_success 'update cvs module' '\n\n \tcd module-cvs &&\n@@ -107,13 +122,22 @@ test_expect_success 'cvsimport.module config works' '\n\n \tcd module-git &&\n \t\tgit config cvsimport.module module &&\n-\t\tgit cvsimport -a -z0 &&\n+\t\tgit cvsimport -a -R -z0 &&\n \t\tgit merge origin &&\n \tcd .. &&\n \ttest_cmp module-cvs/tick module-git/tick\n\n '\n\n+test_expect_success 'second update has correct .git/cvs-revisions' '\n+\n+\t(cd module-git &&\n+\t git log --format=\"o_fortuna 1.1 %H\" -1 HEAD^^ &&\n+\t git log --format=\"o_fortuna 1.2 %H\" -1 HEAD^\n+\t git log --format=\"tick 1.1 %H\" -1 HEAD) > expected &&\n+\ttest_cmp expected module-git/.git/cvs-revisions\n+'\n+\n test_expect_success 'import from a CVS working tree' '\n\n \t$CVS co -d import-from-wt module &&\n@@ -126,6 +150,12 @@ test_expect_success 'import from a CVS working tree' '\n\n '\n\n+test_expect_success 'no .git/cvs-revisions created by default' '\n+\n+\t! test -e import-from-wt/.git/cvs-revisions\n+\n+'\n+\n test_expect_success 'test entire HEAD' 'test_cmp_branch_tree master'\n\n test_done\n-- \n1.6.6.1\n"},{"id":"133853","messageId":"20100207051053.GA17118@coredump.intra.peff.net","threadId":"22547","inReplyTo":"bc341e101002061026t2e7fa4cfte9119bf7fc2d2ddc@mail.gmail.com","subject":"Re: [PATCH v2] cvsimport: new -R option: generate .git/cvs-revisions mapping","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-02-07T05:10:53Z","receivedAt":"2010-02-07T05:10:53Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Feb 06, 2010 at 06:26:24PM +0000, Aaron Crane wrote:\n\n> I believe this revised patch takes account of all his comments.  In\n> particular, compared to the previous version:\n> \n> - Tests are included\n> - Now works with incremental import\n> - The file is always generated as .git/cvs-revisions, rather than\n>   letting the user pick the name\n\nThanks, it looks much better.\n\nAcked-by: Jeff King <peff@peff.net>\n\n-Peff\n"}]}