Skip to content

Commit ab539c9

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c7d3aab commit ab539c9

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

serve.c

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ static int session_id_advertise(struct repository *r, struct strbuf *value)
5757
return 1;
5858
}
5959

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+
6068
struct protocol_capability {
6169
/*
6270
* The name of the capability. The server uses this name when
@@ -121,6 +129,7 @@ static struct protocol_capability capabilities[] = {
121129
{
122130
.name = "session-id",
123131
.advertise = session_id_advertise,
132+
.receive = session_id_receive,
124133
},
125134
{
126135
.name = "object-info",
@@ -221,26 +230,6 @@ static int parse_command(const char *key, struct protocol_capability **command)
221230
return 0;
222231
}
223232

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-
244233
enum request_state {
245234
PROCESS_REQUEST_KEYS,
246235
PROCESS_REQUEST_DONE,
@@ -252,7 +241,6 @@ static int process_request(void)
252241
struct packet_reader reader;
253242
struct strvec keys = STRVEC_INIT;
254243
struct protocol_capability *command = NULL;
255-
const char *client_sid;
256244

257245
packet_reader_init(&reader, 0, NULL, 0,
258246
PACKET_READ_CHOMP_NEWLINE |
@@ -319,9 +307,6 @@ static int process_request(void)
319307
the_repository->hash_algo->name,
320308
hash_algos[client_hash_algo].name);
321309

322-
if (has_capability(&keys, "session-id", &client_sid))
323-
trace2_data_string("transfer", NULL, "client-sid", client_sid);
324-
325310
command->command(the_repository, &reader);
326311

327312
strvec_clear(&keys);

0 commit comments

Comments
 (0)