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

Re: [PATCH] commit & merge: modularize the empty message validator

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 11, 2017, 20:22 UTC
Message-ID
<xmqq8tju3eqp.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170711141254.7747-1-kaarticsivaraam91196@gmail.com>
Kaartic Sivaraam <kaarticsivaraam91196@gmail.com> writes:
Show 19 quoted lines
> In the context of "git merge" the meaning of an "empty message"
> is one that contains no line of text. This is not in line with
> "git commit" where an "empty message" is one that contains only
> whitespaces and/or signed-off-by lines. This could cause surprises
> to users who are accustomed to the meaning of an "empty message"
> of "git commit".
>
> Prevent such surprises by ensuring the meaning of an empty 'merge
> message' to be in line with that of an empty 'commit message'. This
> is done by separating the empty message validator from 'commit' and
> making it stand-alone.
>
> Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
> ---
>  I have made an attempt to solve the issue by separating the concerned
>  function as I found no reason against it.
>
>  I've tried to name them with what felt appropriate and concise to me.
>  Let me know if it's alright.

I probably would have avoided a pair of new files just to house a single function. I anticipate that the last helper function in commit.c at the top-level would become relevant to this topic, and because of that, I would have added this function at the end of the file if I were doing this patch.

Show 6 quoted lines
> @@ -772,7 +773,7 @@ static void prepare_to_commit(struct commit_list *remoteheads)
>  	}
>  	read_merge_msg(&msg);
>  	strbuf_stripspace(&msg, 0 < option_edit);
> -	if (!msg.len)
> +	if (!msg.len || message_is_empty(&msg, 0))

I do not see much point in checking !msg.len here. The function immediately returns by hitting the termination condition of the outermost loop and this is not a performance-critical codepath.

I think the "validation" done with the rest_is_empty() is somewhat bogus. Why should we reject a commit without a message and a trailer block with only signed-off-by lines, while accepting a commit without a message and a trailer block as long as the trailer block has something equally meaningless by itself, like "Helped-by:"? I think we should inspect the proposed commit log message taken from the editor, find its tail ignoring the trailing comment using ignore_non_trailer, and further separate the result into (<message>, <trailers>, <junk at the tail>) using the same logic used by the interpret-trailers tool, and then complain when <message> turns out to be empty, to be truly useful and consistent.

And for that eventual future, merging the logic used in commit and merge might be a good first step.

Having said all that, I am not sure "Prevent such surprises" is a problem that is realistic to begin with. When a user sees the editor buffer in "git merge", it is pre-populated with at least a single line of message "Merge branch 'foo'", possibly followed by the summary of the side branch being merged, so unless the user deliberately removes everything and then add a sign-off line (because we do not usually add one), there is no room for "such surprises" in the first place. It does not _hurt_ to diagnose such a crazy case, but it feels a bit lower priority.

So from the point of "let's improve what merge does", this change looks to me a borderline "Meh"; but to improve the "why sign-off is so special and behave differently from helped-by when deciding if there is any log?" situation, having a separate helper function that is shared across multiple codepaths that accept edited result may be a good idea.

Previous: Kaartic SivaraamNext: Kaartic Sivaraam
Message 9 of 24 in “Why doesn't merge fail if message has only sign-off?”
  1. Kaartic SivaraamJul 2, 2017
  2. Junio C HamanoJul 3, 2017
  3. Kaartic SivaraamJul 4, 2017
  4. merge-message: change meaning of "empty merge message"Kaartic Sivaraam, Jul 6, 2017
  5. Kevin DaudtJul 6, 2017
  6. Kaartic SivaraamJul 6, 2017
  7. commit & merge: modularize the empty message validatorKaartic Sivaraam, Jul 11, 2017
  8. Kaartic SivaraamJul 11, 2017
  9. Junio C HamanoJul 11, 2017
  10. Kaartic SivaraamJul 13, 2017
  11. Junio C HamanoJul 13, 2017
  12. Kaartic SivaraamJul 14, 2017
  13. Christian BrabandtJul 17, 2017
  14. Junio C HamanoJul 17, 2017
  15. Kaartic SivaraamJul 13, 2017
  16. Junio C HamanoJul 13, 2017
  17. Kaartic SivaraamJul 14, 2017
  18. Kaartic SivaraamJul 15, 2017
  19. branch: change the error messages to be more meaningfulKaartic Sivaraam, Aug 21, 2017
  20. Kaartic SivaraamAug 21, 2017
  21. commit: change the meaning of an empty commit messageKaartic Sivaraam, Aug 21, 2017
  22. Junio C HamanoAug 24, 2017
  23. Kaartic SivaraamAug 31, 2017
  24. Kaartic SivaraamOct 2, 2017

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.