sub-process: do not use strbuf_split*()

The code to read status from subprocess reads one packet line and
tries to find "status=<foo>".  It is way overkill to split the line
into an array of two strbufs to extract <foo>.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano
2025-07-31 15:54:31 -07:00
parent b894d4481f
commit d6fd08bd76

View File

@@ -30,24 +30,21 @@ struct subprocess_entry *subprocess_find_entry(struct hashmap *hashmap, const ch
int subprocess_read_status(int fd, struct strbuf *status) int subprocess_read_status(int fd, struct strbuf *status)
{ {
struct strbuf **pair;
char *line;
int len; int len;
for (;;) { for (;;) {
char *line;
const char *value;
len = packet_read_line_gently(fd, NULL, &line); len = packet_read_line_gently(fd, NULL, &line);
if ((len < 0) || !line) if ((len < 0) || !line)
break; break;
pair = strbuf_split_str(line, '=', 2); if (skip_prefix(line, "status=", &value)) {
if (pair[0] && pair[0]->len && pair[1]) {
/* the last "status=<foo>" line wins */ /* the last "status=<foo>" line wins */
if (!strcmp(pair[0]->buf, "status=")) {
strbuf_reset(status); strbuf_reset(status);
strbuf_addbuf(status, pair[1]); strbuf_addstr(status, value);
} }
} }
strbuf_list_free(pair);
}
return (len < 0) ? len : 0; return (len < 0) ? len : 0;
} }