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

[PATCH 0/6] getwholeline should clear the buffer upon EOF

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 22, 2026, 14:03 UTC
Message-ID
<20261122140347.41990-1-gitster@pobox.com>

This series, which is structured in a somewhat unusual way, addresses various issues that are caused by a long-standing API bug that the strbuf_getwholeline() family of functions shared for quite some time.

When they see feof() on their input stream, they immediately return EOF without reading anything (which is good), but they do not clear the output buffer. It is not strictly *wrong* per se, but it proved to be a rather error-prone API contract, as we see in the early part of this series.

Patches 2 (shortlog), 3 (clean -i), and 4 (fast-import) explain the existing bugs in various commands and add test(s) to trigger the bugs, but the fix is left for patch 5, and the fix happens in code far away from where these bugs exist. The usual "describe the fix and demonstrate it with new test_expect_success" pattern is deliberately not followed. This is because doing the usual thing would force reviewers to understand the details of three unrelated commands illustrated in patches 2, 3, and 4, as well as the solution in patch 5 at the same time. Because the code that caused the existing bugs does not appear in any of these steps, the log messages of patches 2-4 instead give detailed walkthroughs and are rather long, which is another reason why the nature of this series discourages following the usual pattern and doing everything in one step.

Then there is a bonus patch 6, which illustrates two additional issues in "clean" and "fast-import" that cannot have test_expect_failure tests that are safe to include before the problem is fixed, because these breakages are infinite loops.

Patch 1, by the way, is what I posted elsewhere already. This is a caller that implicitly relied on strbuf_getwholeline() not clearing the buffer upon feof(), and it is fixed in such a way that it does not matter if strbuf_getwholeline() clears or leaves the buffer upon feof() so "mailinfo" keeps working before or after patch 5 of this series.

 1/6: mailinfo: do not call handle_body() when headers end at EOF
 2/6: t4201: demonstrate shortlog reusing stale buffer on EOF
 3/6: t7301: demonstrate "clean -i" ask mode deleting past EOF
 4/6: t9300: demonstrate fast-import re-parsing heredoc delimiter at EOF
 5/6: strbuf_getwholeline(): clear strbuf upon EOF
 6/6: t7301, t9300: test EOF loops fixed by clearing strbuf upon EOF
 mailinfo.c                   | 18 +++++++----
 strbuf.c                     |  6 ++--
 t/t4201-shortlog.sh          | 29 +++++++++++++++++
 t/t5100-mailinfo.sh          | 18 +++++++++++
 t/t7301-clean-interactive.sh | 31 +++++++++++++++++++
 t/t9300-fast-import.sh       | 60 ++++++++++++++++++++++++++++++++++++
 6 files changed, 154 insertions(+), 8 deletions(-)
-- 
2.56.1-766-g80003c9184
Next: Junio C Hamano
Message 1 of 8 in “getwholeline should clear the buffer upon EOF”
  1. 0/6 getwholeline should clear the buffer upon EOFJunio C Hamano, Nov 22, 2026
  2. 1/6 mailinfo: do not call handle_body() when headers end at EOFJunio C Hamano, Nov 22, 2026
  3. 2/6 t4201: demonstrate shortlog reusing stale buffer on EOFJunio C Hamano, Nov 22, 2026
  4. 3/6 t7301: demonstrate "clean -i" ask mode deleting past EOFJunio C Hamano, Nov 22, 2026
  5. 4/6 t9300: demonstrate fast-import re-parsing heredoc delimiter at EOFJunio C Hamano, Nov 22, 2026
  6. 5/6 strbuf_getwholeline(): clear strbuf upon EOFJunio C Hamano, Nov 22, 2026
  7. 6/6 t7301, t9300: test EOF loops fixed by clearing strbuf upon EOFJunio C Hamano, Nov 22, 2026
  8. Junio C HamanoNov 23, 2026

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.