Skip to content

Commit d8488b9

Browse files
committed
Merge branch 'rs/more-buffered-io'
Use more buffered I/O where we used to call many small write(2)s. * rs/more-buffered-io: upload-pack: use buffered I/O to talk to rev-list midx: use buffered I/O to talk to pack-objects connected: use buffered I/O to talk to rev-list
2 parents ff20794 + a698d67 commit d8488b9

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

connected.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
2222
struct check_connected_options *opt)
2323
{
2424
struct child_process rev_list = CHILD_PROCESS_INIT;
25+
FILE *rev_list_in;
2526
struct check_connected_options defaults = CHECK_CONNECTED_INIT;
26-
char commit[GIT_MAX_HEXSZ + 1];
2727
struct object_id oid;
2828
int err = 0;
2929
struct packed_git *new_pack = NULL;
3030
struct transport *transport;
3131
size_t base_len;
32-
const unsigned hexsz = the_hash_algo->hexsz;
3332

3433
if (!opt)
3534
opt = &defaults;
@@ -122,7 +121,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
122121

123122
sigchain_push(SIGPIPE, SIG_IGN);
124123

125-
commit[hexsz] = '\n';
124+
rev_list_in = xfdopen(rev_list.in, "w");
125+
126126
do {
127127
/*
128128
* If index-pack already checked that:
@@ -135,16 +135,17 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
135135
if (new_pack && find_pack_entry_one(oid.hash, new_pack))
136136
continue;
137137

138-
memcpy(commit, oid_to_hex(&oid), hexsz);
139-
if (write_in_full(rev_list.in, commit, hexsz + 1) < 0) {
140-
if (errno != EPIPE && errno != EINVAL)
141-
error_errno(_("failed write to rev-list"));
142-
err = -1;
138+
if (fprintf(rev_list_in, "%s\n", oid_to_hex(&oid)) < 0)
143139
break;
144-
}
145140
} while (!fn(cb_data, &oid));
146141

147-
if (close(rev_list.in))
142+
if (ferror(rev_list_in) || fflush(rev_list_in)) {
143+
if (errno != EPIPE && errno != EINVAL)
144+
error_errno(_("failed write to rev-list"));
145+
err = -1;
146+
}
147+
148+
if (fclose(rev_list_in))
148149
err = error_errno(_("failed to close rev-list's stdin"));
149150

150151
sigchain_pop(SIGPIPE);

midx.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
14021402
uint32_t i;
14031403
unsigned char *include_pack;
14041404
struct child_process cmd = CHILD_PROCESS_INIT;
1405+
FILE *cmd_in;
14051406
struct strbuf base_name = STRBUF_INIT;
14061407
struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
14071408

@@ -1454,6 +1455,8 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
14541455
goto cleanup;
14551456
}
14561457

1458+
cmd_in = xfdopen(cmd.in, "w");
1459+
14571460
for (i = 0; i < m->num_objects; i++) {
14581461
struct object_id oid;
14591462
uint32_t pack_int_id = nth_midxed_pack_int_id(m, i);
@@ -1462,10 +1465,9 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
14621465
continue;
14631466

14641467
nth_midxed_object_oid(&oid, m, i);
1465-
xwrite(cmd.in, oid_to_hex(&oid), the_hash_algo->hexsz);
1466-
xwrite(cmd.in, "\n", 1);
1468+
fprintf(cmd_in, "%s\n", oid_to_hex(&oid));
14671469
}
1468-
close(cmd.in);
1470+
fclose(cmd_in);
14691471

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

upload-pack.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,8 @@ static int do_reachable_revlist(struct child_process *cmd,
603603
"rev-list", "--stdin", NULL,
604604
};
605605
struct object *o;
606-
char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
606+
FILE *cmd_in = NULL;
607607
int i;
608-
const unsigned hexsz = the_hash_algo->hexsz;
609608

610609
cmd->argv = argv;
611610
cmd->git_cmd = 1;
@@ -623,8 +622,8 @@ static int do_reachable_revlist(struct child_process *cmd,
623622
if (start_command(cmd))
624623
goto error;
625624

626-
namebuf[0] = '^';
627-
namebuf[hexsz + 1] = '\n';
625+
cmd_in = xfdopen(cmd->in, "w");
626+
628627
for (i = get_max_object_index(); 0 < i; ) {
629628
o = get_indexed_object(--i);
630629
if (!o)
@@ -633,11 +632,9 @@ static int do_reachable_revlist(struct child_process *cmd,
633632
o->flags &= ~TMP_MARK;
634633
if (!is_our_ref(o, allow_uor))
635634
continue;
636-
memcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz);
637-
if (write_in_full(cmd->in, namebuf, hexsz + 2) < 0)
635+
if (fprintf(cmd_in, "^%s\n", oid_to_hex(&o->oid)) < 0)
638636
goto error;
639637
}
640-
namebuf[hexsz] = '\n';
641638
for (i = 0; i < src->nr; i++) {
642639
o = src->objects[i].item;
643640
if (is_our_ref(o, allow_uor)) {
@@ -647,11 +644,12 @@ static int do_reachable_revlist(struct child_process *cmd,
647644
}
648645
if (reachable && o->type == OBJ_COMMIT)
649646
o->flags |= TMP_MARK;
650-
memcpy(namebuf, oid_to_hex(&o->oid), hexsz);
651-
if (write_in_full(cmd->in, namebuf, hexsz + 1) < 0)
647+
if (fprintf(cmd_in, "%s\n", oid_to_hex(&o->oid)) < 0)
652648
goto error;
653649
}
654-
close(cmd->in);
650+
if (ferror(cmd_in) || fflush(cmd_in))
651+
goto error;
652+
fclose(cmd_in);
655653
cmd->in = -1;
656654
sigchain_pop(SIGPIPE);
657655

@@ -660,8 +658,8 @@ static int do_reachable_revlist(struct child_process *cmd,
660658
error:
661659
sigchain_pop(SIGPIPE);
662660

663-
if (cmd->in >= 0)
664-
close(cmd->in);
661+
if (cmd_in)
662+
fclose(cmd_in);
665663
if (cmd->out >= 0)
666664
close(cmd->out);
667665
return -1;

0 commit comments

Comments
 (0)