@matheusbsbs / matheus-bagliano / commits / 6af3b00abc
Fork 0

midx: use buffered I/O to talk to pack-objects

Like f0bca72dc77 (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 <chris.torek@gmail.com> Helped-by: Johannes Sixt <j6t@kdbg.org> Encouraged-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Aug 12, 2020 at 18:52 UTC 6af3b00abc3d2af69e6bdf4f8c0843d7e3bf9c88
1 file changed +5 -3
midx.c
+5 -3
@@ -1383,6 +1383,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
1383 uint32_t i;
1384 unsigned char *include_pack;
1385 struct child_process cmd = CHILD_PROCESS_INIT;
1386 + FILE *cmd_in;
1387 struct strbuf base_name = STRBUF_INIT;
1388 struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
1389
@@ -1435,6 +1436,8 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
1436 goto cleanup;
1437 }
1438
1439 + cmd_in = xfdopen(cmd.in, "w");
1440 +
1441 for (i = 0; i < m->num_objects; i++) {
1442 struct object_id oid;
1443 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,
1446 continue;
1447
1448 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));
1450 }
1449 - close(cmd.in);
1451 + fclose(cmd_in);
1452
1453 if (finish_command(&cmd)) {
1454 error(_("could not finish pack-objects"));