Skip to content

Commit 3a63c6a

Browse files
dschogitster
authored andcommitted
pkt-line: do not issue flush packets in write_packetized_*()
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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7455e05 commit 3a63c6a

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

convert.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,9 +884,13 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len
884884
goto done;
885885

886886
if (fd >= 0)
887-
err = write_packetized_from_fd(fd, process->in);
887+
err = write_packetized_from_fd_no_flush(fd, process->in);
888888
else
889-
err = write_packetized_from_buf(src, len, process->in);
889+
err = write_packetized_from_buf_no_flush(src, len, process->in);
890+
if (err)
891+
goto done;
892+
893+
err = packet_flush_gently(process->in);
890894
if (err)
891895
goto done;
892896

pkt-line.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void packet_buf_write_len(struct strbuf *buf, const char *data, size_t len)
251251
packet_trace(data, len, 1);
252252
}
253253

254-
int write_packetized_from_fd(int fd_in, int fd_out)
254+
int write_packetized_from_fd_no_flush(int fd_in, int fd_out)
255255
{
256256
char *buf = xmalloc(LARGE_PACKET_DATA_MAX);
257257
int err = 0;
@@ -267,13 +267,11 @@ int write_packetized_from_fd(int fd_in, int fd_out)
267267
break;
268268
err = packet_write_gently(fd_out, buf, bytes_to_write);
269269
}
270-
if (!err)
271-
err = packet_flush_gently(fd_out);
272270
free(buf);
273271
return err;
274272
}
275273

276-
int write_packetized_from_buf(const char *src_in, size_t len, int fd_out)
274+
int write_packetized_from_buf_no_flush(const char *src_in, size_t len, int fd_out)
277275
{
278276
int err = 0;
279277
size_t bytes_written = 0;
@@ -289,8 +287,6 @@ int write_packetized_from_buf(const char *src_in, size_t len, int fd_out)
289287
err = packet_write_gently(fd_out, src_in + bytes_written, bytes_to_write);
290288
bytes_written += bytes_to_write;
291289
}
292-
if (!err)
293-
err = packet_flush_gently(fd_out);
294290
return err;
295291
}
296292

pkt-line.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((f
3232
void packet_buf_write_len(struct strbuf *buf, const char *data, size_t len);
3333
int packet_flush_gently(int fd);
3434
int packet_write_fmt_gently(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
35-
int write_packetized_from_fd(int fd_in, int fd_out);
36-
int write_packetized_from_buf(const char *src_in, size_t len, int fd_out);
35+
int write_packetized_from_fd_no_flush(int fd_in, int fd_out);
36+
int write_packetized_from_buf_no_flush(const char *src_in, size_t len, int fd_out);
3737

3838
/*
3939
* Read a packetized line into the buffer, which must be at least size bytes

0 commit comments

Comments
 (0)