Git development
 help / color / mirror / Atom feed
* [PATCH 0/6] getwholeline should clear the buffer upon EOF
@ 2026-11-22 14:03 Junio C Hamano
  2026-11-22 14:03 ` [PATCH 1/6] mailinfo: do not call handle_body() when headers end at EOF Junio C Hamano
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Junio C Hamano @ 2026-11-22 14:03 UTC (permalink / raw)
  To: git

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-23 15:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 14:03 [PATCH 0/6] getwholeline should clear the buffer upon EOF Junio C Hamano
2026-11-22 14:03 ` [PATCH 1/6] mailinfo: do not call handle_body() when headers end at EOF Junio C Hamano
2026-11-22 14:03 ` [PATCH 2/6] t4201: demonstrate shortlog reusing stale buffer on EOF Junio C Hamano
2026-11-22 14:03 ` [PATCH 3/6] t7301: demonstrate "clean -i" ask mode deleting past EOF Junio C Hamano
2026-11-22 14:03 ` [PATCH 4/6] t9300: demonstrate fast-import re-parsing heredoc delimiter at EOF Junio C Hamano
2026-11-22 14:03 ` [PATCH 5/6] strbuf_getwholeline(): clear strbuf upon EOF Junio C Hamano
2026-11-22 14:03 ` [PATCH 6/6] t7301, t9300: test EOF loops fixed by clearing " Junio C Hamano
2026-11-23 15:37 ` [PATCH 0/6] getwholeline should clear the buffer " Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox