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

Re: [PATCH v2] sequencer: replace error() with BUG() in update_squash_messages()

From
Junio C Hamano <gitster@pobox.com>
Date
May 28, 2025, 22:16 UTC
Message-ID
<xmqqr008peil.fsf@gitster.g>
In-Reply-To
<pull.1964.v2.git.git.1748168353204.gitgitgadget@gmail.com>
"Lidong Yan via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 6 quoted lines
> From: Lidong Yan <502024330056@smail.nju.edu.cn>
>
> In sequencer.c, caller only pass TODO_SQUASH or TODO_FIXUP to
> update_squash_messages(), any other command passed in should be
> considered as BUG. Thus I think `return error('unknown command')`
> should be replaced as `BUG('unknown command')`.
Yup.  The only caller has
	else if (is_fixup(command)) {
	     if (update_squash_messages(r, command, ...) {

and is_fixup() is confusingly [*] defined to return true only when the command is one of these two values.

[Footnote]
 * And a similarly named is_fixup_flag() only accepts TODO_FIXUP and
   never TODO_SQUASH.  Both of these helpers probably need to be
   renamed.
Show 11 quoted lines
> diff --git a/sequencer.c b/sequencer.c
> index b5c4043757e..3cd0dd3434e 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -2139,7 +2139,7 @@ static int update_squash_messages(struct repository *r,
>  		strbuf_add_commented_lines(&buf, body, strlen(body),
>  					   comment_line_str);
>  	} else
> -		return error(_("unknown command: %d"), command);
> +		BUG(_("unknown command: %d"), command);
>  	repo_unuse_commit_buffer(r, commit, message);

BUG() is not end-user facing but programmer facing, and we do not use _("...") in them. I see a few existing violators that need to be corrected.

OK.  Or
	if (!is_fixup(command))
		BUG("not a FIXUP or SQUASH %d", command);
at the very beginning of the function?
Previous: Lidong Yan via GitGitGadgetNext: Phillip Wood
Message 6 of 18 in “sequencer: fix memory leak if `update_squash_messages()` failed”
  1. sequencer: fix memory leak if `update_squash_messages()` failedLidong Yan via GitGitGadget, May 14, 2025
  2. Phillip WoodMay 15, 2025
  3. Junio C HamanoMay 15, 2025
  4. lidongyanMay 15, 2025
  5. sequencer: replace error() with BUG() in update_squash_messages()Lidong Yan via GitGitGadget, May 25, 2025
  6. Junio C HamanoMay 28, 2025
  7. Phillip WoodMay 29, 2025
  8. Junio C HamanoMay 30, 2025
  9. Phillip WoodJun 2, 2025
  10. 0/2 sequencer: replace error() with BUG() in update_squash_messages()Lidong Yan via GitGitGadget, May 30, 2025
  11. 1/2 sequencer: replace error() with BUG() in update_squash_messages()Lidong Yan via GitGitGadget, May 30, 2025
  12. Junio C HamanoMay 30, 2025
  13. 2/2 BUG(): remove leading underscore of the format stringLidong Yan via GitGitGadget, May 30, 2025
  14. Junio C HamanoMay 30, 2025
  15. 0/2 sequencer: replace error() with BUG() in update_squash_messages()Lidong Yan via GitGitGadget, Jun 3, 2025
  16. 1/2 sequencer: replace error() with BUG() in update_squash_messages()Lidong Yan via GitGitGadget, Jun 3, 2025
  17. 2/2 BUG(): remove leading underscore of the format stringLidong Yan via GitGitGadget, Jun 3, 2025
  18. Junio C HamanoJun 3, 2025

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.