diff mbox series

[22/44] fetch-pack: parse and advertise the object-format capability

Message ID 20200513005424.81369-23-sandals@crustytoothpaste.net (mailing list archive)
State New, archived
Headers show
Series SHA-256 part 2/3: protocol functionality | expand

Commit Message

brian m. carlson May 13, 2020, 12:54 a.m. UTC
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>
---
 fetch-pack.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Martin Ă…gren May 16, 2020, 11:03 a.m. UTC | #1
On Wed, 13 May 2020 at 02:56, brian m. carlson
<sandals@crustytoothpaste.net> wrote:
>
> Parse the server's object-format capability and respond accordingly,
> dying if there is a mismatch.

> +       if (server_feature_v2("object-format", &hash_name)) {
> +               int hash_algo = hash_algo_by_name(hash_name);
> +               if (hash_algo_by_ptr(the_hash_algo) != hash_algo)
> +                       die(_("mismatched algorithms: client %s; server %s"),
> +                           the_hash_algo->name, hash_name);
> +               packet_write_fmt(fd_out, "object-format=%s", the_hash_algo->name);
> +       }
> +       else if (hash_algo_by_ptr(the_hash_algo) != GIT_HASH_SHA1)
> +               die(_("the server does not support algorithm '%s'"),
> +                   the_hash_algo->name);

Micronit: "} else if (...) {", i.e., join to one line and add braces.


Martin
diff mbox series

Patch

diff --git a/fetch-pack.c b/fetch-pack.c
index 1d277190e7..3a48ed4b13 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1179,6 +1179,7 @@  static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
 			      int sideband_all, int seen_ack)
 {
 	int ret = 0;
+	const char *hash_name;
 	struct strbuf req_buf = STRBUF_INIT;
 
 	if (server_supports_v2("fetch", 1))
@@ -1193,6 +1194,17 @@  static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
 					 args->server_options->items[i].string);
 	}
 
+	if (server_feature_v2("object-format", &hash_name)) {
+		int hash_algo = hash_algo_by_name(hash_name);
+		if (hash_algo_by_ptr(the_hash_algo) != hash_algo)
+			die(_("mismatched algorithms: client %s; server %s"),
+			    the_hash_algo->name, hash_name);
+		packet_write_fmt(fd_out, "object-format=%s", the_hash_algo->name);
+	}
+	else if (hash_algo_by_ptr(the_hash_algo) != GIT_HASH_SHA1)
+		die(_("the server does not support algorithm '%s'"),
+		    the_hash_algo->name);
+
 	packet_buf_delim(&req_buf);
 	if (args->use_thin_pack)
 		packet_buf_write(&req_buf, "thin-pack");