Skip to content

Commit 4b83120

Browse files
bk2204gitster
authored andcommitted
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>
1 parent 9dc78c2 commit 4b83120

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

fetch-pack.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,7 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
11791179
int sideband_all, int seen_ack)
11801180
{
11811181
int ret = 0;
1182+
const char *hash_name;
11821183
struct strbuf req_buf = STRBUF_INIT;
11831184

11841185
if (server_supports_v2("fetch", 1))
@@ -1193,6 +1194,17 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
11931194
args->server_options->items[i].string);
11941195
}
11951196

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+
11961208
packet_buf_delim(&req_buf);
11971209
if (args->use_thin_pack)
11981210
packet_buf_write(&req_buf, "thin-pack");

0 commit comments

Comments
 (0)