Skip to content

Commit 6af3b00

Browse files
rscharfegitster
authored andcommitted
midx: use buffered I/O to talk to pack-objects
Like f0bca72 (send-pack: use buffered I/O to talk to pack-objects, 2016-06-08), significantly reduce the number of system calls and simplify the code for sending object IDs to pack-objects by using stdio's buffering. Helped-by: Chris Torek <[email protected]> Helped-by: Johannes Sixt <[email protected]> Encouraged-by: Derrick Stolee <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 24b75fa commit 6af3b00

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

midx.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
13831383
uint32_t i;
13841384
unsigned char *include_pack;
13851385
struct child_process cmd = CHILD_PROCESS_INIT;
1386+
FILE *cmd_in;
13861387
struct strbuf base_name = STRBUF_INIT;
13871388
struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
13881389

@@ -1435,6 +1436,8 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
14351436
goto cleanup;
14361437
}
14371438

1439+
cmd_in = xfdopen(cmd.in, "w");
1440+
14381441
for (i = 0; i < m->num_objects; i++) {
14391442
struct object_id oid;
14401443
uint32_t pack_int_id = nth_midxed_pack_int_id(m, i);
@@ -1443,10 +1446,9 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
14431446
continue;
14441447

14451448
nth_midxed_object_oid(&oid, m, i);
1446-
xwrite(cmd.in, oid_to_hex(&oid), the_hash_algo->hexsz);
1447-
xwrite(cmd.in, "\n", 1);
1449+
fprintf(cmd_in, "%s\n", oid_to_hex(&oid));
14481450
}
1449-
close(cmd.in);
1451+
fclose(cmd_in);
14501452

14511453
if (finish_command(&cmd)) {
14521454
error(_("could not finish pack-objects"));

0 commit comments

Comments
 (0)