git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Lidong Yan via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org, Lidong Yan <502024330056@smail.nju.edu.cn>
Subject: Re: [PATCH v2] sequencer: replace error() with BUG() in update_squash_messages()
Date: Mon, 2 Jun 2025 14:59:31 +0100	[thread overview]
Message-ID: <eba62aad-a396-46d9-9a37-3521e4e7a23e@gmail.com> (raw)
In-Reply-To: <xmqq1ps6iuw0.fsf@gitster.g>

On 30/05/2025 05:29, Junio C Hamano wrote:
> Phillip Wood <phillip.wood123@gmail.com> writes:
> 
>>> OK.  Or
>>> 	if (!is_fixup(command))
>>> 		BUG("not a FIXUP or SQUASH %d", command);
>>> at the very beginning of the function?
>>
>> Asserting the precondition at the start of the function sounds like a
>> good idea
> 
> I am of two minds.
> 
> I do not know if this is better for longer-term maintainability or
> not.  Such a message at the beginning of the function declares that
> the current implementation does not want to receive a command that
> is not either of these two.  Such a message tells the next developer
> who adds another caller to the function to make sure not to pass
> other commands, which is good.
> 
> But I do not know what it tells to the next developer who wants to
> add support for another command.  After opening that initial gate a
> bit wider, perhaps to
> 
> 	if (!is_filxup(command) && !is_my_new_command(command))
> 		BUT("not a FIXUP or SQUASH or MYCOMMAND %d", command);
> 
> would they make sure to handle their new command correctly in the
> if/elseif cascade, from which we are removing the "error()" with
> such a change, and would our reviewers notice if they forget to do
> so?  I dunno.

I guess it cuts both ways. As you say it is a small function and I think 
someone adding support for a new command would need to do more that just 
change the precondition to get their code to work unless they're calling 
this when they don't need to.

> In any case, such a future change will have to be done with a good
> understanding of the entirety of this small function anyway, so I
> guess either way is OK.

Agreed

Phillip

  reply	other threads:[~2025-06-02 13:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-14 12:44 [PATCH] sequencer: fix memory leak if `update_squash_messages()` failed Lidong Yan via GitGitGadget
2025-05-15 10:08 ` Phillip Wood
2025-05-15 16:20   ` Junio C Hamano
2025-05-15 16:43     ` lidongyan
2025-05-25 10:19 ` [PATCH v2] sequencer: replace error() with BUG() in update_squash_messages() Lidong Yan via GitGitGadget
2025-05-28 22:16   ` Junio C Hamano
2025-05-29 13:39     ` Phillip Wood
2025-05-30  4:29       ` Junio C Hamano
2025-06-02 13:59         ` Phillip Wood [this message]
2025-05-30  1:52   ` [PATCH v3 0/2] " Lidong Yan via GitGitGadget
2025-05-30  1:52     ` [PATCH v3 1/2] " Lidong Yan via GitGitGadget
2025-05-30 13:35       ` Junio C Hamano
2025-05-30  1:52     ` [PATCH v3 2/2] BUG(): remove leading underscore of the format string Lidong Yan via GitGitGadget
2025-05-30 13:15       ` Junio C Hamano
2025-06-03  2:01     ` [PATCH v4 0/2] sequencer: replace error() with BUG() in update_squash_messages() Lidong Yan via GitGitGadget
2025-06-03  2:01       ` [PATCH v4 1/2] " Lidong Yan via GitGitGadget
2025-06-03  2:01       ` [PATCH v4 2/2] BUG(): remove leading underscore of the format string Lidong Yan via GitGitGadget
2025-06-03 17:40         ` 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=eba62aad-a396-46d9-9a37-3521e4e7a23e@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=502024330056@smail.nju.edu.cn \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=phillip.wood@dunelm.org.uk \
    /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).