to prepare for having a long running odb helper sub-process handling the communication between Git and an external odb. We introduce "odb.<name>.subprocesscommand" to make it possible to define such a sub-process, and we mark such odb helpers with the new 'script_mode' field set to 0. Helpers defined using the existing "odb.<name>.scriptcommand" are marked with the 'script_mode' field set to 1. Implementation of the different capabilities/instructions in the new (sub-)process mode is left for following commits. Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx> --- external-odb.c | 8 +++++++- odb-helper.c | 19 ++++++++++++++----- odb-helper.h | 1 + 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/external-odb.c b/external-odb.c index 31d21bfe04..ccca67eff5 100644 --- a/external-odb.c +++ b/external-odb.c @@ -32,8 +32,14 @@ static int external_odb_config(const char *var, const char *value, void *data) o = find_or_create_helper(name, namelen); - if (!strcmp(subkey, "scriptcommand")) + if (!strcmp(subkey, "scriptcommand")) { + o->script_mode = 1; return git_config_string(&o->cmd, var, value); + } + if (!strcmp(subkey, "subprocesscommand")) { + o->script_mode = 0; + return git_config_string(&o->cmd, var, value); + } return 0; } diff --git a/odb-helper.c b/odb-helper.c index b1f5464214..4c16dd297a 100644 --- a/odb-helper.c +++ b/odb-helper.c @@ -123,6 +123,9 @@ int odb_helper_init(struct odb_helper *o) FILE *fh; struct strbuf line = STRBUF_INIT; + if (!o->script_mode) + return 0; + if (odb_helper_start(o, &cmd, 0, "init") < 0) return -1; @@ -173,16 +176,12 @@ static int odb_helper_object_cmp(const void *va, const void *vb) return hashcmp(a->sha1, b->sha1); } -static void odb_helper_load_have(struct odb_helper *o) +static void have_object_script(struct odb_helper *o) { struct odb_helper_cmd cmd; FILE *fh; struct strbuf line = STRBUF_INIT; - if (o->have_valid) - return; - o->have_valid = 1; - if (odb_helper_start(o, &cmd, 0, "have") < 0) return; @@ -194,6 +193,16 @@ static void odb_helper_load_have(struct odb_helper *o) strbuf_release(&line); fclose(fh); odb_helper_finish(o, &cmd); +} + +static void odb_helper_load_have(struct odb_helper *o) +{ + if (o->have_valid) + return; + o->have_valid = 1; + + if (o->script_mode) + have_object_script(o); qsort(o->have, o->have_nr, sizeof(*o->have), odb_helper_object_cmp); } diff --git a/odb-helper.h b/odb-helper.h index f2fd2b7c9c..04b85f1d02 100644 --- a/odb-helper.h +++ b/odb-helper.h @@ -15,6 +15,7 @@ struct odb_helper { const char *name; const char *cmd; unsigned int supported_capabilities; + int script_mode; struct odb_helper_object { unsigned char sha1[20]; -- 2.14.0.rc1.52.gf02fb0ddac.dirty