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

Re: [PATCH 2/2] merge-ort: fix slightly overzealous assertion for rename-to-self

From
Taylor Blau <me@ttaylorr.com>
Date
Mar 12, 2025, 22:00 UTC
Message-ID
<Z9ID/2zx25qesuJs@nand.local>
In-Reply-To
<f48b3310d4ae8d05780fd25e467083c4dc9852cc.1741275027.git.gitgitgadget@gmail.com>
On Thu, Mar 06, 2025 at 03:30:27PM +0000, Elijah Newren via GitGitGadget wrote:
Show 19 quoted lines
> From: Elijah Newren <newren@gmail.com>
>
> merge-ort has a number of sanity checks on the file it is processing in
> process_renames().  One of these sanity checks was slightly overzealous
> because it indirectly assumed that a renamed file always ended up at a
> different path than where it started.  That is normally an entirely fair
> assumption, but directory rename detection can make things interesting.
>
> As a quick refresher, if one side of history renames directory A/ -> B/,
> and the other side of history adds new files to A/, then directory
> rename detection notices and suggests moving those new files to B/.  A
> similar thing is done for paths renamed into A/, causing them to be
> transitively renamed into B/.  But, if the file originally came from B/,
> then this can end up causing a file to be renamed back to itself.
>
> It turns out the rest of the code following this assertion handled the
> case fine; the assertion was just an extra sanity check, not a rigid
> precondition.  Therefore, simply adjust the assertion to pass under this
> special case as well.

Wow, that is a very interesting edge case from Dmitry. The explanation and fix makes sense, and yeah, looks like just an over-zealous assertion.

As a meta-comment, I vaguely remember past discussions on the list about when to assert() versus when to BUG(). I recall that where we landed was that:

    if (foo)
        BUG("something");
was preferable to:
    assert(foo);

I know that we don't usually define NDEBUG, but I think there are a couple of cases where we do, like for nedmalloc stuff when building with USE_NED_ALLOCATOR, and in Windows builds if DEBUG is undefined.

So I don't think it makes a huge practical difference, but it might be nice to put in CodingGuidelines or similar.

Thanks, Taylor

Previous: Elijah Newren via GitGitGadgetNext: Elijah Newren
Message 4 of 11 in “merge-ort: fix a crash in process_renames for a file transitively renamed to itself”
  1. 0/2 merge-ort: fix a crash in process_renames for a file transitively renamed to itselfElijah Newren via GitGitGadget, Mar 6, 2025
  2. 1/2 t6423: add a testcase causing a failed assertion in process_renamesDmitry Goncharov via GitGitGadget, Mar 6, 2025
  3. 2/2 merge-ort: fix slightly overzealous assertion for rename-to-selfElijah Newren via GitGitGadget, Mar 6, 2025
  4. Taylor BlauMar 12, 2025
  5. Elijah NewrenMar 12, 2025
  6. Junio C HamanoMar 12, 2025
  7. Elijah NewrenMar 13, 2025
  8. Junio C HamanoMar 13, 2025
  9. Elijah NewrenMar 13, 2025
  10. Junio C HamanoMar 13, 2025
  11. Elijah NewrenMar 14, 2025

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.