This adds the infrastructure to handle 'have' instructions in process mode. The answer from the helper sub-process should be like the output in script mode, that is lines like this: sha1 SPACE size SPACE type NEWLINE Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx> --- odb-helper.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/odb-helper.c b/odb-helper.c index db90c0a004..31fb398469 100644 --- a/odb-helper.c +++ b/odb-helper.c @@ -646,6 +646,70 @@ static int odb_helper_object_cmp(const void *va, const void *vb) return hashcmp(a->sha1, b->sha1); } +static int send_have_packets(struct odb_helper *o, + struct object_process *entry, + struct strbuf *status) +{ + char *line; + int packet_len; + int total_got = 0; + struct child_process *process = &entry->subprocess.process; + int err = packet_write_fmt_gently(process->in, "command=have\n"); + + if (err) + return err; + + err = packet_flush_gently(process->in); + if (err) + return err; + + for (;;) { + /* packet_read() writes a '\0' extra byte at the end */ + char buf[LARGE_PACKET_DATA_MAX + 1]; + char *p = buf; + int more; + + packet_len = packet_read(process->out, NULL, NULL, + buf, LARGE_PACKET_DATA_MAX + 1, + PACKET_READ_GENTLE_ON_EOF); + + if (packet_len <= 0) + break; + + total_got += packet_len; + + do { + char *eol = strchrnul(p, '\n'); + more = (*eol == '\n'); + *eol = '\0'; + if (add_have_entry(o, p)) + break; + p = eol + 1; + } while (more); + } + + if (packet_len < 0) + return packet_len; + + return check_object_process_status(process->out, status); +} + +static int have_object_process(struct odb_helper *o) +{ + int err; + struct object_process *entry; + struct strbuf status = STRBUF_INIT; + + entry = launch_object_process(o, ODB_HELPER_CAP_HAVE); + if (!entry) + return -1; + + err = send_have_packets(o, entry, &status); + + return check_object_process_error(err, status.buf, entry, o->cmd, + ODB_HELPER_CAP_HAVE); +} + static void have_object_script(struct odb_helper *o) { struct odb_helper_cmd cmd; @@ -667,12 +731,20 @@ static void have_object_script(struct odb_helper *o) static void odb_helper_load_have(struct odb_helper *o) { + uint64_t start; + if (o->have_valid) return; o->have_valid = 1; + start = getnanotime(); + if (o->script_mode) have_object_script(o); + else + have_object_process(o); + + trace_performance_since(start, "odb_helper_load_have"); qsort(o->have, o->have_nr, sizeof(*o->have), odb_helper_object_cmp); } -- 2.14.0.rc1.52.gf02fb0ddac.dirty