Skip to content

Commit 791e1ad

Browse files
steadmongitster
authored andcommitted
upload-pack: advertise session ID in v0 capabilities
When transfer.advertiseSID is true, advertise upload-pack's session ID via the new session-id capability. Signed-off-by: Josh Steadmon <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e97e1cf commit 791e1ad

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

upload-pack.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ struct upload_pack_data {
110110
unsigned done : 1; /* v2 only */
111111
unsigned allow_ref_in_want : 1; /* v2 only */
112112
unsigned allow_sideband_all : 1; /* v2 only */
113+
unsigned advertise_sid : 1;
113114
};
114115

115116
static void upload_pack_data_init(struct upload_pack_data *data)
@@ -141,6 +142,7 @@ static void upload_pack_data_init(struct upload_pack_data *data)
141142
packet_writer_init(&data->writer, 1);
142143

143144
data->keepalive = 5;
145+
data->advertise_sid = 0;
144146
}
145147

146148
static void upload_pack_data_clear(struct upload_pack_data *data)
@@ -1178,6 +1180,11 @@ static void format_symref_info(struct strbuf *buf, struct string_list *symref)
11781180
strbuf_addf(buf, " symref=%s:%s", item->string, (char *)item->util);
11791181
}
11801182

1183+
static void format_session_id(struct strbuf *buf, struct upload_pack_data *d) {
1184+
if (d->advertise_sid)
1185+
strbuf_addf(buf, " session-id=%s", trace2_session_id());
1186+
}
1187+
11811188
static int send_ref(const char *refname, const struct object_id *oid,
11821189
int flag, void *cb_data)
11831190
{
@@ -1193,9 +1200,11 @@ static int send_ref(const char *refname, const struct object_id *oid,
11931200

11941201
if (capabilities) {
11951202
struct strbuf symref_info = STRBUF_INIT;
1203+
struct strbuf session_id = STRBUF_INIT;
11961204

11971205
format_symref_info(&symref_info, &data->symref);
1198-
packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s object-format=%s agent=%s\n",
1206+
format_session_id(&session_id, data);
1207+
packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s%s object-format=%s agent=%s\n",
11991208
oid_to_hex(oid), refname_nons,
12001209
0, capabilities,
12011210
(data->allow_uor & ALLOW_TIP_SHA1) ?
@@ -1205,9 +1214,11 @@ static int send_ref(const char *refname, const struct object_id *oid,
12051214
data->stateless_rpc ? " no-done" : "",
12061215
symref_info.buf,
12071216
data->allow_filter ? " filter" : "",
1217+
session_id.buf,
12081218
the_hash_algo->name,
12091219
git_user_agent_sanitized());
12101220
strbuf_release(&symref_info);
1221+
strbuf_release(&session_id);
12111222
} else {
12121223
packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), refname_nons);
12131224
}
@@ -1299,6 +1310,8 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
12991310
data->allow_sideband_all = git_config_bool(var, value);
13001311
} else if (!strcmp("core.precomposeunicode", var)) {
13011312
precomposed_unicode = git_config_bool(var, value);
1313+
} else if (!strcmp("transfer.advertisesid", var)) {
1314+
data->advertise_sid = git_config_bool(var, value);
13021315
}
13031316

13041317
if (current_config_scope() != CONFIG_SCOPE_LOCAL &&

0 commit comments

Comments
 (0)