fetch-pack: refactor command and capability write
A subsequent commit will need this functionality independent of the rest of send_fetch_request(), so put this into its own function. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Tan committed
Apr 8, 2021 at 18:10 UTC
6871d0cec62dc12d0c5f7390eee8a80614919578
1 file changed
+24
-17
fetch-pack.c
+24
-17
@@ -1213,29 +1213,23 @@ static int add_haves(struct fetch_negotiator *negotiator,
1213
return haves_added;
1214
}
1215
1216
-static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
1217
- struct fetch_pack_args *args,
1218
- const struct ref *wants, struct oidset *common,
1219
- int *haves_to_send, int *in_vain,
1220
- int sideband_all, int seen_ack)
1216
+static void write_fetch_command_and_capabilities(struct strbuf *req_buf,
1217
+ const struct string_list *server_options)
1218
{
1222
- int haves_added;
1223
- int done_sent = 0;
1219
const char *hash_name;
1225
- struct strbuf req_buf = STRBUF_INIT;
1220
1221
if (server_supports_v2("fetch", 1))
1228
- packet_buf_write(&req_buf, "command=fetch");
1222
+ packet_buf_write(req_buf, "command=fetch");
1223
if (server_supports_v2("agent", 0))
1230
- packet_buf_write(&req_buf, "agent=%s", git_user_agent_sanitized());
1224
+ packet_buf_write(req_buf, "agent=%s", git_user_agent_sanitized());
1225
if (advertise_sid && server_supports_v2("session-id", 0))
1232
- packet_buf_write(&req_buf, "session-id=%s", trace2_session_id());
1233
- if (args->server_options && args->server_options->nr &&
1226
+ packet_buf_write(req_buf, "session-id=%s", trace2_session_id());
1227
+ if (server_options && server_options->nr &&
1228
server_supports_v2("server-option", 1)) {
1229
int i;
1236
- for (i = 0; i < args->server_options->nr; i++)
1237
- packet_buf_write(&req_buf, "server-option=%s",
1238
- args->server_options->items[i].string);
1230
+ for (i = 0; i < server_options->nr; i++)
1231
+ packet_buf_write(req_buf, "server-option=%s",
1232
+ server_options->items[i].string);
1233
}
1234
1235
if (server_feature_v2("object-format", &hash_name)) {
@@ -1243,13 +1237,26 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
1237
if (hash_algo_by_ptr(the_hash_algo) != hash_algo)
1238
die(_("mismatched algorithms: client %s; server %s"),
1239
the_hash_algo->name, hash_name);
1246
- packet_buf_write(&req_buf, "object-format=%s", the_hash_algo->name);
1240
+ packet_buf_write(req_buf, "object-format=%s", the_hash_algo->name);
1241
} else if (hash_algo_by_ptr(the_hash_algo) != GIT_HASH_SHA1) {
1242
die(_("the server does not support algorithm '%s'"),
1243
the_hash_algo->name);
1244
}
1245
+ packet_buf_delim(req_buf);
1246
+}
1247
+
1248
+static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
1249
+ struct fetch_pack_args *args,
1250
+ const struct ref *wants, struct oidset *common,
1251
+ int *haves_to_send, int *in_vain,
1252
+ int sideband_all, int seen_ack)
1253
+{
1254
+ int haves_added;
1255
+ int done_sent = 0;
1256
+ struct strbuf req_buf = STRBUF_INIT;
1257
+
1258
+ write_fetch_command_and_capabilities(&req_buf, args->server_options);
1259
1252
- packet_buf_delim(&req_buf);
1260
if (args->use_thin_pack)
1261
packet_buf_write(&req_buf, "thin-pack");
1262
if (args->no_progress)