fetch-pack: parse and advertise the object-format capability
Parse the server's object-format capability and respond accordingly, dying if there is a mismatch. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
May 25, 2020 at 19:59 UTC
4b831208bb365fedd0cce286e0c27627598d9393
1 file changed
+12
fetch-pack.c
+12
@@ -1179,6 +1179,7 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
1179
int sideband_all, int seen_ack)
1180
{
1181
int ret = 0;
1182
+ const char *hash_name;
1183
struct strbuf req_buf = STRBUF_INIT;
1184
1185
if (server_supports_v2("fetch", 1))
@@ -1193,6 +1194,17 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
1194
args->server_options->items[i].string);
1195
}
1196
1197
+ if (server_feature_v2("object-format", &hash_name)) {
1198
+ int hash_algo = hash_algo_by_name(hash_name);
1199
+ if (hash_algo_by_ptr(the_hash_algo) != hash_algo)
1200
+ die(_("mismatched algorithms: client %s; server %s"),
1201
+ the_hash_algo->name, hash_name);
1202
+ packet_write_fmt(fd_out, "object-format=%s", the_hash_algo->name);
1203
+ } else if (hash_algo_by_ptr(the_hash_algo) != GIT_HASH_SHA1) {
1204
+ die(_("the server does not support algorithm '%s'"),
1205
+ the_hash_algo->name);
1206
+ }
1207
+
1208
packet_buf_delim(&req_buf);
1209
if (args->use_thin_pack)
1210
packet_buf_write(&req_buf, "thin-pack");