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

Re: [PATCH 2/2] merge-ort/merge-recursive: do report errors in `merge_submodule()`

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Mar 9, 2024, 20:46 UTC
Message-ID
<a0af1155-59d9-0c35-f3e9-c0fe1ba0e11b@gmx.de>
In-Reply-To
<xmqqwmqbcmrz.fsf@gitster.g>
Hi Junio,
On Sat, 9 Mar 2024, Junio C Hamano wrote:
Show 45 quoted lines
> "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
>
> > From: Johannes Schindelin <johannes.schindelin@gmx.de>
> >
> > In 24876ebf68b (commit-reach(repo_in_merge_bases_many): report missing
> > commits, 2024-02-28), I taught `merge_submodule()` to handle errors
> > reported by `repo_in_merge_bases_many()`.
> >
> > However, those errors were not passed through to the callers. That was
> > unintentional, and this commit remedies that.
> >
> > Note that `find_first_merges()` can now also return -1 (because it
> > passes through that return value from `repo_in_merge_bases()`), and this
> > commit also adds the forgotten handling for that scenario.
>
> Good clean-up.  But this "oops, we did not check for errors" makes
> me wonder if we are better off adopting "by default we assume an
> error, until we are sure we are good" pattern, i.e.
>
>         func()
>         {
>                 int ret = -1; /* assume worst */
>
>                 do stuff;
>                 if (...) {
>                         error(_("this is bad"));
>                         goto cleanup;
>                 }
>                 do stuff;
>                 if (...) {
>                         error(_("this is bad, too"));
>                         goto cleanup;
>                 }
>
>                 /* ok we are happy */
>                 ret = 0;
>
>         cleanup:
>                 release resources;
>                 return ret;
>         }
>
> The patch to both functions do make it appear that they are good
> candidates for application of the pattern to me.

This is a very fitting pattern here, and it is in fact used already! It is used with `ret = 0`, though, to indicate unclean merges.

This makes sense, as most of the specifically-handled cases have that outcome. By my counting, 5 of the handled cases result in ret = -1, i.e. non-recoverable errors, but 8 of the cases result in ret = 0, i.e. unclean merges, whereas only 2 cases return 1, i.e. clean merges.

Those numbers are for the `merge_submodule()` variant in `merge-ort.c`. In `merge-recursive.c`, by my counting there are 10 instead of 8 `ret = 0` cases, the other two numbers are the same.

Ciao, Johannes

Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 9 in “The merge-base logic vs missing commit objects (follow-up)”
  1. 0/2 The merge-base logic vs missing commit objects (follow-up)Johannes Schindelin via GitGitGadget, Mar 9, 2024
  2. 1/2 merge-recursive: prepare for `merge_submodule()` to report errorsJohannes Schindelin via GitGitGadget, Mar 9, 2024
  3. 2/2 merge-ort/merge-recursive: do report errors in `merge_submodule()`Johannes Schindelin via GitGitGadget, Mar 9, 2024
  4. Junio C HamanoMar 9, 2024
  5. Johannes SchindelinMar 9, 2024
  6. Junio C HamanoMar 9, 2024
  7. Elijah NewrenMar 9, 2024
  8. Junio C HamanoMar 9, 2024
  9. Junio C HamanoMar 9, 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.