transport-helper: implement object-format extensions
Implement the object-format extensions that let us determine the hash algorithm in use when pushing or pulling data. 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
8b85ee4f47aadc23c8806bff5540baf819bbde95
1 file changed
+22
-2
transport-helper.c
+22
-2
@@ -32,7 +32,8 @@ struct helper_data {
32
signed_tags : 1,
33
check_connectivity : 1,
34
no_disconnect_req : 1,
35
- no_private_update : 1;
35
+ no_private_update : 1,
36
+ object_format : 1;
37
38
/*
39
* As an optimization, the transport code may invoke fetch before
@@ -207,6 +208,8 @@ static struct child_process *get_helper(struct transport *transport)
208
data->import_marks = xstrdup(arg);
209
} else if (starts_with(capname, "no-private-update")) {
210
data->no_private_update = 1;
211
+ } else if (starts_with(capname, "object-format")) {
212
+ data->object_format = 1;
213
} else if (mandatory) {
214
die(_("unknown mandatory capability %s; this remote "
215
"helper probably needs newer version of Git"),
@@ -1103,6 +1106,12 @@ static struct ref *get_refs_list_using_list(struct transport *transport,
1106
data->get_refs_list_called = 1;
1107
helper = get_helper(transport);
1108
1109
+ if (data->object_format) {
1110
+ write_str_in_full(helper->in, "option object-format\n");
1111
+ if (recvline(data, &buf) || strcmp(buf.buf, "ok"))
1112
+ exit(128);
1113
+ }
1114
+
1115
if (data->push && for_push)
1116
write_str_in_full(helper->in, "list for-push\n");
1117
else
@@ -1115,6 +1124,17 @@ static struct ref *get_refs_list_using_list(struct transport *transport,
1124
1125
if (!*buf.buf)
1126
break;
1127
+ else if (buf.buf[0] == ':') {
1128
+ const char *value;
1129
+ if (skip_prefix(buf.buf, ":object-format ", &value)) {
1130
+ int algo = hash_algo_by_name(value);
1131
+ if (algo == GIT_HASH_UNKNOWN)
1132
+ die(_("unsupported object format '%s'"),
1133
+ value);
1134
+ transport->hash_algo = &hash_algos[algo];
1135
+ }
1136
+ continue;
1137
+ }
1138
1139
eov = strchr(buf.buf, ' ');
1140
if (!eov)
@@ -1127,7 +1147,7 @@ static struct ref *get_refs_list_using_list(struct transport *transport,
1147
if (buf.buf[0] == '@')
1148
(*tail)->symref = xstrdup(buf.buf + 1);
1149
else if (buf.buf[0] != '?')
1130
- get_oid_hex(buf.buf, &(*tail)->old_oid);
1150
+ get_oid_hex_algop(buf.buf, &(*tail)->old_oid, transport->hash_algo);
1151
if (eon) {
1152
if (has_attribute(eon + 1, "unchanged")) {
1153
(*tail)->status |= REF_STATUS_UPTODATE;