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

Re: [PATCH 1/5] merge-ort: propagate callback errors from traverse_trees_wrapper()

From
Elijah Newren <newren@gmail.com>
Date
Jun 14, 2026, 03:16 UTC
Message-ID
<CABPp-BEGvmes=mH=XKf0YYRLB-S2bAd_LB4hqaQOxp9xBCF3Bw@mail.gmail.com>
In-Reply-To
<xmqq33z65ui1.fsf@gitster.g>
Sorry for the late reply...
On Mon, Jun 1, 2026 at 5:13 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 21 quoted lines
>
> "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: Elijah Newren <newren@gmail.com>
> >
> > traverse_trees_wrapper() saves entries from a first pass through
> > traverse_trees() and then replays them through the real callback
> > (collect_merge_info_callback).  However, the replay loop silently
> > discards the callback return value.  This means any error reported by
> > the callback during replay -- including a future check for malformed
> > trees -- would be ignored, allowing the merge to proceed with corrupt
> > state.
> >
> > Capture the return value, stop the loop on negative (error) returns,
> > and propagate the error to the caller.  Note that the callback returns
> > a positive mask value on success, so we normalize non-negative returns
> > to 0 for the caller.
>
> All makes perfect sense.
>
> How would the externally visible behaviour change at this step?
There's almost no change at this point.  There is only one callpath
that can result in a negative return value, from near the top of
traverse_trees():
    if (traverse_trees_cur_depth > r->settings.max_allowed_tree_depth)
        return error("exceeded maximum allowed tree depth");
All other paths return non-negative values currently, so this patch is
mostly preparatory for later patches in this series.
Show 11 quoted lines
> Upon an error from the callback, we used to keep going and processed
> other callback data in the renames structure.  We now leave the rest
> unprocessed.
>
> The caller of this helper would never have seen a failure, but now
> they will.  Both callers, collect_merge_info_callback() and
> handle_deferred_entries(), are reacting to a negative "error" return
> well (perhaps because they sometimes call traverse_trees() in the
> same control flow, which does return an error already), so
> presumably there is no downside caused by aborting the innermost
> process upon the first error return.

I'd state it a bit differently: not only is there no downwise to aborting upon the first error, there IS a clear downside from ignoring the errors and attempting to proceed anyway. This code wasn't a deferred error kind of thing; it was an ignored error. For the maximum allowed tree depth issue, we'd just prune the trees below that depth and pretend that was the correct merge. And our lack of detecting duplicate tree entries essentially means that we have a "last one wins" (are we sure that's really the correct rule?) with the added wrinkle that the first one can toggle various state flags that can further tweak the merge and maybe even trip some assertions.

I'll add some of this info to the commit message.
Previous: Junio C HamanoNext: Elijah Newren via GitGitGadget
Message 4 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.