Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 0/6] getwholeline should clear the buffer upon EOF
Date: Sun, 22 Nov 2026 06:03:41 -0800	[thread overview]
Message-ID: <20261122140347.41990-1-gitster@pobox.com> (raw)

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


             reply	other threads:[~2026-11-22 14:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 14:03 Junio C Hamano [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261122140347.41990-1-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox