git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,  Patrick Steinhardt <ps@pks.im>,
	 Dirk Gouders <dirk@gouders.net>,  Jeff King <peff@peff.net>,
	 Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH 2/2] merge-ort/merge-recursive: do report errors in `merge_submodule()`
Date: Sat, 09 Mar 2024 09:56:00 -0800	[thread overview]
Message-ID: <xmqqwmqbcmrz.fsf@gitster.g> (raw)
In-Reply-To: <50fe1a26515c06afec5ac7fb723727e1365a14fc.1709993397.git.gitgitgadget@gmail.com> (Johannes Schindelin via GitGitGadget's message of "Sat, 09 Mar 2024 14:09:57 +0000")

"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.

Thanks.

> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  merge-ort.c       | 5 +++++
>  merge-recursive.c | 8 ++++++++
>  2 files changed, 13 insertions(+)
>
> diff --git a/merge-ort.c b/merge-ort.c
> index 033c4348e2d..5d36c04f509 100644
> --- a/merge-ort.c
> +++ b/merge-ort.c
> @@ -1819,6 +1819,7 @@ static int merge_submodule(struct merge_options *opt,
>  			 _("Failed to merge submodule %s "
>  			   "(repository corrupt)"),
>  			 path);
> +		ret = -1;
>  		goto cleanup;
>  	}
>  	if (ret2 > 0)
> @@ -1829,6 +1830,7 @@ static int merge_submodule(struct merge_options *opt,
>  			 _("Failed to merge submodule %s "
>  			   "(repository corrupt)"),
>  			 path);
> +		ret = -1;
>  		goto cleanup;
>  	}
>  	if (!ret2) {
> @@ -1848,6 +1850,7 @@ static int merge_submodule(struct merge_options *opt,
>  			 _("Failed to merge submodule %s "
>  			   "(repository corrupt)"),
>  			 path);
> +		ret = -1;
>  		goto cleanup;
>  	}
>  	if (ret2 > 0) {
> @@ -1866,6 +1869,7 @@ static int merge_submodule(struct merge_options *opt,
>  			 _("Failed to merge submodule %s "
>  			   "(repository corrupt)"),
>  			 path);
> +		ret = -1;
>  		goto cleanup;
>  	}
>  	if (ret2 > 0) {
> @@ -1899,6 +1903,7 @@ static int merge_submodule(struct merge_options *opt,
>  			 _("Failed to merge submodule %s "
>  			   "(repository corrupt)"),
>  			 path);
> +		ret = -1;
>  		break;
>  	case 0:
>  		path_msg(opt, CONFLICT_SUBMODULE_FAILED_TO_MERGE, 0,
> diff --git a/merge-recursive.c b/merge-recursive.c
> index f3132a9ecae..fc772c2b113 100644
> --- a/merge-recursive.c
> +++ b/merge-recursive.c
> @@ -1246,12 +1246,14 @@ static int merge_submodule(struct merge_options *opt,
>  	ret2 = repo_in_merge_bases(&subrepo, commit_base, commit_a);
>  	if (ret2 < 0) {
>  		output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path);
> +		ret = -1;
>  		goto cleanup;
>  	}
>  	if (ret2 > 0)
>  		ret2 = repo_in_merge_bases(&subrepo, commit_base, commit_b);
>  	if (ret2 < 0) {
>  		output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path);
> +		ret = -1;
>  		goto cleanup;
>  	}
>  	if (!ret2) {
> @@ -1263,6 +1265,7 @@ static int merge_submodule(struct merge_options *opt,
>  	ret2 = repo_in_merge_bases(&subrepo, commit_a, commit_b);
>  	if (ret2 < 0) {
>  		output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path);
> +		ret = -1;
>  		goto cleanup;
>  	}
>  	if (ret2) {
> @@ -1281,6 +1284,7 @@ static int merge_submodule(struct merge_options *opt,
>  	ret2 = repo_in_merge_bases(&subrepo, commit_b, commit_a);
>  	if (ret2 < 0) {
>  		output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path);
> +		ret = -1;
>  		goto cleanup;
>  	}
>  	if (ret2) {
> @@ -1312,6 +1316,10 @@ static int merge_submodule(struct merge_options *opt,
>  	parent_count = find_first_merges(&subrepo, &merges, path,
>  					 commit_a, commit_b);
>  	switch (parent_count) {
> +	case -1:
> +		output(opt, 1,_("Failed to merge submodule %s (repository corrupt)"), path);
> +		ret = -1;
> +		break;
>  	case 0:
>  		output(opt, 1, _("Failed to merge submodule %s (merge following commits not found)"), path);
>  		break;

  reply	other threads:[~2024-03-09 17:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-09 14:09 [PATCH 0/2] The merge-base logic vs missing commit objects (follow-up) Johannes Schindelin via GitGitGadget
2024-03-09 14:09 ` [PATCH 1/2] merge-recursive: prepare for `merge_submodule()` to report errors Johannes Schindelin via GitGitGadget
2024-03-09 14:09 ` [PATCH 2/2] merge-ort/merge-recursive: do report errors in `merge_submodule()` Johannes Schindelin via GitGitGadget
2024-03-09 17:56   ` Junio C Hamano [this message]
2024-03-09 20:46     ` Johannes Schindelin
2024-03-09 23:18       ` Junio C Hamano
2024-03-09 16:51 ` [PATCH 0/2] The merge-base logic vs missing commit objects (follow-up) Elijah Newren
2024-03-09 17:56   ` Junio C Hamano
2024-03-09 17:45 ` Junio C Hamano

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=xmqqwmqbcmrz.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=dirk@gouders.net \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=peff@peff.net \
    --cc=ps@pks.im \
    /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).