@matheusbsbs / matheus-bagliano / commits / 7f60501775
Fork 0

remote-curl: implement object-format extensions

Implement the object-format extensions that let us determine the hash algorithm in use when pushing, pulling, and fetching. 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 7f60501775b2a0e0dcabb98fde3eb46fd980a8cc
1 file changed +18 -1
remote-curl.c
+18 -1
@@ -41,7 +41,9 @@ struct options {
41 deepen_relative : 1,
42 from_promisor : 1,
43 no_dependents : 1,
44 - atomic : 1;
44 + atomic : 1,
45 + object_format : 1;
46 + const struct git_hash_algo *hash_algo;
47 };
48 static struct options options;
49 static struct string_list cas_options = STRING_LIST_INIT_DUP;
@@ -190,6 +192,16 @@ static int set_option(const char *name, const char *value)
192 } else if (!strcmp(name, "filter")) {
193 options.filter = xstrdup(value);
194 return 0;
195 + } else if (!strcmp(name, "object-format")) {
196 + int algo;
197 + options.object_format = 1;
198 + if (strcmp(value, "true")) {
199 + algo = hash_algo_by_name(value);
200 + if (algo == GIT_HASH_UNKNOWN)
201 + die("unknown object format '%s'", value);
202 + options.hash_algo = &hash_algos[algo];
203 + }
204 + return 0;
205 } else {
206 return 1 /* unsupported */;
207 }
@@ -231,6 +243,7 @@ static struct ref *parse_git_refs(struct discovery *heads, int for_push)
243 case protocol_v0:
244 get_remote_heads(&reader, &list, for_push ? REF_NORMAL : 0,
245 NULL, &heads->shallow);
246 + options.hash_algo = reader.hash_algo;
247 break;
248 case protocol_unknown_version:
249 BUG("unknown protocol version");
@@ -509,6 +522,9 @@ static struct ref *get_refs(int for_push)
522 static void output_refs(struct ref *refs)
523 {
524 struct ref *posn;
525 + if (options.object_format && options.hash_algo) {
526 + printf(":object-format %s\n", options.hash_algo->name);
527 + }
528 for (posn = refs; posn; posn = posn->next) {
529 if (posn->symref)
530 printf("@%s %s\n", posn->symref, posn->name);
@@ -1439,6 +1455,7 @@ int cmd_main(int argc, const char **argv)
1455 printf("option\n");
1456 printf("push\n");
1457 printf("check-connectivity\n");
1458 + printf("object-format\n");
1459 printf("\n");
1460 fflush(stdout);
1461 } else if (skip_prefix(buf.buf, "stateless-connect ", &arg)) {