Re: [PATCH v2 03/11] serve: add "receive" method for v2 capabilities table
From: Junio C Hamano <hidden>
Date: 2021-09-15 16:41:50
Jeff King [off-list ref] writes:
+ /* + * Function called when a client requests the capability as a + * non-command. This may be NULL if the capability does nothing. + * + * For a capability of the form "foo=bar", the value string points to + * the content after the "=" (i.e., "bar"). For simple capabilities + * (just "foo"), it is NULL. + */ + void (*receive)(struct repository *r, const char *value);
What does "as a non-command" mean? To put it another way, when a client requests the capability as a command, what does the receive method do differently?
quoted hunk
@@ -164,12 +174,17 @@ static struct protocol_capability *get_capability(const char *key, const char ** return NULL; } -static int is_valid_capability(const char *key) +static int receive_client_capability(const char *key) { const char *value; const struct protocol_capability *c = get_capability(key, &value); - return c && c->advertise(the_repository, NULL); + if (!c || !c->advertise(the_repository, NULL)) + return 0; + + if (c->receive) + c->receive(the_repository, value); + return 1; } static int parse_command(const char *key, struct protocol_capability **command)@@ -262,7 +277,7 @@ static int process_request(void) case PACKET_READ_NORMAL: /* collect request; a sequence of keys and values */
The comment tentatively gets slightly stale here, but that will be corrected at the end, so it would be fine ;-)
if (parse_command(reader.line, &command) ||
- is_valid_capability(reader.line))
+ receive_client_capability(reader.line))
strvec_push(&keys, reader.line);
else
die("unknown capability '%s'", reader.line);