send-pack: detect when the server doesn't support our hash
Detect when the server doesn't support our hash algorithm and abort. If the server does support our hash, advertise it as part of our capabilities. 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:58 UTC
82db03abbbce3cfe28f42a16a16c2b5723974954
1 file changed
+6
send-pack.c
+6
@@ -362,6 +362,7 @@ int send_pack(struct send_pack_args *args,
362
int atomic_supported = 0;
363
int use_push_options = 0;
364
int push_options_supported = 0;
365
+ int object_format_supported = 0;
366
unsigned cmds_sent = 0;
367
int ret;
368
struct async demux;
@@ -388,6 +389,9 @@ int send_pack(struct send_pack_args *args,
389
if (server_supports("push-options"))
390
push_options_supported = 1;
391
392
+ if (!server_supports_hash(the_hash_algo->name, &object_format_supported))
393
+ die(_("the receiving end does not support this repository's hash algorithm"));
394
+
395
if (args->push_cert != SEND_PACK_PUSH_CERT_NEVER) {
396
int len;
397
push_cert_nonce = server_feature_value("push-cert", &len);
@@ -428,6 +432,8 @@ int send_pack(struct send_pack_args *args,
432
strbuf_addstr(&cap_buf, " atomic");
433
if (use_push_options)
434
strbuf_addstr(&cap_buf, " push-options");
435
+ if (object_format_supported)
436
+ strbuf_addf(&cap_buf, " object-format=%s", the_hash_algo->name);
437
if (agent_supported)
438
strbuf_addf(&cap_buf, " agent=%s", git_user_agent_sanitized());
439