git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Bug in merge-recursive in virtual commit corner case

From
Junio C Hamano <junkio@cox.net>
Date
Dec 7, 2006, 09:13 UTC
Message-ID
<7vmz60ukz1.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20061207083531.GA22701@spearce.org>
Shawn Pearce <spearce@spearce.org> writes:
Show 19 quoted lines
> I found the above error message in tree-diff.c's diff_tree_sha1
> function.  I threw in debugging and found that the new tree was
> the root tree of one branch and the base was the root tree of some
> other revision.
>
> Apparently the empty tree is being created in merge-recursive.c:
>
>    1219     if (merged_common_ancestors == NULL) {
>    1220         /* if there is no common ancestor, make an empty tree */
>    1221         struct tree *tree = xcalloc(1, sizeof(struct tree));
>    1222
>    1223         tree->object.parsed = 1;
>    1224         tree->object.type = OBJ_TREE;
>    1225         hash_sha1_file(NULL, 0, tree_type, tree->object.sha1);
>    1226         merged_common_ancestors = make_virtual_commit(tree, "ancestor");
>    1227     }
>
> So basically this code crashes if its ever used in a repository
> that hasn't had a need for the empty tree before.  :-(

I hit the same issue when I integrated Johannes's in-core merge; I originally used hash_sha1_file() but that results in objects that are supposed to be in the virtual parent unreadable when merging the real children. The key is to use write_sha1_file() to actually create the needed objects, and trust later prune to remove them.

Replace it with write_sha1_file() and you should be fine, I think.

Previous: Shawn PearceNext: Johannes Schindelin
Message 2 of 6 in “Bug in merge-recursive in virtual commit corner case”
  1. Shawn PearceDec 7, 2006
  2. Junio C HamanoDec 7, 2006
  3. Johannes SchindelinDec 7, 2006
  4. Shawn PearceDec 7, 2006
  5. Johannes SchindelinDec 8, 2006
  6. Junio C HamanoDec 8, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.