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

Re: [PATCH] commit: cope with scissors lines in commit message

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 8, 2015, 15:36 UTC
Message-ID
<xmqqoakqciv1.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1433727639-5927-1-git-send-email-szeder@ira.uka.de>
SZEDER Gábor <szeder@ira.uka.de> writes:
Show 18 quoted lines
> The diff and submodule shortlog appended to the commit message template
> by 'git commit --verbose' are not stripped when the commit message
> contains an indented scissors line.
>
> When cleaning up a commit message with 'git commit --verbose' or
> '--cleanup=scissors' the code is careful and triggers only on a pure
> scissors line, i.e. a line containing nothing but a comment character, a
> space, and the scissors cut.  This is good, because people can embed
> scissor lines in the commit message while using 'git commit --verbose',
> and the text they write after their indented scissors line doesn't get
> deleted.
>
> While doing so, however, the cleanup function only looks at the first
> line matching the scissors pattern and if it doesn't start at the
> beginning of the line, then the function just returns without performing
> any cleanup.  This is bad, because a "real" scissors line added by 'git
> commit --verbose' might follow, and in that case the diff and submodule
> shortlog get included in the commit message.

Yikes; this is not just "bad" but simply "wrong". Thanks for noticing.

Show 17 quoted lines
>  void wt_status_truncate_message_at_cut_line(struct strbuf *buf)
>  {
> -	const char *p;
> +	const char *p = buf->buf;
>  	struct strbuf pattern = STRBUF_INIT;
>  
>  	strbuf_addf(&pattern, "%c %s", comment_line_char, cut_line);
> -	p = strstr(buf->buf, pattern.buf);
> -	if (p && (p == buf->buf || p[-1] == '\n'))
> -		strbuf_setlen(buf, p - buf->buf);
> +	while ((p = strstr(p, pattern.buf))) {
> +		if (p == buf->buf || p[-1] == '\n') {
> +			strbuf_setlen(buf, p - buf->buf);
> +			break;
> +		}
> +		p++;
> +	}
I however wonder if we should make strstr() do more work for us.
	strbuf_addf(&pattern, "\n%c %s", comment_line_char, cut_line);
	if (starts_with(buf->buf, pattern.buf + 1))
		strbuf_setlen(buf, 0);
	else if ((p = strstr(buf->buf, pattern.buf)) != NULL)
        	strbuf_setlen(buf, p - buf->buf + 1);
	strbuf_release(&pattern);
perhaps?
Previous: SZEDER GáborNext: SZEDER Gábor
Message 2 of 5 in “commit: cope with scissors lines in commit message”
  1. commit: cope with scissors lines in commit messageSZEDER Gábor, Jun 8, 2015
  2. Junio C HamanoJun 8, 2015
  3. SZEDER GáborJun 8, 2015
  4. commit: cope with scissors lines in commit messageSZEDER Gábor, Jun 9, 2015
  5. commit: cope with scissors lines in commit messageSZEDER Gábor, Jun 9, 2015

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.