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

Re: Unexpected git merge exit code when killing merge driver during ancestor merge

From
MCMatt Cree <matt.cree@gearset.com>
Date
May 8, 2024, 18:14 UTC
Message-ID
<B2E03023-18FF-453E-91F0-9A55D430EE31@gearset.com>
As time has gone on, I’ve discovered when we do have this crash during an ancestor merge, somewhat unsurprisingly there is an index.lock file left over in the .git directory.
I’ve taken a look at the code and I believe I’ve spotted the issue — I have v2.44.0 checked out atm.
In the function `merge_ort_internal` function the ancestor merges occur using recursion. If there’s an error during this process, a negative number must be set as the `result->clean` value and this is used to terminate the recursion early https://github.com/git/git/blob/184c3b4c735f1c1f0f811fddcf3c2676e7ad613f/merge-ort.c#L5052
In terminating here, it means the code does not continue on to the final merge which uses the merge_ort_nonrecursive_internal which would have been called in the non recursive case anyway https://github.com/git/git/blob/184c3b4c735f1c1f0f811fddcf3c2676e7ad613f/merge-ort.c#L5068 
From what I can see, that function will correctly reinitialise/reset the opt data structure if the call depth is 0? I am guessing that is an indicator that the merge is supposed to be finished? If we did not clear it here, I’d guess we’d run into the same bug I identified during a non-recursive merge. Therefore, back at the point we first found a negative `result->clean` value, I think we probably want to do a similar reinitialisation of the opts i.e.
Show 10 quoted lines
>		if (result->clean < 0)
>			/*
>			 * When there are ancestor merge failures,
>			 * the merge_ort_nonrecursive_internal() cleans these up
>			 * so we must do it here too
>			 */
>			result->priv = opt->priv;
>			result->_properly_initialized = RESULT_INITIALIZED;
>			opt->priv = NULL;
>			return;
I’m really not familiar with C or the git source code so this might be wrong, but it would be useful to have this case handled by git rather than myself as the time between an ancestor merge and a final merge can vary wildly and any kind of ‘short circuit’ logic I write would prefer heavily to use discover of conflicts during an ancestor merge.
Message 1 of 1 in “Re: Unexpected git merge exit code when killing merge driver during ancestor merge”
  1. Matt CreeMay 8, 2024

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.