]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pkt-line: do not issue flush packets in write_packetized_*()
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Mon, 15 Mar 2021 21:08:19 +0000 (21:08 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Mar 2021 21:32:50 +0000 (14:32 -0700)
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@microsoft.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
convert.c
pkt-line.c
pkt-line.h

index ee360c2f07ced0daa8f3f7b1b651fae7c245cb26..976d4905cb3a1f3377ac134a23ad5b48b1cb778e 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -884,9 +884,13 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len
                goto done;
 
        if (fd >= 0)
-               err = write_packetized_from_fd(fd, process->in);
+               err = write_packetized_from_fd_no_flush(fd, process->in);
        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;
 
index 66bd0ddfd1d023c944151fe1678fda21c9846550..bb0fb0c3802c9971a3262846f6852e19335b2cfd 100644 (file)
@@ -251,7 +251,7 @@ 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)
+int write_packetized_from_fd_no_flush(int fd_in, int fd_out)
 {
        char *buf = xmalloc(LARGE_PACKET_DATA_MAX);
        int err = 0;
@@ -267,13 +267,11 @@ int write_packetized_from_fd(int fd_in, int fd_out)
                        break;
                err = packet_write_gently(fd_out, buf, bytes_to_write);
        }
-       if (!err)
-               err = packet_flush_gently(fd_out);
        free(buf);
        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;
@@ -289,8 +287,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;
 }
 
index 8c90daa59ef0ca5f32202a1bcf52583b3f324e4f..31012b9943bf352a51dd460c4baf91926e7e9b59 100644 (file)
@@ -32,8 +32,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);
-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);
+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