Skip to content

Commit 5ef260d

Browse files
peffgitster
authored andcommitted
serve: return capability "value" from get_capability()
When the client sends v2 capabilities, they may be simple, like: foo or have a value like: foo=bar (all of the current capabilities actually expect a value, but the protocol allows for boolean ones). We use get_capability() to make sure the client's pktline matches a capability. In doing so, we parse enough to see the "=" and the value (if any), but we immediately forget it. Nobody cares for now, because they end up parsing the values out later using has_capability(). But in preparation for changing that, let's pass back a pointer so the callers know what we found. Note that unlike has_capability(), we'll return NULL for a "simple" capability. Distinguishing these will be useful for some future patches. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7680452 commit 5ef260d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

serve.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void protocol_v2_advertise_capabilities(void)
139139
strbuf_release(&value);
140140
}
141141

142-
static struct protocol_capability *get_capability(const char *key)
142+
static struct protocol_capability *get_capability(const char *key, const char **value)
143143
{
144144
int i;
145145

@@ -149,16 +149,25 @@ static struct protocol_capability *get_capability(const char *key)
149149
for (i = 0; i < ARRAY_SIZE(capabilities); i++) {
150150
struct protocol_capability *c = &capabilities[i];
151151
const char *out;
152-
if (skip_prefix(key, c->name, &out) && (!*out || *out == '='))
152+
if (!skip_prefix(key, c->name, &out))
153+
continue;
154+
if (!*out) {
155+
*value = NULL;
153156
return c;
157+
}
158+
if (*out++ == '=') {
159+
*value = out;
160+
return c;
161+
}
154162
}
155163

156164
return NULL;
157165
}
158166

159167
static int is_valid_capability(const char *key)
160168
{
161-
const struct protocol_capability *c = get_capability(key);
169+
const char *value;
170+
const struct protocol_capability *c = get_capability(key, &value);
162171

163172
return c && c->advertise(the_repository, NULL);
164173
}
@@ -168,7 +177,8 @@ static int parse_command(const char *key, struct protocol_capability **command)
168177
const char *out;
169178

170179
if (skip_prefix(key, "command=", &out)) {
171-
struct protocol_capability *cmd = get_capability(out);
180+
const char *value;
181+
struct protocol_capability *cmd = get_capability(out, &value);
172182

173183
if (*command)
174184
die("command '%s' requested after already requesting command '%s'",

0 commit comments

Comments
 (0)