Skip to content

Commit 7f60501

Browse files
bk2204gitster
authored andcommitted
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>
1 parent 8b85ee4 commit 7f60501

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

remote-curl.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ struct options {
4141
deepen_relative : 1,
4242
from_promisor : 1,
4343
no_dependents : 1,
44-
atomic : 1;
44+
atomic : 1,
45+
object_format : 1;
46+
const struct git_hash_algo *hash_algo;
4547
};
4648
static struct options options;
4749
static struct string_list cas_options = STRING_LIST_INIT_DUP;
@@ -190,6 +192,16 @@ static int set_option(const char *name, const char *value)
190192
} else if (!strcmp(name, "filter")) {
191193
options.filter = xstrdup(value);
192194
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;
193205
} else {
194206
return 1 /* unsupported */;
195207
}
@@ -231,6 +243,7 @@ static struct ref *parse_git_refs(struct discovery *heads, int for_push)
231243
case protocol_v0:
232244
get_remote_heads(&reader, &list, for_push ? REF_NORMAL : 0,
233245
NULL, &heads->shallow);
246+
options.hash_algo = reader.hash_algo;
234247
break;
235248
case protocol_unknown_version:
236249
BUG("unknown protocol version");
@@ -509,6 +522,9 @@ static struct ref *get_refs(int for_push)
509522
static void output_refs(struct ref *refs)
510523
{
511524
struct ref *posn;
525+
if (options.object_format && options.hash_algo) {
526+
printf(":object-format %s\n", options.hash_algo->name);
527+
}
512528
for (posn = refs; posn; posn = posn->next) {
513529
if (posn->symref)
514530
printf("@%s %s\n", posn->symref, posn->name);
@@ -1439,6 +1455,7 @@ int cmd_main(int argc, const char **argv)
14391455
printf("option\n");
14401456
printf("push\n");
14411457
printf("check-connectivity\n");
1458+
printf("object-format\n");
14421459
printf("\n");
14431460
fflush(stdout);
14441461
} else if (skip_prefix(buf.buf, "stateless-connect ", &arg)) {

0 commit comments

Comments
 (0)