Skip to content

Commit 2dac9b5

Browse files
stefanbellergitster
authored andcommitted
run_processes_parallel: treat output of children as byte array
We do not want the output to be interrupted by a NUL byte, so we cannot use raw fputs. Introduce strbuf_write to avoid having long arguments in run-command.c. Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8c6b549 commit 2dac9b5

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

run-command.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ static void pp_cleanup(struct parallel_processes *pp)
994994
* When get_next_task added messages to the buffer in its last
995995
* iteration, the buffered output is non empty.
996996
*/
997-
fputs(pp->buffered_output.buf, stderr);
997+
strbuf_write(&pp->buffered_output, stderr);
998998
strbuf_release(&pp->buffered_output);
999999

10001000
sigchain_pop_common();
@@ -1079,7 +1079,7 @@ static void pp_output(struct parallel_processes *pp)
10791079
int i = pp->output_owner;
10801080
if (pp->children[i].state == GIT_CP_WORKING &&
10811081
pp->children[i].err.len) {
1082-
fputs(pp->children[i].err.buf, stderr);
1082+
strbuf_write(&pp->children[i].err, stderr);
10831083
strbuf_reset(&pp->children[i].err);
10841084
}
10851085
}
@@ -1117,11 +1117,11 @@ static int pp_collect_finished(struct parallel_processes *pp)
11171117
strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
11181118
strbuf_reset(&pp->children[i].err);
11191119
} else {
1120-
fputs(pp->children[i].err.buf, stderr);
1120+
strbuf_write(&pp->children[i].err, stderr);
11211121
strbuf_reset(&pp->children[i].err);
11221122

11231123
/* Output all other finished child processes */
1124-
fputs(pp->buffered_output.buf, stderr);
1124+
strbuf_write(&pp->buffered_output, stderr);
11251125
strbuf_reset(&pp->buffered_output);
11261126

11271127
/*

strbuf.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,12 @@ ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
395395
return cnt;
396396
}
397397

398+
ssize_t strbuf_write(struct strbuf *sb, FILE *f)
399+
{
400+
return sb->len ? fwrite(sb->buf, 1, sb->len, f) : 0;
401+
}
402+
403+
398404
#define STRBUF_MAXLINK (2*PATH_MAX)
399405

400406
int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint)

strbuf.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,12 @@ extern ssize_t strbuf_read_file(struct strbuf *sb, const char *path, size_t hint
386386
*/
387387
extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint);
388388

389+
/**
390+
* Write the whole content of the strbuf to the stream not stopping at
391+
* NUL bytes.
392+
*/
393+
extern ssize_t strbuf_write(struct strbuf *sb, FILE *stream);
394+
389395
/**
390396
* Read a line from a FILE *, overwriting the existing contents
391397
* of the strbuf. The second argument specifies the line

0 commit comments

Comments
 (0)