{"thread":{"id":"46254","subject":"Migration from CVS to Git looses merges","startedAt":"2017-06-25T07:20:48Z","lastAt":"2017-06-25T09:35:12Z","messageCount":3,"participants":["Urs Thuermann","Andreas Schwab"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"323234","messageId":"ygfd19stua3.fsf@tehran.isnogud.escape.de","threadId":"46254","inReplyTo":null,"subject":"Migration from CVS to Git looses merges","fromName":"Urs Thuermann","fromEmail":"urs@isnogud.escape.de","sentAt":"2017-06-25T07:12:52Z","receivedAt":"2017-06-25T07:20:48Z","isPatch":false,"sender":{"key":"urs@isnogud.escape.de","avatar":"https://avatars.githubusercontent.com/u/11499339?v=4"},"body":"I want to convert several old CVS repositories to Git.  Some of these\nCVS repositories contain branches, which have later been merged to the\nmain trunk.  When I try to convert using cvs2git or git cvsimport the\nbranches appear in the new git repository but they are not merged to\nthe master branch.\n\nHere is an example of how the branches in the CVS repository were\ncreated and merged:\n\n    cd /tmp\n    export CVSROOT=$PWD/CVS\n\n    cvs init\n    mkdir CVS/foo\n    cvs co foo\n\n    cd foo\n    (date; seq 10; date) > bar\n    cvs add bar\n    cvs ci -m msg1                              # rev 1.1\n\n    sleep 1\n    printf \"1c\\n%s\\n.\\nwq\\n\" \"`date`\" | ed bar\n    cvs ci -m msg2                              # rev 1.2\n\n    sleep 1\n    cvs tag -b a-branch\n\n    sleep 1\n    printf \"1c\\n%s\\n.\\nwq\\n\" \"`date`\" | ed bar\n    cvs ci -m msg3                              # rev 1.3\n\n    sleep 1\n    cvs up -r a-branch\n    printf \"12c\\n%s\\n.\\nwq\\n\" \"`date`\" | ed bar\n    cvs ci -m msg-b1                            # rev 1.2.2.1\n\n    sleep 1\n    printf \"12c\\n%s\\n.\\nwq\\n\" \"`date`\" | ed bar\n    cvs ci -m msg-b2                            # rev 1.2.2.2\n\n    sleep 1\n    cvs up -A\n    cvs up -j a-branch\n    cvs ci -m \"Merge branch a-branch\"           # rev 1.4\n\nNow I have tried 2 ways to convert this to git:\n\n1. mkdir g; cd g; git cvsimport -A <file> -m foo\n2. mkdir g; cd g; git init;\n   cvs2git --blobfile=foo.blob --dumpfile=foo.dump --username=urs ../CVS/foo\n   cat foo.blob foo.dump | git fast-import\n\nIn both cases, the branch \"a-branch\" is in the git repository but is\nnot merged with the master branch, i.e. rev 1.4 has only parent 1.3\nbut not 1.2.2.2.  I also tried cvsimport with several regexes passed\nusing -M to match \"Merge branch a-branch\", but still the same result.\n\nHow should the CVS repository be converted to git, so that the commit\ncorresponding to rev 1.4 has two parents, 1.3 and 1.2.2.2?\n\nurs\n"},{"id":"323236","messageId":"87a84web83.fsf@linux-m68k.org","threadId":"46254","inReplyTo":"ygfd19stua3.fsf@tehran.isnogud.escape.de","subject":"Re: Migration from CVS to Git looses merges","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2017-06-25T08:13:32Z","receivedAt":"2017-06-25T08:13:46Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"On Jun 25 2017, Urs Thuermann <urs@isnogud.escape.de> wrote:\n\n> In both cases, the branch \"a-branch\" is in the git repository but is\n> not merged with the master branch, i.e. rev 1.4 has only parent 1.3\n> but not 1.2.2.2.  I also tried cvsimport with several regexes passed\n> using -M to match \"Merge branch a-branch\", but still the same result.\n\nMerges are recognized purely by matching the commit message, and the\nregexp must capture the branch name in the first subexpr.  The -m option\nenables some default regexps but won't match your example.  You can use\n-M 'Merge branch ([-\\w]+)' to match it.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"323237","messageId":"ygf7f00tnwh.fsf@tehran.isnogud.escape.de","threadId":"46254","inReplyTo":"87a84web83.fsf@linux-m68k.org","subject":"Re: Migration from CVS to Git looses merges","fromName":"Urs Thuermann","fromEmail":"urs@isnogud.escape.de","sentAt":"2017-06-25T09:30:38Z","receivedAt":"2017-06-25T09:35:12Z","isPatch":false,"sender":{"key":"urs@isnogud.escape.de","avatar":"https://avatars.githubusercontent.com/u/11499339?v=4"},"body":"Andreas Schwab <schwab@linux-m68k.org> writes:\n\n> Merges are recognized purely by matching the commit message, and the\n> regexp must capture the branch name in the first subexpr.  The -m option\n> enables some default regexps but won't match your example.  You can use\n> -M 'Merge branch ([-\\w]+)' to match it.\n\nThanks, I tried again and now it works.  I misread the man page and\nalso tried enclosing the regexp in //, also tried to escape the\nparentheses (as in BRE), and I thought I also tried 'Merge branch (.*)'.\nObviously, I missed that one since it now works.\n\nBTW, I now looked up the regexes for -m in git-cvsimport.perl.  Should\nprobably in the man page.\n\nI also suggest the following patch, so that -m would work with my not\nso uncommon merge commit message:\n\ndiff --git a/git-cvsimport.perl b/git-cvsimport.perl\nindex 1e4e65a..1f8044b 100755\n--- a/git-cvsimport.perl\n+++ b/git-cvsimport.perl\n@@ -207,7 +207,7 @@ if ($#ARGV == 0) {\n \n our @mergerx = ();\n if ($opt_m) {\n-\t@mergerx = ( qr/\\b(?:from|of|merge|merging|merged) ([-\\w]+)/i );\n+\t@mergerx = ( qr/\\b(?:from|of|merge|merging|merged) (?:branch )?([-\\w]+)/i );\n }\n if (@opt_M) {\n \tpush (@mergerx, map { qr/$_/ } @opt_M);\n\n\nurs\n"}]}