git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH 6/6] merge-ort: fix directory rename on top of source of other rename/delete
Date: Fri, 1 Aug 2025 10:31:11 +0200	[thread overview]
Message-ID: <aIx7TxhXHhRI3vEt@pks.im> (raw)
In-Reply-To: <0813d42d91fe9e27f713de3c7d2377c28311ae57.1753197791.git.gitgitgadget@gmail.com>

On Tue, Jul 22, 2025 at 03:23:11PM +0000, Elijah Newren via GitGitGadget wrote:

What a massive commit message. It almost felt like a blog post rather
than a commit message, but I certainly don't mind the additional
context.

> From: Elijah Newren <newren@gmail.com>
> 
> At GitHub, we've got a real-world repository that has been triggering
> failures of the form:
> 
>     git: merge-ort.c:3007: process_renames: Assertion `newinfo && !newinfo->merged.clean' failed.
> 
> which comes from the line:
> 
>     VERIFY_CI(newinfo);
> 
> Unfortunately, this one has been quite complex to unravel, and is a
> bit complex to explain.  So, I'm going to carefully try to explain each
> relevant piece needed to understand the fix, then carefully build up
> from a simple testcase to some of the relevant testcases.
> 
> == New special case we need to consider ==
> 
> Rename pairs in the diffcore machinery connect the source path of a
> rename with the destination path of a rename.  Since we have rename
> pairs to consider on both sides of history since the merge base,
> merging has to consider a few special cases of possible overlap:
> 
>   A) two rename pairs having the same target path
>   B) two rename pairs having the same source path
>   C) the source path of one rename pair being the target path of a
>      different rename pair

So basically file A get's moved somewhere else and then replaced by a
different file B?

> Some of these came up often enough that we gave them names:
>   A) a rename/rename(2to1) conflict (looks similar to an add/add conflict)
>   B) a rename/rename(1to2) conflict, which represents the same path being
>      renamed differently on the two sides of history
>   C) not yet named
> 
> merge-ort is well-prepared to handle cases (A) and (B), as was
> merge-recursive (which was merge-ort's predecessor).  Case (C) was
> briefly considered during the years of merge-recursive maintenance,
> but the full extent of support it got was a few FIXME/TODO comments
> littered around the code highlighting some of the places that would
> probably need to be fixed to support it.  When I wrote merge-ort I
> ignored case (C) entirely, since I believed that case (C) was only
> possible if we were to support break detection during merges.  Not
> only had break detection never been supported by any merge algorithm,
> I thought break detection wasn't worth the effort to support in a
> merge algorithm.  However, it turns out that case (C) can be triggered
> without break detection, if there's enough moving pieces.
> 
> Before I dive into how to trigger case (C) with directory renames plus
> other renames, it might be helpful to use a simpler example with break
> detection first.  And before we get to that it may help to explain
> some more basics of handling renames in the merge algorithm.  So, let
> me first backup and provide a quick refresher on on each of

s/on on/on/

[snip]
> == Directory rename detection ==
> 
> If one side of history renames directory D/ -> E/, and the other side of
> history adds new files to E/, then directory rename detection notices

Did you mean to say "D/" here?

[snip]
> == Testcases 8+ ==
> 
> Another bonus bug, found via understanding our final solution (and the
> failure of our first attempted solution)!

s/solution/solutions/ as there are multiple attempted solutions that
were discarded?

> diff --git a/merge-ort.c b/merge-ort.c
> index feb06720c7e1..f1ecccee940b 100644
> --- a/merge-ort.c
> +++ b/merge-ort.c
> @@ -2313,14 +2313,20 @@ static char *apply_dir_rename(struct strmap_entry *rename_info,
>  	return strbuf_detach(&new_path, NULL);
>  }
>  
> -static int path_in_way(struct strmap *paths, const char *path, unsigned side_mask)
> +static int path_in_way(struct strmap *paths,
> +		       const char *path,
> +		       unsigned side_mask,
> +		       struct diff_filepair *p)
>  {
>  	struct merged_info *mi = strmap_get(paths, path);
>  	struct conflict_info *ci;
>  	if (!mi)
>  		return 0;
>  	INITIALIZE_CI(ci, mi);
> -	return mi->clean || (side_mask & (ci->filemask | ci->dirmask));
> +	return mi->clean || (side_mask & (ci->filemask | ci->dirmask))
> +	  // See testcases 12n, 12p, 12q for more details on this next condition

This should use `/* */`-style comments.

> +			 || ((ci->filemask & 0x01) &&
> +			     strcmp(p->one->path, path));

So if we have a stage 1 index entry and the path is the same due to a
transitive rename we can say that the path is not in the way?

Patrick

  reply	other threads:[~2025-08-01  8:31 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-22 15:23 [PATCH 0/6] Fix various rename corner cases Elijah Newren via GitGitGadget
2025-07-22 15:23 ` [PATCH 1/6] merge-ort: update comments to modern testfile location Elijah Newren via GitGitGadget
2025-07-22 15:23 ` [PATCH 2/6] merge-ort: drop unnecessary temporary in check_for_directory_rename() Elijah Newren via GitGitGadget
2025-07-22 15:23 ` [PATCH 3/6] t6423: document two bugs with rename-to-self testcases Elijah Newren via GitGitGadget
2025-08-01  8:30   ` Patrick Steinhardt
2025-08-04 19:15     ` Elijah Newren
2025-08-05  4:38       ` Patrick Steinhardt
2025-08-05 18:33         ` Elijah Newren
2025-07-22 15:23 ` [PATCH 4/6] t6423: fix missed staging of file in testcases 12i,12j,12k Elijah Newren via GitGitGadget
2025-08-01  8:30   ` Patrick Steinhardt
2025-08-04 19:23     ` Elijah Newren
2025-08-05  4:38       ` Patrick Steinhardt
2025-08-05 18:33         ` Elijah Newren
2025-07-22 15:23 ` [PATCH 5/6] merge-ort: fix incorrect file handling Elijah Newren via GitGitGadget
2025-08-01  8:31   ` Patrick Steinhardt
2025-08-04 22:08     ` Elijah Newren
2025-08-05  4:39       ` Patrick Steinhardt
2025-08-05 18:34         ` Elijah Newren
2025-07-22 15:23 ` [PATCH 6/6] merge-ort: fix directory rename on top of source of other rename/delete Elijah Newren via GitGitGadget
2025-08-01  8:31   ` Patrick Steinhardt [this message]
2025-08-04 22:33     ` Elijah Newren
2025-08-01  8:31 ` [PATCH 0/6] Fix various rename corner cases Patrick Steinhardt
2025-08-05 19:35 ` [PATCH v2 " Elijah Newren via GitGitGadget
2025-08-05 19:35   ` [PATCH v2 1/6] merge-ort: update comments to modern testfile location Elijah Newren via GitGitGadget
2025-08-05 19:35   ` [PATCH v2 2/6] merge-ort: drop unnecessary temporary in check_for_directory_rename() Elijah Newren via GitGitGadget
2025-08-05 19:35   ` [PATCH v2 3/6] t6423: document two bugs with rename-to-self testcases Elijah Newren via GitGitGadget
2025-08-05 19:35   ` [PATCH v2 4/6] t6423: fix missed staging of file in testcases 12i,12j,12k Elijah Newren via GitGitGadget
2025-08-05 19:35   ` [PATCH v2 5/6] merge-ort: fix incorrect file handling Elijah Newren via GitGitGadget
2025-08-05 19:35   ` [PATCH v2 6/6] merge-ort: fix directory rename on top of source of other rename/delete Elijah Newren via GitGitGadget
2025-08-05 20:18     ` Junio C Hamano
2025-08-05 20:47       ` Elijah Newren
2025-08-06 23:15   ` [PATCH v3 0/7] Fix various rename corner cases Elijah Newren via GitGitGadget
2025-08-06 23:15     ` [PATCH v3 1/7] merge-ort: update comments to modern testfile location Elijah Newren via GitGitGadget
2025-08-06 23:15     ` [PATCH v3 2/7] merge-ort: drop unnecessary temporary in check_for_directory_rename() Elijah Newren via GitGitGadget
2025-08-06 23:15     ` [PATCH v3 3/7] t6423: document two bugs with rename-to-self testcases Elijah Newren via GitGitGadget
2025-08-06 23:15     ` [PATCH v3 4/7] t6423: fix missed staging of file in testcases 12i,12j,12k Elijah Newren via GitGitGadget
2025-08-06 23:15     ` [PATCH v3 5/7] merge-ort: clarify the interning of strings in opt->priv->path Elijah Newren via GitGitGadget
2025-08-06 23:15     ` [PATCH v3 6/7] merge-ort: fix incorrect file handling Elijah Newren via GitGitGadget
2025-08-06 23:15     ` [PATCH v3 7/7] merge-ort: fix directory rename on top of source of other rename/delete Elijah Newren via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aIx7TxhXHhRI3vEt@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=newren@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).