From: Johannes Schindelin <johannes.schindelin@xxxxxx> Remove the `packet_flush_gently()` call in `write_packetized_from_buf() and `write_packetized_from_fd()` and require the caller to call it if desired. Rename both functions to `write_packetized_from_*_no_flush()` to prevent later merge accidents. `write_packetized_from_buf()` currently only has one caller: `apply_multi_file_filter()` in `convert.c`. It always wants a flush packet to be written after writing the payload. However, we are about to introduce a caller that wants to write many packets before a final flush packet, so let's make the caller responsible for emitting the flush packet. Signed-off-by: Jeff Hostetler <jeffhost@xxxxxxxxxxxxx> Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- convert.c | 8 ++++++-- pkt-line.c | 10 +++------- pkt-line.h | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/convert.c b/convert.c index 41012c2d301c..bccf7afa8797 100644 --- a/convert.c +++ b/convert.c @@ -885,9 +885,13 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len if (fd >= 0) { struct packet_scratch_space scratch; - err = write_packetized_from_fd(fd, process->in, &scratch); + err = write_packetized_from_fd_no_flush(fd, process->in, &scratch); } else - err = write_packetized_from_buf(src, len, process->in); + err = write_packetized_from_buf_no_flush(src, len, process->in); + if (err) + goto done; + + err = packet_flush_gently(process->in); if (err) goto done; diff --git a/pkt-line.c b/pkt-line.c index 4cff2f7a68a5..3602b0d37092 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -250,8 +250,8 @@ void packet_buf_write_len(struct strbuf *buf, const char *data, size_t len) packet_trace(data, len, 1); } -int write_packetized_from_fd(int fd_in, int fd_out, - struct packet_scratch_space *scratch) +int write_packetized_from_fd_no_flush(int fd_in, int fd_out, + struct packet_scratch_space *scratch) { int err = 0; ssize_t bytes_to_write; @@ -266,12 +266,10 @@ int write_packetized_from_fd(int fd_in, int fd_out, err = packet_write_gently(fd_out, scratch->buffer, bytes_to_write); } - if (!err) - err = packet_flush_gently(fd_out); return err; } -int write_packetized_from_buf(const char *src_in, size_t len, int fd_out) +int write_packetized_from_buf_no_flush(const char *src_in, size_t len, int fd_out) { int err = 0; size_t bytes_written = 0; @@ -287,8 +285,6 @@ int write_packetized_from_buf(const char *src_in, size_t len, int fd_out) err = packet_write_gently(fd_out, src_in + bytes_written, bytes_to_write); bytes_written += bytes_to_write; } - if (!err) - err = packet_flush_gently(fd_out); return err; } diff --git a/pkt-line.h b/pkt-line.h index c0722aefe638..a7149429ac35 100644 --- a/pkt-line.h +++ b/pkt-line.h @@ -39,8 +39,8 @@ void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((f void packet_buf_write_len(struct strbuf *buf, const char *data, size_t len); int packet_flush_gently(int fd); int packet_write_fmt_gently(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3))); -int write_packetized_from_fd(int fd_in, int fd_out, struct packet_scratch_space *scratch); -int write_packetized_from_buf(const char *src_in, size_t len, int fd_out); +int write_packetized_from_fd_no_flush(int fd_in, int fd_out, struct packet_scratch_space *scratch); +int write_packetized_from_buf_no_flush(const char *src_in, size_t len, int fd_out); /* * Read a packetized line into the buffer, which must be at least size bytes -- gitgitgadget