{"thread":{"id":"43262","subject":"Bug in merge-recursive in virtual commit corner case","startedAt":"2006-12-07T08:35:31Z","lastAt":"2006-12-08T06:01:52Z","messageCount":6,"participants":["Shawn Pearce","Junio C Hamano","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"294165","messageId":"20061207083531.GA22701@spearce.org","threadId":"43262","inReplyTo":null,"subject":"Bug in merge-recursive in virtual commit corner case","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-07T08:35:31Z","receivedAt":"2006-12-07T08:35:31Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"So I managed to create a fairly complex set of branches which are all\nmerged back against each other at various points in time.  Two of\nthem have 3 merge bases according to git-merge-base.  Tonight I\ntried to merge them together, but received the following wonderful\nerror from git-merge-recursive:\n\n  fatal: unable to read source tree (4b825dc642cb6eb9a060e54bf8d69288fbee4904)\n\nFor those in the know, that's the empty tree.  This particular\nrepository does not have the empty tree anywhere in it, which is\nwhy we can't read the object: it doesn't exist, and shouldn't exist.\n\nRunning `git-mktree </dev/null` to create the empty tree worked;\ngit-merge-recursive ran through and cleanly merged the two branches.\nBut the empty tree still shouldn't be in my repository, so a future\ngit-prune is just going to whack it again.  Yes, I know, I could\nanchor it with a ref (.git/refs/empty-tree) but I shouldn't need\nto use git-mktree and git-update-ref just to use git-merge-recursive.\n\nI found the above error message in tree-diff.c's diff_tree_sha1\nfunction.  I threw in debugging and found that the new tree was\nthe root tree of one branch and the base was the root tree of some\nother revision.\n\nApparently the empty tree is being created in merge-recursive.c:\n\n   1219     if (merged_common_ancestors == NULL) {\n   1220         /* if there is no common ancestor, make an empty tree */\n   1221         struct tree *tree = xcalloc(1, sizeof(struct tree));\n   1222\n   1223         tree->object.parsed = 1;\n   1224         tree->object.type = OBJ_TREE;\n   1225         hash_sha1_file(NULL, 0, tree_type, tree->object.sha1);\n   1226         merged_common_ancestors = make_virtual_commit(tree, \"ancestor\");\n   1227     }\n\nSo basically this code crashes if its ever used in a repository\nthat hasn't had a need for the empty tree before.  :-(\n\nI've been unable to create an isolated test case.  I can't publish\nthe repository that I caused the case in either.\n\nI'm not quite sure what the fix should be here: patch diff_tree_sha1\nto know when it gets the empty tree, or create the object in\nmerge-recursive.c?\n\n-- \n"},{"id":"298254","messageId":"7vmz60ukz1.fsf@assigned-by-dhcp.cox.net","threadId":"43262","inReplyTo":"20061207083531.GA22701@spearce.org","subject":"Re: Bug in merge-recursive in virtual commit corner case","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-07T09:13:54Z","receivedAt":"2006-12-07T09:13:54Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shawn Pearce <spearce@spearce.org> writes:\n\n> I found the above error message in tree-diff.c's diff_tree_sha1\n> function.  I threw in debugging and found that the new tree was\n> the root tree of one branch and the base was the root tree of some\n> other revision.\n>\n> Apparently the empty tree is being created in merge-recursive.c:\n>\n>    1219     if (merged_common_ancestors == NULL) {\n>    1220         /* if there is no common ancestor, make an empty tree */\n>    1221         struct tree *tree = xcalloc(1, sizeof(struct tree));\n>    1222\n>    1223         tree->object.parsed = 1;\n>    1224         tree->object.type = OBJ_TREE;\n>    1225         hash_sha1_file(NULL, 0, tree_type, tree->object.sha1);\n>    1226         merged_common_ancestors = make_virtual_commit(tree, \"ancestor\");\n>    1227     }\n>\n> So basically this code crashes if its ever used in a repository\n> that hasn't had a need for the empty tree before.  :-(\n\nI hit the same issue when I integrated Johannes's in-core merge;\nI originally used hash_sha1_file() but that results in objects\nthat are supposed to be in the virtual parent unreadable when\nmerging the real children.  The key is to use write_sha1_file()\nto actually create the needed objects, and trust later prune to\nremove them.\n\nReplace it with write_sha1_file() and you should be fine, I\nthink.\n"},{"id":"297223","messageId":"Pine.LNX.4.63.0612071636030.28348@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"43262","inReplyTo":"20061207083531.GA22701@spearce.org","subject":"Re: Bug in merge-recursive in virtual commit corner case","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-07T15:38:23Z","receivedAt":"2006-12-07T15:38:23Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 7 Dec 2006, Shawn Pearce wrote:\n\n> So I managed to create a fairly complex set of branches which are all\n> merged back against each other at various points in time.  Two of\n> them have 3 merge bases according to git-merge-base.  Tonight I\n> tried to merge them together, but received the following wonderful\n> error from git-merge-recursive:\n> \n>   fatal: unable to read source tree (4b825dc642cb6eb9a060e54bf8d69288fbee4904)\n> \n> For those in the know, that's the empty tree.  This particular \n> repository does not have the empty tree anywhere in it, which is why we \n> can't read the object: it doesn't exist, and shouldn't exist.\n\nI think there is something else wrong. If you have three merge bases, I do \nnot see how you could get into that particular code path.\n\nAny possibility for me to have a private look at your repo?\n\nCiao,\nDscho\n"},{"id":"297202","messageId":"20061207192401.GB12143@spearce.org","threadId":"43262","inReplyTo":"Pine.LNX.4.63.0612071636030.28348@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: Bug in merge-recursive in virtual commit corner case","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-07T19:24:01Z","receivedAt":"2006-12-07T19:24:01Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> On Thu, 7 Dec 2006, Shawn Pearce wrote:\n> \n> > So I managed to create a fairly complex set of branches which are all\n> > merged back against each other at various points in time.  Two of\n> > them have 3 merge bases according to git-merge-base.  Tonight I\n> > tried to merge them together, but received the following wonderful\n> > error from git-merge-recursive:\n> > \n> >   fatal: unable to read source tree (4b825dc642cb6eb9a060e54bf8d69288fbee4904)\n> > \n> > For those in the know, that's the empty tree.  This particular \n> > repository does not have the empty tree anywhere in it, which is why we \n> > can't read the object: it doesn't exist, and shouldn't exist.\n> \n> I think there is something else wrong. If you have three merge bases, I do \n> not see how you could get into that particular code path.\n\nArrgh.  I can redo the merge and try to debug it myself; maybe I\ncan at least get enough details about what's going on to create a\ndummy repo which exhibits the same behavior.\n \n> Any possibility for me to have a private look at your repo?\n\nNo, unfortunately for me (I wish I could let you debug this!).\nFar too many legal issues are involved.  There is possible jail\ntime on my part for sharing any of the files in there...  ;-)\n\nAlthough Junio mentioned he recently saw something like this in\ngit.git when he merged in your xdl_merge() code.  I wonder if its\nthe same issue.\n\n-- \n"},{"id":"295235","messageId":"Pine.LNX.4.63.0612080401080.28348@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"43262","inReplyTo":"20061207192401.GB12143@spearce.org","subject":"Re: Bug in merge-recursive in virtual commit corner case","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-08T03:03:03Z","receivedAt":"2006-12-08T03:03:03Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\ncan you send me at least the output of \n\n$ git-rev-list --parents branch1 branch2\n\npreferrably packed? There is nothing you can do legally wrong, since you \nare not sending any data, only metadata.\n\nCiao,\nDscho\n"},{"id":"295105","messageId":"7vd56vorhr.fsf@assigned-by-dhcp.cox.net","threadId":"43262","inReplyTo":"20061207192401.GB12143@spearce.org","subject":"Re: Bug in merge-recursive in virtual commit corner case","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-08T06:01:52Z","receivedAt":"2006-12-08T06:01:52Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shawn Pearce <spearce@spearce.org> writes:\n\n> Although Junio mentioned he recently saw something like this in\n> git.git when he merged in your xdl_merge() code.  I wonder if its\n> the same issue.\n\nNo, that is not related at all.  My initial attempt (which is\nnot in any commit that survives til today) used hash_sha1_file()\non the result from xdl_merge() where I should have used\nwrite_sha1_file(), and I saw the same \"oh, the required object\nis not there\" errors from everywhere.\n\n"}]}