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 <chrisc...@tuxfamily.org>
---
 external-odb.c |  4 ++++
 odb-helper.c   | 16 +++++++++++-----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/external-odb.c b/external-odb.c
index ec1ec82dd9..9f797d66f4 100644
--- a/external-odb.c
+++ b/external-odb.c
@@ -41,6 +41,10 @@ static int external_odb_config(const char *var, const char 
*value, void *data)
                o->type = ODB_HELPER_SCRIPT_CMD;
                return git_config_string(&o->dealer, var, value);
        }
+       if (!strcmp(subkey, "subprocesscommand")) {
+               o->type = ODB_HELPER_SUBPROCESS_CMD;
+               return git_config_string(&o->dealer, var, value);
+       }
 
        return 0;
 }
diff --git a/odb-helper.c b/odb-helper.c
index 677ea850a5..bf3c1ad8ac 100644
--- a/odb-helper.c
+++ b/odb-helper.c
@@ -116,16 +116,12 @@ static int odb_helper_object_cmp(const void *va, const 
void *vb)
        return oidcmp(&a->oid, &b->oid);
 }
 
-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, "have") < 0)
                return;
 
@@ -137,6 +133,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->type == ODB_HELPER_SCRIPT_CMD)
+               have_object_script(o);
 
        qsort(o->have, o->have_nr, sizeof(*o->have), odb_helper_object_cmp);
 }
-- 
2.17.0.rc0.37.g8f476fabe9

Reply via email to