serve: provide "receive" function for session-id capability
Rather than pulling the session-id string from the list of collected capabilities, we can handle it as soon as we receive it. This gets us closer to dropping the collected list entirely. The behavior should be the same, with one exception. Previously if the client sent us multiple session-id lines, we'd report only the first. Now we'll pass each one along to trace2. This shouldn't matter in practice, since clients shouldn't do that (and if they do, it's probably sensible to log them all). As this removes the last caller of the static has_capability(), we can remove it, as well (and in fact we must to avoid -Wunused-function complaining). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Sep 14, 2021 at 19:51 UTC
ab539c9094e3e3691f157830f74406042d55f774
1 file changed
+9
-24
serve.c
+9
-24
@@ -57,6 +57,14 @@ static int session_id_advertise(struct repository *r, struct strbuf *value)
57
return 1;
58
}
59
60
+static void session_id_receive(struct repository *r,
61
+ const char *client_sid)
62
+{
63
+ if (!client_sid)
64
+ client_sid = "";
65
+ trace2_data_string("transfer", NULL, "client-sid", client_sid);
66
+}
67
+
68
struct protocol_capability {
69
/*
70
* The name of the capability. The server uses this name when
@@ -121,6 +129,7 @@ static struct protocol_capability capabilities[] = {
129
{
130
.name = "session-id",
131
.advertise = session_id_advertise,
132
+ .receive = session_id_receive,
133
},
134
{
135
.name = "object-info",
@@ -221,26 +230,6 @@ static int parse_command(const char *key, struct protocol_capability **command)
230
return 0;
231
}
232
224
-static int has_capability(const struct strvec *keys, const char *capability,
225
- const char **value)
226
-{
227
- int i;
228
- for (i = 0; i < keys->nr; i++) {
229
- const char *out;
230
- if (skip_prefix(keys->v[i], capability, &out) &&
231
- (!*out || *out == '=')) {
232
- if (value) {
233
- if (*out == '=')
234
- out++;
235
- *value = out;
236
- }
237
- return 1;
238
- }
239
- }
240
-
241
- return 0;
242
-}
243
-
233
enum request_state {
234
PROCESS_REQUEST_KEYS,
235
PROCESS_REQUEST_DONE,
@@ -252,7 +241,6 @@ static int process_request(void)
241
struct packet_reader reader;
242
struct strvec keys = STRVEC_INIT;
243
struct protocol_capability *command = NULL;
255
- const char *client_sid;
244
245
packet_reader_init(&reader, 0, NULL, 0,
246
PACKET_READ_CHOMP_NEWLINE |
@@ -319,9 +307,6 @@ static int process_request(void)
307
the_repository->hash_algo->name,
308
hash_algos[client_hash_algo].name);
309
322
- if (has_capability(&keys, "session-id", &client_sid))
323
- trace2_data_string("transfer", NULL, "client-sid", client_sid);
324
-
310
command->command(the_repository, &reader);
311
312
strvec_clear(&keys);