@@ -883,10 +883,9 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len
if (err)
goto done;
- if (fd >= 0) {
- struct packet_scratch_space scratch;
- err = write_packetized_from_fd_no_flush(fd, process->in, &scratch);
- } else
+ if (fd >= 0)
+ err = write_packetized_from_fd_no_flush(fd, process->in);
+ else
err = write_packetized_from_buf_no_flush(src, len, process->in);
if (err)
goto done;
@@ -250,22 +250,25 @@ void packet_buf_write_len(struct strbuf *buf, const char *data, size_t len)
packet_trace(data, len, 1);
}
-int write_packetized_from_fd_no_flush(int fd_in, int fd_out,
- struct packet_scratch_space *scratch)
+int write_packetized_from_fd_no_flush(int fd_in, int fd_out)
{
int err = 0;
ssize_t bytes_to_write;
+ char *buf = xmalloc(LARGE_PACKET_DATA_MAX);
while (!err) {
- bytes_to_write = xread(fd_in, scratch->buffer,
- sizeof(scratch->buffer));
- if (bytes_to_write < 0)
- return COPY_READ_ERROR;
+ bytes_to_write = xread(fd_in, buf, LARGE_PACKET_DATA_MAX);
+ if (bytes_to_write < 0) {
+ err = COPY_READ_ERROR;
+ break;
+ }
if (bytes_to_write == 0)
break;
- err = packet_write_gently(fd_out, scratch->buffer,
- bytes_to_write);
+ err = packet_write_gently(fd_out, buf, bytes_to_write);
}
+
+ free(buf);
+
return err;
}
@@ -8,10 +8,6 @@
#define LARGE_PACKET_MAX 65520
#define LARGE_PACKET_DATA_MAX (LARGE_PACKET_MAX - 4)
-struct packet_scratch_space {
- char buffer[LARGE_PACKET_DATA_MAX]; /* does not include header bytes */
-};
-
/*
* Write a packetized stream, where each line is preceded by
* its length (including the header) as a 4-byte hex number.
@@ -39,7 +35,7 @@ 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_no_flush(int fd_in, int fd_out, struct packet_scratch_space *scratch);
+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);
/*