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

Re: [PATCH 4/5] merge-ort: abort merge when trees have duplicate entries

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 1, 2026, 12:23 UTC
Message-ID
<xmqqtsrm4fgv.fsf@gitster.g>
In-Reply-To
<0d81c027aafcb386398836ffc73b058b7ea4c702.1776731171.git.gitgitgadget@gmail.com>
"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 19 quoted lines
> From: Elijah Newren <newren@gmail.com>
>
> Trees with duplicate entries are malformed; fsck reports "contains
> duplicate file entries" for them.  merge-ort has from the beginning
> assumed that we would never hit such trees.  It was written with the
> assumption that traverse_trees() calls collect_merge_info_callback() at
> most once per path.  The "sanity checks" in that callback (added in
> d2bc1994f363 (merge-ort: implement a very basic collect_merge_info(),
> 2020-12-13)) verify properties of each individual call but not that
> invariant.  The strmap_put() in setup_path_info() silently overwrites
> the entry from any prior call for the same path, because it assumed
> there would be no other path.  Unfortunately, supplemental data
> structures for various optimizations could still be tweaked before the
> extra paths were overwritten, and those data structures not matching
> expected state could trip various assertions.
>
> Change the return type of setup_path_info() from void to int to allow us
> to detect this case, and abort the merge with a clear error message when
> it occurs.
OK.
Show 7 quoted lines
> @@ -1081,9 +1081,11 @@ static void setup_path_info(struct merge_options *opt,
>  			 */
>  			mi->is_null = 1;
>  	}
> -	strmap_put(&opt->priv->paths, fullpath, mi);
> +	if (strmap_put(&opt->priv->paths, fullpath, mi))
> +		return error(_("tree has duplicate entries for '%s'"), fullpath);

OK. I was wondering what _other_ kind of malformed trees would the updated code by this change is prepared to handle (most notably, tree entries must be sorted, and one way to detect duplicate is to remember one single path that we saw earlier, which would work as long as the entries are sorted). This "ah, we saw that path already" approach is much more robust in that it does not have to depend on a sorted tree.

Makes sense.
Previous: Elijah Newren via GitGitGadgetNext: Elijah Newren via GitGitGadget
Message 9 of 23 in “Duplicate entry hardening”
  1. 0/5 Duplicate entry hardeningElijah Newren via GitGitGadget, Apr 21, 2026
  2. 1/5 merge-ort: propagate callback errors from traverse_trees_wrapper()Elijah Newren via GitGitGadget, Apr 21, 2026
  3. Junio C HamanoJun 1, 2026
  4. Elijah NewrenJun 14, 2026
  5. 2/5 merge-ort: drop unnecessary show_all_errors from collect_merge_info()Elijah Newren via GitGitGadget, Apr 21, 2026
  6. Junio C HamanoJun 1, 2026
  7. 3/5 merge-ort: free diff pairs queue in clear_or_reinit_internal_opts()Elijah Newren via GitGitGadget, Apr 21, 2026
  8. 4/5 merge-ort: abort merge when trees have duplicate entriesElijah Newren via GitGitGadget, Apr 21, 2026
  9. Junio C HamanoJun 1, 2026
  10. 5/5 cache-tree: fix verify_cache() to catch non-adjacent D/F conflictsElijah Newren via GitGitGadget, Apr 21, 2026
  11. Junio C HamanoJun 1, 2026
  12. Elijah NewrenJun 14, 2026
  13. Junio C HamanoJun 1, 2026
  14. Patrick SteinhardtJun 1, 2026
  15. Automated reviews by AI (was Re: [PATCH 0/5] Duplicate entry hardening)Christian Couder, Jun 12, 2026
  16. Junio C HamanoJun 12, 2026
  17. 0/5 Duplicate entry hardeningElijah Newren via GitGitGadget, Jun 14, 2026
  18. 1/5 merge-ort: propagate callback errors from traverse_trees_wrapper()Elijah Newren via GitGitGadget, Jun 14, 2026
  19. 2/5 merge-ort: drop unnecessary show_all_errors from collect_merge_info()Elijah Newren via GitGitGadget, Jun 14, 2026
  20. 3/5 merge-ort: free diff pairs queue in clear_or_reinit_internal_opts()Elijah Newren via GitGitGadget, Jun 14, 2026
  21. 4/5 merge-ort: abort merge when trees have duplicate entriesElijah Newren via GitGitGadget, Jun 14, 2026
  22. 5/5 cache-tree: fix verify_cache() to catch non-adjacent D/F conflictsElijah Newren via GitGitGadget, Jun 14, 2026
  23. Junio C HamanoJun 14, 2026

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.