git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Calvin Wan <calvinwan@google.com>,
	Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH v2 2/3] merge-ort: add comment to avoid surprise with new sub_flag variable
Date: Wed, 17 Aug 2022 14:45:15 -0700	[thread overview]
Message-ID: <xmqqedxetuhg.fsf@gitster.g> (raw)
In-Reply-To: <340c0f46f74acd641945fceba5ab5feac011ae60.1660718028.git.gitgitgadget@gmail.com> (Elijah Newren via GitGitGadget's message of "Wed, 17 Aug 2022 06:33:47 +0000")

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Elijah Newren <newren@gmail.com>
>
> Commit 4057523a40 ("submodule merge: update conflict error message",
> 2022-08-04) added a sub_flag variable that is used to store a value from
> enum conflict_and_info_types, but initializes it with an invalid value
> of -1.  The code may never set it to a valid value, and use the invalid
> one.  This can be surprising when reading over the code at first, but it
> was intentional.  Add a comment making it clear that it is okay to be
> using an invalid value, due to how it is used later.

The current code uses -1 as the "suggest the default course of
action", so -1 is very much a "valid value" from the viewpoint of
the code that suggests how to resolve.  It indeed is an invalid
value from the viewpoint of those who maintain conflict_and_info_types
enum.

> Signed-off-by: Elijah Newren <newren@gmail.com>
> ---
>  merge-ort.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/merge-ort.c b/merge-ort.c
> index 67159fc6ef9..0a935a8135f 100644
> --- a/merge-ort.c
> +++ b/merge-ort.c
> @@ -1886,7 +1886,7 @@ cleanup:
>  		const char *abbrev;
>  
>  		util = xmalloc(sizeof(*util));
> -		util->flag = sub_flag;
> +		util->flag = sub_flag; /* May still be -1 */
>  		util->abbrev = NULL;
>  		if (!sub_not_initialized) {
>  			abbrev = repo_find_unique_abbrev(&subrepo, b, DEFAULT_ABBREV);

This new comment may be a slight improvement, but a valid value of
sub_flag is used only to signal the situation where the code does
not know what to suggest, which feels backwards for longer-term code
evolution.  Presumably, we would use the util->flag field to store
which of the known cases we know what to suggest as we know better.

I wonder if we should initialize the variable to the most generic
CONFLICT_SUBMODULE_FAILED_TO_MERGE instead of -1.  The value would
mean "use the default suggestion", and the two known unworkable
values (not-initialized and history-not-available) are currently
handled according to what these two values mean.  We may later add
more specialization based on other CONFLICT_SUBMODULE_* values.

Thanks.


  reply	other threads:[~2022-08-17 21:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-17  0:27 [PATCH 0/3] Fixups for cw/submodule-merge-messages Elijah Newren via GitGitGadget
2022-08-17  0:27 ` [PATCH 1/3] merge-ort: remove translator lego in new "submodule conflict suggestion" Elijah Newren via GitGitGadget
2022-08-17  0:28 ` [PATCH 2/3] merge-ort: add comment to avoid surprise with new sub_flag variable Elijah Newren via GitGitGadget
2022-08-17  0:28 ` [PATCH 3/3] merge-ort: provide helpful submodule update message when possible Elijah Newren via GitGitGadget
2022-08-17  5:37 ` [PATCH 0/3] Fixups for cw/submodule-merge-messages Junio C Hamano
2022-08-17  6:33 ` [PATCH v2 " Elijah Newren via GitGitGadget
2022-08-17  6:33   ` [PATCH v2 1/3] merge-ort: remove translator lego in new "submodule conflict suggestion" Elijah Newren via GitGitGadget
2022-08-17  6:33   ` [PATCH v2 2/3] merge-ort: add comment to avoid surprise with new sub_flag variable Elijah Newren via GitGitGadget
2022-08-17 21:45     ` Junio C Hamano [this message]
2022-08-18  6:36       ` Elijah Newren
2022-08-17  6:33   ` [PATCH v2 3/3] merge-ort: provide helpful submodule update message when possible Elijah Newren via GitGitGadget
2022-08-17 21:31   ` [PATCH v2 0/3] Fixups for cw/submodule-merge-messages Junio C Hamano
2022-08-18  7:15   ` [PATCH v3 " Elijah Newren via GitGitGadget
2022-08-18  7:15     ` [PATCH v3 1/3] merge-ort: remove translator lego in new "submodule conflict suggestion" Elijah Newren via GitGitGadget
2022-08-18  7:15     ` [PATCH v3 2/3] merge-ort: avoid surprise with new sub_flag variable Elijah Newren via GitGitGadget
2022-08-18  7:15     ` [PATCH v3 3/3] merge-ort: provide helpful submodule update message when possible Elijah Newren via GitGitGadget

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=xmqqedxetuhg.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=calvinwan@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=newren@gmail.com \
    /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).