From: Michael Montalbo <mmontalbo@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [RFC PATCH v7 08/10] sub-process: add a gentle status read
Date: Sat, 1 Aug 2026 10:41:51 -0700 [thread overview]
Message-ID: <20260801174156.2998808-9-mmontalbo@gmail.com> (raw)
In-Reply-To: <20260801174156.2998808-1-mmontalbo@gmail.com>
subprocess_read_status() reads "status=<key>" packets up to a flush with
packet_read_line_gently(), which is gentle only about EOF. A malformed
length header still dies inside pkt-line, and an empty packet is
indistinguishable from the flush that ends the section. A protocol
violation in a status section therefore either kills the whole command
or silently truncates the section. That posture fits the filter
protocol's callers, which treat their process as required
infrastructure; the diff process consult added later in this series
treats its process as optional, and any protocol error must degrade to
the builtin diff rather than abort the command.
Add subprocess_read_status_gently(): the same status loop, reading
through packet_read_with_status() with the gentle options, returning
-1 on a truncated or malformed packet and on an empty packet where a
status line or the terminating flush belongs. subprocess_read_status()
and its callers are unchanged.
The handshake has its gentle counterpart in 061a68e443 (sub-process:
use gentle handshake to avoid die() on startup failure, 2026-06-01),
which turned truncated handshake reads into error returns for every
caller. This series' base includes that commit, so a process that
dies during the handshake feeds the same non-fatal fallback as a
status failure here, and an optional diff process degrades to the
builtin diff on either kind of protocol error.
Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
---
sub-process.c | 24 ++++++++++++++++++++++++
sub-process.h | 10 ++++++++++
2 files changed, 34 insertions(+)
diff --git a/sub-process.c b/sub-process.c
index 3cef42b088..33bd789618 100644
--- a/sub-process.c
+++ b/sub-process.c
@@ -49,6 +49,30 @@ int subprocess_read_status(int fd, struct strbuf *status)
return (len < 0) ? len : 0;
}
+int subprocess_read_status_gently(int fd, struct strbuf *status)
+{
+ for (;;) {
+ int pktlen = -1;
+ enum packet_read_status rs;
+ const char *value;
+
+ rs = packet_read_with_status(fd, NULL, NULL, packet_buffer,
+ sizeof(packet_buffer), &pktlen,
+ PACKET_READ_CHOMP_NEWLINE |
+ PACKET_READ_GENTLE_ON_EOF |
+ PACKET_READ_GENTLE_ON_READ_ERROR);
+ if (rs == PACKET_READ_FLUSH)
+ return 0;
+ if (rs != PACKET_READ_NORMAL || !pktlen)
+ return -1;
+ if (skip_prefix(packet_buffer, "status=", &value)) {
+ /* the last "status=<foo>" line wins */
+ strbuf_reset(status);
+ strbuf_addstr(status, value);
+ }
+ }
+}
+
void subprocess_stop_command(struct subprocess_entry *entry)
{
if (!entry)
diff --git a/sub-process.h b/sub-process.h
index 45f1b8e5e3..8655b38897 100644
--- a/sub-process.h
+++ b/sub-process.h
@@ -101,4 +101,14 @@ int subprocess_handshake(struct subprocess_entry *entry,
int subprocess_read_status(int fd, struct strbuf *status);
+/*
+ * Like subprocess_read_status(), but a malformed status section fails
+ * instead of dying: a truncated or malformed packet, and an empty
+ * packet where a status line or the terminating flush belongs, return
+ * -1 and leave the stream unusable. subprocess_read_status() cannot
+ * tell an empty packet from the flush that ends the section, and dies
+ * on a framing error inside packet_read_line_gently().
+ */
+int subprocess_read_status_gently(int fd, struct strbuf *status);
+
#endif
--
2.54.0
next prev parent reply other threads:[~2026-08-01 17:42 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-22 2:11 [PATCH 0/5] [RFC] diff: add diff.<driver>.process for external hunk providers Michael Montalbo via GitGitGadget
2026-05-22 2:11 ` [PATCH 1/5] xdiff: support external hunks via xpparam_t Michael Montalbo via GitGitGadget
2026-05-22 5:29 ` Junio C Hamano
2026-05-22 19:06 ` Michael Montalbo
2026-05-24 8:50 ` Junio C Hamano
2026-05-24 18:01 ` Michael Montalbo
2026-05-22 2:11 ` [PATCH 2/5] userdiff: add diff.<driver>.process config Michael Montalbo via GitGitGadget
2026-05-22 2:11 ` [PATCH 3/5] diff: add long-running diff process via diff.<driver>.process Michael Montalbo via GitGitGadget
2026-05-22 2:11 ` [PATCH 4/5] blame: consult diff process for zero-hunk detection Michael Montalbo via GitGitGadget
2026-05-22 2:11 ` [PATCH 5/5] diff-process-normalize: add built-in whitespace normalizer Michael Montalbo via GitGitGadget
2026-05-22 5:29 ` [PATCH 0/5] [RFC] diff: add diff.<driver>.process for external hunk providers Junio C Hamano
2026-05-22 17:19 ` Michael Montalbo
2026-05-25 18:29 ` [PATCH v2 0/4] " Michael Montalbo via GitGitGadget
2026-05-25 18:29 ` [PATCH v2 1/4] xdiff: support external hunks via xpparam_t Michael Montalbo via GitGitGadget
2026-05-25 18:29 ` [PATCH v2 2/4] userdiff: add diff.<driver>.process config Michael Montalbo via GitGitGadget
2026-05-25 18:29 ` [PATCH v2 3/4] diff: add long-running diff process via diff.<driver>.process Michael Montalbo via GitGitGadget
2026-05-26 1:56 ` Junio C Hamano
2026-05-29 0:51 ` Michael Montalbo
2026-05-26 2:26 ` Junio C Hamano
2026-05-29 0:55 ` Michael Montalbo
2026-05-25 18:29 ` [PATCH v2 4/4] blame: consult diff process for zero-hunk detection Michael Montalbo via GitGitGadget
2026-05-29 20:48 ` [PATCH v3 0/6] [RFC] diff: add diff.<driver>.process for external hunk providers Michael Montalbo via GitGitGadget
2026-05-29 20:48 ` [PATCH v3 1/6] xdiff: support external hunks via xpparam_t Michael Montalbo via GitGitGadget
2026-05-29 20:48 ` [PATCH v3 2/6] userdiff: add diff.<driver>.process config Michael Montalbo via GitGitGadget
2026-05-29 20:48 ` [PATCH v3 3/6] sub-process: separate process lifecycle from hashmap management Michael Montalbo via GitGitGadget
2026-05-29 20:48 ` [PATCH v3 4/6] diff: add long-running diff process via diff.<driver>.process Michael Montalbo via GitGitGadget
2026-06-07 14:36 ` Johannes Schindelin
2026-06-07 17:04 ` Michael Montalbo
2026-06-08 12:26 ` Junio C Hamano
2026-06-07 20:36 ` Michael Montalbo
2026-06-08 17:19 ` Junio C Hamano
2026-06-08 12:06 ` Junio C Hamano
2026-05-29 20:48 ` [PATCH v3 5/6] diff: bypass diff process with --no-ext-diff and in format-patch Michael Montalbo via GitGitGadget
2026-05-29 20:48 ` [PATCH v3 6/6] blame: consult diff process for no-hunk detection Michael Montalbo via GitGitGadget
2026-05-31 10:44 ` [PATCH v3 0/6] [RFC] diff: add diff.<driver>.process for external hunk providers Junio C Hamano
2026-06-01 4:28 ` Michael Montalbo
2026-06-14 18:59 ` [PATCH v4 " Michael Montalbo via GitGitGadget
2026-06-14 18:59 ` [PATCH v4 1/6] xdiff: support external hunks via xpparam_t Michael Montalbo via GitGitGadget
2026-06-14 18:59 ` [PATCH v4 2/6] userdiff: add diff.<driver>.process config Michael Montalbo via GitGitGadget
2026-06-14 18:59 ` [PATCH v4 3/6] sub-process: separate process lifecycle from hashmap management Michael Montalbo via GitGitGadget
2026-06-14 18:59 ` [PATCH v4 4/6] diff: add long-running diff process via diff.<driver>.process Michael Montalbo via GitGitGadget
2026-06-14 18:59 ` [PATCH v4 5/6] diff: bypass diff process with --no-ext-diff and in format-patch Michael Montalbo via GitGitGadget
2026-06-14 18:59 ` [PATCH v4 6/6] blame: consult diff process for no-hunk detection Michael Montalbo via GitGitGadget
2026-07-15 21:01 ` [PATCH v5 0/9] [RFC] diff: add diff.<driver>.process for external hunk providers Michael Montalbo via GitGitGadget
2026-07-15 21:01 ` [PATCH v5 1/9] gitattributes: document how external diff drivers relate to diff features Michael Montalbo via GitGitGadget
2026-07-15 21:01 ` [PATCH v5 2/9] xdiff: support external hunks via xpparam_t Michael Montalbo via GitGitGadget
2026-07-15 21:01 ` [PATCH v5 3/9] userdiff: add diff.<driver>.process config Michael Montalbo via GitGitGadget
2026-07-15 21:01 ` [PATCH v5 4/9] sub-process: separate process lifecycle from hashmap management Michael Montalbo via GitGitGadget
2026-07-15 21:01 ` [PATCH v5 5/9] diff: add long-running diff process via diff.<driver>.process Michael Montalbo via GitGitGadget
2026-07-15 21:01 ` [PATCH v5 6/9] diff: bypass diff process with --no-ext-diff and in format-patch Michael Montalbo via GitGitGadget
2026-07-15 21:02 ` [PATCH v5 7/9] blame: consult diff process for no-hunk detection Michael Montalbo via GitGitGadget
2026-07-15 21:02 ` [PATCH v5 8/9] diff: consult diff process for --stat counts Michael Montalbo via GitGitGadget
2026-07-15 21:02 ` [PATCH v5 9/9] line-log: consult diff process for range tracking Michael Montalbo via GitGitGadget
2026-07-16 16:40 ` [PATCH v5 0/9] [RFC] diff: add diff.<driver>.process for external hunk providers Junio C Hamano
2026-07-16 17:31 ` Michael Montalbo
2026-07-26 18:51 ` [PATCH v6 " Michael Montalbo via GitGitGadget
2026-07-26 18:51 ` [PATCH v6 1/9] gitattributes: document how external diff drivers relate to diff features Michael Montalbo via GitGitGadget
2026-07-26 18:51 ` [PATCH v6 2/9] xdiff: support external hunks via xpparam_t Michael Montalbo via GitGitGadget
2026-07-26 18:51 ` [PATCH v6 3/9] userdiff: add diff.<driver>.process config Michael Montalbo via GitGitGadget
2026-07-26 18:51 ` [PATCH v6 4/9] sub-process: separate process lifecycle from hashmap management Michael Montalbo via GitGitGadget
2026-07-26 18:51 ` [PATCH v6 5/9] diff: add long-running diff process via diff.<driver>.process Michael Montalbo via GitGitGadget
2026-07-26 18:51 ` [PATCH v6 6/9] diff: bypass diff process with --no-ext-diff and in format-patch Michael Montalbo via GitGitGadget
2026-07-26 18:51 ` [PATCH v6 7/9] blame: consult diff process for no-hunk detection Michael Montalbo via GitGitGadget
2026-07-26 18:51 ` [PATCH v6 8/9] diff: consult diff process for --stat counts Michael Montalbo via GitGitGadget
2026-07-26 18:51 ` [PATCH v6 9/9] line-log: consult diff process for range tracking Michael Montalbo via GitGitGadget
2026-08-01 17:41 ` [RFC PATCH v7 0/10] diff: add provider interface and initial providers Michael Montalbo
2026-08-01 17:41 ` [RFC PATCH v7 01/10] gitattributes: document how external diff drivers relate to diff features Michael Montalbo
2026-08-01 17:41 ` [RFC PATCH v7 02/10] diff: introduce a hunk provider interface Michael Montalbo
2026-08-01 17:41 ` [RFC PATCH v7 03/10] diff-hunks: add the store format, library, and command Michael Montalbo
2026-08-01 17:41 ` [RFC PATCH v7 04/10] diff: record precomputed hunks during stat output Michael Montalbo
2026-08-01 17:41 ` [RFC PATCH v7 05/10] diff: read precomputed hunks for " Michael Montalbo
2026-08-01 17:41 ` [RFC PATCH v7 06/10] blame: read precomputed hunks Michael Montalbo
2026-08-01 17:41 ` [RFC PATCH v7 07/10] sub-process: separate process lifecycle from hashmap management Michael Montalbo
2026-08-01 17:41 ` Michael Montalbo [this message]
2026-08-01 17:41 ` [RFC PATCH v7 09/10] userdiff: add diff.<driver>.process config Michael Montalbo
2026-08-01 17:41 ` [RFC PATCH v7 10/10] diff: consult oid-only hunk providers via diff.<driver>.process Michael Montalbo
2026-08-04 3:15 ` Michael Montalbo
2026-08-13 22:06 ` Junio C Hamano
2026-08-04 13:52 ` [RFC PATCH v7 0/10] diff: add provider interface and initial providers Phillip Wood
[not found] ` <pull.2120.v4.git.1781463332.gitgitgadget@gmail.com>
2026-06-15 21:14 ` [PREVIEW v4 0/6] [RFC] diff: add diff.<driver>.process for external hunk providers Michael Montalbo
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=20260801174156.2998808-9-mmontalbo@gmail.com \
--to=mmontalbo@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johannes.schindelin@gmx.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.