This adds the infrastructure to send objects to a sub-process handling the communication with an external odb. For now we only handle sending raw blobs using the 'put_raw_obj' instruction. Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx> --- odb-helper.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/odb-helper.c b/odb-helper.c index fce1dff501..db90c0a004 100644 --- a/odb-helper.c +++ b/odb-helper.c @@ -445,6 +445,58 @@ static int get_object_process(struct odb_helper *o, const unsigned char *sha1, i o->cmd, cur_cap); } +static int send_put_packets(struct object_process *entry, + const unsigned char *sha1, + const void *buf, + size_t len, + struct strbuf *status) +{ + struct child_process *process = &entry->subprocess.process; + int err = packet_write_fmt_gently(process->in, "command=put_raw_obj\n"); + if (err) + return err; + + err = packet_write_fmt_gently(process->in, "sha1=%s\n", sha1_to_hex(sha1)); + if (err) + return err; + + err = packet_write_fmt_gently(process->in, "size=%"PRIuMAX"\n", len); + if (err) + return err; + + err = packet_write_fmt_gently(process->in, "kind=blob\n"); + if (err) + return err; + + err = packet_flush_gently(process->in); + if (err) + return err; + + err = write_packetized_from_buf(buf, len, process->in); + if (err) + return err; + + return check_object_process_status(process->out, status); +} + +static int put_object_process(struct odb_helper *o, + const void *buf, size_t len, + const char *type, unsigned char *sha1) +{ + int err; + struct object_process *entry; + struct strbuf status = STRBUF_INIT; + + entry = launch_object_process(o, ODB_HELPER_CAP_PUT_RAW_OBJ); + if (!entry) + return -1; + + err = send_put_packets(entry, sha1, buf, len, &status); + + return check_object_process_error(err, status.buf, entry, o->cmd, + ODB_HELPER_CAP_PUT_RAW_OBJ); +} + struct odb_helper *odb_helper_new(const char *name, int namelen) { struct odb_helper *o; @@ -896,9 +948,9 @@ int odb_helper_get_object(struct odb_helper *o, return res; } -int odb_helper_put_object(struct odb_helper *o, - const void *buf, size_t len, - const char *type, unsigned char *sha1) +static int put_raw_object_script(struct odb_helper *o, + const void *buf, size_t len, + const char *type, unsigned char *sha1) { struct odb_helper_cmd cmd; @@ -924,3 +976,20 @@ int odb_helper_put_object(struct odb_helper *o, odb_helper_finish(o, &cmd); return 0; } + +int odb_helper_put_object(struct odb_helper *o, + const void *buf, size_t len, + const char *type, unsigned char *sha1) +{ + int res; + uint64_t start = getnanotime(); + + if (o->script_mode) + res = put_raw_object_script(o, buf, len, type, sha1); + else + res = put_object_process(o, buf, len, type, sha1); + + trace_performance_since(start, "odb_helper_put_object"); + + return res; +} -- 2.14.0.rc1.52.gf02fb0ddac.dirty