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

Re: [PATCH] notes: remove trailing whitespace from editor template

From
KHKristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
Date
May 27, 2025, 16:11 UTC
Message-ID
<820b1255-c2e0-4383-aebc-46e49112fe2d@app.fastmail.com>
In-Reply-To
<ab009472-d15d-4894-aa83-0ab8b0d2dfbd@gmail.com>
On Tue, May 27, 2025, at 10:24, Phillip Wood wrote:
Show 20 quoted lines
>> Do you mean doing the operation on the output buffer instead?:
>>
>> 	if (strbuf_read(&buf, show.out, 0) < 0)
>> 		die_errno(_("could not read 'show' output"));
>> 	/* strip trailing whitespace introduced by blank lines */
>> 	strbuf_stripspace(&buf, NULL);
>> 	strbuf_add_commented_lines(&cbuf, buf.buf, buf.len, comment_line_str);
>> 	write_or_die(fd, cbuf.buf, cbuf.len);
>>
>> I think that’s cleaner.  But I don’t see how it makes the code more
>> future-proof.
>
> Because it is now stripping buf and not cbuf. If in the future we decide
> to build the message in a buffer rather than writing it piecemeal to
> disk we would change signature of this function to take an strbuf
> instead of a file descriptor and use the buffer provided by the caller
> instead of cbuf. If we were to strip cbuf then a naive conversion would
> end up stripping the buffer passed by caller, not just the output from
> "git show". Various git notes subcommands have a --stripspace option and
> calling strbuf_stripspace() on the caller provided buffer would break that.
So stripping `buf` is what I should do?
Show 8 quoted lines
>>> Should that be " \$"? What you've got seems to work with dash but I'm
>>> not sure if it is POSIX compliant or not.
>>
>> `$` is the anchor metacharacter in this context (end of string)
>> according to Posix.
>
> Right but what does the shell do to that '$'? It is not escaped and
> inside a double quoted string.
Oh right, it’s about the shell.  I’ll fix it.
Thanks for spotting.
Previous: Phillip WoodNext: Junio C Hamano
Message 6 of 17 in “notes: remove trailing whitespace from editor template”
  1. notes: remove trailing whitespace from editor templatekristofferhaugsbakk@fastmail.com, May 24, 2025
  2. Kristoffer HaugsbakkMay 25, 2025
  3. Phillip WoodMay 26, 2025
  4. Kristoffer HaugsbakkMay 26, 2025
  5. Phillip WoodMay 27, 2025
  6. Kristoffer HaugsbakkMay 27, 2025
  7. Junio C HamanoMay 27, 2025
  8. Eric SunshineMay 27, 2025
  9. Kristoffer HaugsbakkMay 27, 2025
  10. Junio C HamanoMay 27, 2025
  11. Phillip WoodJun 2, 2025
  12. D. Ben KnobleJun 3, 2025
  13. Eric SunshineJun 3, 2025
  14. Kristoffer HaugsbakkJun 9, 2025
  15. Kristoffer HaugsbakkJun 9, 2025
  16. D. Ben KnobleJun 10, 2025
  17. Junio C HamanoJun 10, 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.