{"thread":{"id":"47117","subject":"[PATCH] Git-cvsimport Improvement","startedAt":"2017-11-04T18:30:08Z","lastAt":"2017-11-04T18:30:08Z","messageCount":1,"participants":["patrick keshishian"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"331828","messageId":"CAN0yQBo+yHfNAudYCSG1Xbfn1Kf4wWP9MGXxApatSaxZB898sA@mail.gmail.com","threadId":"47117","inReplyTo":null,"subject":"[PATCH] Git-cvsimport Improvement","fromName":"patrick keshishian","fromEmail":"pkeshish@gmail.com","sentAt":"2017-11-04T18:30:01Z","receivedAt":"2017-11-04T18:30:08Z","isPatch":true,"sender":{"key":"pkeshish@gmail.com","avatar":null},"body":"Greetings,\n\nI am attempting to improve CVS -> CVSps -> Git-cvsimport process.\n\nThe part involving Git-cvsimport has to do with parsing of CVSps\nPatchSet file. Consider what happens if a CVS log/commit message\nincludes lines which start with \"Members:\", say from copy-and-paste\n[2].\n\nTo avoid this issue, I have proposed that CVSps append the \"Log:\" tag\nwith line count of original CVS log/commit message [1].\n\n\nThe idea is if line-count is found after \"Log:\", that many (CVS log\nmessage) lines get consumed before advancing $state to look for\n\"^Members:\"\n\nCurrent Git-cvsimport isn't strict in matching the \"Log:\" tag\n(fortunately) and my proposed change to Git-cvsimport should be fully\nbackward compatible.\n\nSee attached patch.\n\nCheers,\n--patrick\n\np.s., For reference: Why I'm doing this and RFC sent to CVS list:\n\thttp://lists.nongnu.org/archive/html/info-cvs/2017-11/msg00000.html\n\n[1] https://github.com/andreyvit/cvsps/pull/4\n\n[2]  Example PatchSet with \"Members:\" line in original CVS commit message:\n---------------------\nPatchSet 3\nDate: 2017/10/30 23:25:20\nAuthor: catbert\nBranch: HEAD\nTag: (none)\nLog:\nThis will confuse git-cvsimport's parser\n\nMembers:\n\tsomefile.c:1.1->1.2\n\tanother.h:1.7->1.8\n\tfoo.mk:1.22->1.23\n\nImagine these were lines pasted to note something\n\nMembers:\n\tABC:1.1->1.2\n\n\ncommit c3e406c54b8cd3a2bbf0aa729fef201e20fa6df5\nAuthor: patrick keshishian <pkeshish@gmail.com>\nDate:   Sat Nov 4 08:42:12 2017 -0700\n\n    Optionally parse line count out of PatchSets with \"Log: count\"\n    \n    This is a change being suggested to CVSps where the line count of the\n    commit message gets added to the \"Log:\" tag to help Git cvsimport not\n    get confused if the CVS log/commit message included lines starting with\n    any of the tags found in CVSps PatchSet, e.g., Members:\n    \n    This is part of a larger change to make CVS to Git import more robust.\n\ndiff --git a/git-cvsimport.perl b/git-cvsimport.perl\nindex 36929921e..5d78c5e87 100755\n--- a/git-cvsimport.perl\n+++ b/git-cvsimport.perl\n@@ -786,6 +786,13 @@ open(CVS, \"<$cvspsfile\") or die $!;\n #\n #---------------------\n \n+# NOTE:\n+## pk, 2017/10/30\n+# patched cvsps will output ^Log: line with number of lines of log\n+# which are to follow. This makes parsing robust for cases where the\n+# log message contains ^Members: lines! Happens in OpenBSD sources:\n+# e.g., See src/usr.sbin/bgpd/rde.c\n+\n my $state = 0;\n \n sub update_index (\\@\\@) {\n@@ -816,7 +823,7 @@ sub write_tree () {\n \treturn $tree;\n }\n \n-my ($patchset,$date,$author_name,$author_email,$author_tz,$branch,$ancestor,$tag,$logmsg);\n+my ($patchset,$date,$author_name,$author_email,$author_tz,$branch,$ancestor,$tag,$logmsg,$loglines);\n my (@old,@new,@skipped,%ignorebranch,@commit_revisions);\n \n # commits that cvsps cannot place anywhere...\n@@ -1005,8 +1012,13 @@ while (<CVS>) {\n \t\t\t$tag = $_;\n \t\t}\n \t\t$state = 7;\n-\t} elsif ($state == 7 and /^Log:/) {\n+\t} elsif ($state == 7 and /^Log:\\s*(\\d+)?$/) {\n+\t\t$loglines = $1 // -1;\n \t\t$logmsg = \"\";\n+\t\twhile ($loglines-- > 0 && ($_ = <CVS>)) {\n+\t\t\tchomp;\n+\t\t\t$logmsg .= \"$_\\n\";\n+\t\t}\n \t\t$state = 8;\n \t} elsif ($state == 8 and /^Members:/) {\n \t\t$branch = $opt_o if $branch eq \"HEAD\";\n"}]}