Skip to content

Commit a2a066d

Browse files
steadmongitster
authored andcommitted
receive-pack: log received client session ID
When receive-pack receives a session-id capability from the client, log the received session ID via a trace2 data event. Signed-off-by: Josh Steadmon <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8c48700 commit a2a066d

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

builtin/receive-pack.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,7 @@ static struct command *read_head_info(struct packet_reader *reader,
20392039
if (linelen < reader->pktlen) {
20402040
const char *feature_list = reader->line + linelen + 1;
20412041
const char *hash = NULL;
2042+
const char *client_sid;
20422043
int len = 0;
20432044
if (parse_feature_request(feature_list, "report-status"))
20442045
report_status = 1;
@@ -2061,6 +2062,12 @@ static struct command *read_head_info(struct packet_reader *reader,
20612062
}
20622063
if (xstrncmpz(the_hash_algo->name, hash, len))
20632064
die("error: unsupported object format '%s'", hash);
2065+
client_sid = parse_feature_value(feature_list, "session-id", &len, NULL);
2066+
if (client_sid) {
2067+
char *sid = xstrndup(client_sid, len);
2068+
trace2_data_string("transfer", NULL, "client-sid", client_sid);
2069+
free(sid);
2070+
}
20642071
}
20652072

20662073
if (!strcmp(reader->line, "push-cert")) {

t/t5705-session-id-in-capabilities.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ do
2828
'
2929

3030
test_expect_success "session IDs not advertised by default (push v${PROTO})" '
31-
test_when_finished "rm -rf local tr2-client-events" &&
31+
test_when_finished "rm -rf local tr2-client-events tr2-server-events" &&
32+
test_when_finished "git -C local push --delete origin new-branch" &&
3233
cp -r "$LOCAL_PRISTINE" local &&
3334
git -C local pull --no-rebase origin &&
3435
GIT_TRACE2_EVENT_NESTING=5 \
3536
GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \
36-
git -c protocol.version=$PROTO -C local push origin &&
37-
test -z "$(grep \"key\":\"server-sid\" tr2-client-events)"
37+
git -c protocol.version=$PROTO -C local push \
38+
--receive-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-receive-pack" \
39+
origin HEAD:new-branch &&
40+
test -z "$(grep \"key\":\"server-sid\" tr2-client-events)" &&
41+
test -z "$(grep \"key\":\"client-sid\" tr2-server-events)"
3842
'
3943
done
4044

@@ -57,13 +61,17 @@ do
5761
'
5862

5963
test_expect_success "session IDs advertised (push v${PROTO})" '
60-
test_when_finished "rm -rf local tr2-client-events" &&
64+
test_when_finished "rm -rf local tr2-client-events tr2-server-events" &&
65+
test_when_finished "git -C local push --delete origin new-branch" &&
6166
cp -r "$LOCAL_PRISTINE" local &&
6267
git -C local pull --no-rebase origin &&
6368
GIT_TRACE2_EVENT_NESTING=5 \
6469
GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \
65-
git -c protocol.version=$PROTO -C local push origin &&
66-
grep \"key\":\"server-sid\" tr2-client-events
70+
git -c protocol.version=$PROTO -C local push \
71+
--receive-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-receive-pack" \
72+
origin HEAD:new-branch &&
73+
grep \"key\":\"server-sid\" tr2-client-events &&
74+
grep \"key\":\"client-sid\" tr2-server-events
6775
'
6876
done
6977

0 commit comments

Comments
 (0)