On Sun, Sep 10, 2017 at 2:12 PM, Lars Schneider
<[email protected]> wrote:
>
>> On 03 Aug 2017, at 10:18, Christian Couder <[email protected]> 
>> wrote:
>>
>> +static void parse_capabilities(char *cap_buf,
>> +                            unsigned int *supported_capabilities,
>> +                            const char *process_name)
>> +{
>> +     struct string_list cap_list = STRING_LIST_INIT_NODUP;
>> +
>> +     string_list_split_in_place(&cap_list, cap_buf, '=', 1);
>> +
>> +     if (cap_list.nr == 2 && !strcmp(cap_list.items[0].string, 
>> "capability")) {
>> +             const char *cap_name = cap_list.items[1].string;
>> +
>> +             if (!strcmp(cap_name, "get_git_obj")) {
>> +                     *supported_capabilities |= ODB_HELPER_CAP_GET_GIT_OBJ;
>> +             } else if (!strcmp(cap_name, "get_raw_obj")) {
>> +                     *supported_capabilities |= ODB_HELPER_CAP_GET_RAW_OBJ;
>> +             } else if (!strcmp(cap_name, "get_direct")) {
>> +                     *supported_capabilities |= ODB_HELPER_CAP_GET_DIRECT;
>> +             } else if (!strcmp(cap_name, "put_git_obj")) {
>> +                     *supported_capabilities |= ODB_HELPER_CAP_PUT_GIT_OBJ;
>> +             } else if (!strcmp(cap_name, "put_raw_obj")) {
>> +                     *supported_capabilities |= ODB_HELPER_CAP_PUT_RAW_OBJ;
>> +             } else if (!strcmp(cap_name, "put_direct")) {
>> +                     *supported_capabilities |= ODB_HELPER_CAP_PUT_DIRECT;
>> +             } else if (!strcmp(cap_name, "have")) {
>> +                     *supported_capabilities |= ODB_HELPER_CAP_HAVE;
>> +             } else {
>> +                     warning("external process '%s' requested unsupported 
>> read-object capability '%s'",
>> +                             process_name, cap_name);
>> +             }
>
> In 1514c8ed ("convert: refactor capabilities negotiation", 2017-06-30) I 
> introduced
> a simpler version of the capabilities negotiation. Maybe useful for you here, 
> too?

Yeah, actually there is also fa64a2fdbe (sub-process: refactor
handshake to common function, 2017-07-26) that Jonathan Tan wrote on
top of your changes and that adds subprocess_handshake(). So the
current code is using it like that:

static int start_object_process_fn(struct subprocess_entry *subprocess)
{
    static int versions[] = {1, 0};
    static struct subprocess_capability capabilities[] = {
        { "get_git_obj", ODB_HELPER_CAP_GET_GIT_OBJ },
        { "get_raw_obj", ODB_HELPER_CAP_GET_RAW_OBJ },
        { "get_direct",  ODB_HELPER_CAP_GET_DIRECT  },
        { "put_git_obj", ODB_HELPER_CAP_PUT_GIT_OBJ },
        { "put_raw_obj", ODB_HELPER_CAP_PUT_RAW_OBJ },
        { "put_direct",  ODB_HELPER_CAP_PUT_DIRECT  },
        { "have",        ODB_HELPER_CAP_HAVE },
        { NULL, 0 }
    };
    struct object_process *entry = (struct object_process *)subprocess;
    return subprocess_handshake(subprocess, "git-read-object", versions, NULL,
                    capabilities,
                    &entry->supported_capabilities);
}

Reply via email to