Skip to content

Commit d9fc3a9

Browse files
committed
Merge branch 'jv/use-larger-buffer-in-upload-pack'
"git upload-pack" (the other side of "git fetch") used a 8kB buffer but most of its payload came on 64kB "packets". The buffer size has been enlarged so that such a packet fits. * jv/use-larger-buffer-in-upload-pack: upload-pack.c: increase output buffer size
2 parents 76987b8 + 55a9651 commit d9fc3a9

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

upload-pack.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,13 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
194194
}
195195

196196
struct output_state {
197-
char buffer[8193];
197+
/*
198+
* We do writes no bigger than LARGE_PACKET_DATA_MAX - 1, because with
199+
* sideband-64k the band designator takes up 1 byte of space. Because
200+
* relay_pack_data keeps the last byte to itself, we make the buffer 1
201+
* byte bigger than the intended maximum write size.
202+
*/
203+
char buffer[(LARGE_PACKET_DATA_MAX - 1) + 1];
198204
int used;
199205
unsigned packfile_uris_started : 1;
200206
unsigned packfile_started : 1;
@@ -269,7 +275,7 @@ static void create_pack_file(struct upload_pack_data *pack_data,
269275
const struct string_list *uri_protocols)
270276
{
271277
struct child_process pack_objects = CHILD_PROCESS_INIT;
272-
struct output_state output_state = { { 0 } };
278+
struct output_state *output_state = xcalloc(1, sizeof(struct output_state));
273279
char progress[128];
274280
char abort_msg[] = "aborting due to possible repository "
275281
"corruption on the remote side.";
@@ -404,7 +410,7 @@ static void create_pack_file(struct upload_pack_data *pack_data,
404410
}
405411
if (0 <= pu && (pfd[pu].revents & (POLLIN|POLLHUP))) {
406412
int result = relay_pack_data(pack_objects.out,
407-
&output_state,
413+
output_state,
408414
pack_data->use_sideband,
409415
!!uri_protocols);
410416

@@ -438,11 +444,12 @@ static void create_pack_file(struct upload_pack_data *pack_data,
438444
}
439445

440446
/* flush the data */
441-
if (output_state.used > 0) {
442-
send_client_data(1, output_state.buffer, output_state.used,
447+
if (output_state->used > 0) {
448+
send_client_data(1, output_state->buffer, output_state->used,
443449
pack_data->use_sideband);
444450
fprintf(stderr, "flushed.\n");
445451
}
452+
free(output_state);
446453
if (pack_data->use_sideband)
447454
packet_flush(1);
448455
return;

0 commit comments

Comments
 (0)