{"thread":{"id":"22458","subject":"[PATCH] cvsimport: new -R option: generate revision-to-commit mapping","startedAt":"2010-01-31T12:43:44Z","lastAt":"2010-01-31T13:24:49Z","messageCount":2,"participants":["Aaron Crane","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"133181","messageId":"bc341e101001310443x18e02281i2e4d18334ead700b@mail.gmail.com","threadId":"22458","inReplyTo":null,"subject":"[PATCH] cvsimport: new -R option: generate revision-to-commit mapping","fromName":"Aaron Crane","fromEmail":"git@aaroncrane.co.uk","sentAt":"2010-01-31T12:43:44Z","receivedAt":"2010-01-31T12:43:44Z","isPatch":true,"sender":{"key":"git@aaroncrane.co.uk","avatar":null},"body":"Signed-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\nThis is my first Git submission, so I'd welcome any comments, especially\nif there's something wrong with the way I'm sending this.\n\n Documentation/git-cvsimport.txt |   15 ++++++++++++++-\n git-cvsimport.perl              |   20 ++++++++++++++++----\n 2 files changed, 30 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-cvsimport.txt b/Documentation/git-cvsimport.txt\nindex ddfcb3d..19e8c9f 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 <revision-to-commit-file>] [<CVS_module>]\n\n\n DESCRIPTION\n@@ -157,6 +157,19 @@ 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 <revision-to-commit-file>::\n+\tGenerate a file containing a mapping from CVS revision numbers to\n+\tnewly-created Git commit IDs.  The generated file will contain one\n+\tline for each (filename, revision) pair found by 'cvsps'; each line\n+\twill look like\n++\n+---------\n+src/widget.c 1.1 1d862f173cdc7325b6fa6d2ae1cfd61fd1b512b7\n+---------\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..8ef89c6 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 revision-to-commit-file] [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@@ -175,6 +175,10 @@ if (@opt_M) {\n \tpush (@mergerx, map { qr/$_/ } @opt_M);\n }\n\n+open my $revision_map, '>', $opt_R\n+    or die \"Can't open -R file $opt_R: $!\\n\"\n+\tif defined $opt_R;\n+\n # Remember UTC of our starting time\n # we'll want to avoid importing commits\n # that are too recent\n@@ -742,7 +746,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 +829,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 +968,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 +991,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*$/) {\n-- \n1.6.6.1\n"},{"id":"133183","messageId":"20100131132449.GA29470@coredump.intra.peff.net","threadId":"22458","inReplyTo":"bc341e101001310443x18e02281i2e4d18334ead700b@mail.gmail.com","subject":"Re: [PATCH] cvsimport: new -R option: generate revision-to-commit mapping","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-01-31T13:24:49Z","receivedAt":"2010-01-31T13:24:49Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Jan 31, 2010 at 12:43:44PM +0000, Aaron Crane wrote:\n\n> Signed-off-by: Aaron Crane <git@aaroncrane.co.uk>\n> ---\n\nPlease put a bit of the rationale into the commit message. Even a\nsentence or two can help later on when somebody is reading the output of\n\"git log\".\n\n>  Documentation/git-cvsimport.txt |   15 ++++++++++++++-\n>  git-cvsimport.perl              |   20 ++++++++++++++++----\n>  2 files changed, 30 insertions(+), 5 deletions(-)\n\nA basic test would be nice. You should be able to just use your new \"-R\"\nduring the import in t9600, and then check that it generated the correct\nmapping.\n\n> +-R <revision-to-commit-file>::\n> +\tGenerate a file containing a mapping from CVS revision numbers to\n> +\tnewly-created Git commit IDs.  The generated file will contain one\n> +\tline for each (filename, revision) pair found by 'cvsps'; each line\n> +\twill look like\n\nIs mentioning 'cvsps' right here?  cvsps doesn't know about git commit\nid's.\n\n> +open my $revision_map, '>', $opt_R\n> +    or die \"Can't open -R file $opt_R: $!\\n\"\n> +\tif defined $opt_R;\n\nYou need to use munge_user_filename here to handle relative paths. See\ncommit f6fdbb6.\n\nAlso, should you perhaps be appending to the file instead of truncating\nit? Remember that cvsimport can be used incrementally. I wonder if it\nwould be better to simply have \"-R\" without an argument to append the\nrevision map to a file .git/cvs-revisions or something. And then the\nuser can easily pull it from there after the import.\n\n-Peff\n"}]}