Skip to content

getwholeline should clear the buffer upon EOF

Junio C Hamano git 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest6 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6mailinfo: do not call handle_body() when headers end at EOFmailinfo.c t/t5100-mailinfo.sh+30 -60 replies
2/6t4201: demonstrate shortlog reusing stale buffer on EOFt/t4201-shortlog.sh+29 -00 replies
3/6t7301: demonstrate "clean -i" ask mode deleting past EOFt/t7301-clean-interactive.sh+20 -00 replies
4/6t9300: demonstrate fast-import re-parsing heredoc delimiter at EOFt/t9300-fast-import.sh+27 -00 replies
5/6strbuf_getwholeline(): clear strbuf upon EOFstrbuf.c t/t4201-shortlog.sh t/t7301-clean-interactive.sh +1 more+8 -60 replies
6/6t7301, t9300: test EOF loops fixed by clearing strbuf upon EOFt/t7301-clean-interactive.sh t/t9300-fast-import.sh+44 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

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

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(-)
Signature · 1 line
2.56.1-766-g80003c9184