Skip to content

Commit e56e530

Browse files
peffgitster
authored andcommitted
serve: add "receive" method for v2 capabilities table
We have a capabilities table that tells us what we should tell the client we are capable of, and what to do when a client gives us a particular command (e.g., "command=ls-refs"). But it doesn't tell us what to do when the client sends us back a capability (e.g., "object-format=sha256"). We just collect them all in a strvec and hope somebody can use them later. Instead, let's provide a function pointer in the table to act on these. This will eventually help us avoid collecting the strings, which will be more efficient and less prone to mischief. Using the new method is optional, which helps in two ways: - we can move existing capabilities over to this new system gradually in individual commits - some capabilities we don't actually do anything with anyway. For example, the client is free to say "agent=git/1.2.3" to us, but we do not act on the information in any way. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ef260d commit e56e530

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

serve.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ struct protocol_capability {
7070
* This field should be NULL for capabilities which are not commands.
7171
*/
7272
int (*command)(struct repository *r, struct packet_reader *request);
73+
74+
/*
75+
* Function called when a client requests the capability as a
76+
* non-command. This may be NULL if the capability does nothing.
77+
*
78+
* For a capability of the form "foo=bar", the value string points to
79+
* the content after the "=" (i.e., "bar"). For simple capabilities
80+
* (just "foo"), it is NULL.
81+
*/
82+
void (*receive)(struct repository *r, const char *value);
7383
};
7484

7585
static struct protocol_capability capabilities[] = {
@@ -164,12 +174,17 @@ static struct protocol_capability *get_capability(const char *key, const char **
164174
return NULL;
165175
}
166176

167-
static int is_valid_capability(const char *key)
177+
static int receive_client_capability(const char *key)
168178
{
169179
const char *value;
170180
const struct protocol_capability *c = get_capability(key, &value);
171181

172-
return c && c->advertise(the_repository, NULL);
182+
if (!c || !c->advertise(the_repository, NULL))
183+
return 0;
184+
185+
if (c->receive)
186+
c->receive(the_repository, value);
187+
return 1;
173188
}
174189

175190
static int parse_command(const char *key, struct protocol_capability **command)
@@ -262,7 +277,7 @@ static int process_request(void)
262277
case PACKET_READ_NORMAL:
263278
/* collect request; a sequence of keys and values */
264279
if (parse_command(reader.line, &command) ||
265-
is_valid_capability(reader.line))
280+
receive_client_capability(reader.line))
266281
strvec_push(&keys, reader.line);
267282
else
268283
die("unknown capability '%s'", reader.line);

0 commit comments

Comments
 (0)