Skip to content

Commit 8b85ee4

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

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

transport-helper.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ struct helper_data {
3232
signed_tags : 1,
3333
check_connectivity : 1,
3434
no_disconnect_req : 1,
35-
no_private_update : 1;
35+
no_private_update : 1,
36+
object_format : 1;
3637

3738
/*
3839
* As an optimization, the transport code may invoke fetch before
@@ -207,6 +208,8 @@ static struct child_process *get_helper(struct transport *transport)
207208
data->import_marks = xstrdup(arg);
208209
} else if (starts_with(capname, "no-private-update")) {
209210
data->no_private_update = 1;
211+
} else if (starts_with(capname, "object-format")) {
212+
data->object_format = 1;
210213
} else if (mandatory) {
211214
die(_("unknown mandatory capability %s; this remote "
212215
"helper probably needs newer version of Git"),
@@ -1103,6 +1106,12 @@ static struct ref *get_refs_list_using_list(struct transport *transport,
11031106
data->get_refs_list_called = 1;
11041107
helper = get_helper(transport);
11051108

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+
11061115
if (data->push && for_push)
11071116
write_str_in_full(helper->in, "list for-push\n");
11081117
else
@@ -1115,6 +1124,17 @@ static struct ref *get_refs_list_using_list(struct transport *transport,
11151124

11161125
if (!*buf.buf)
11171126
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+
}
11181138

11191139
eov = strchr(buf.buf, ' ');
11201140
if (!eov)
@@ -1127,7 +1147,7 @@ static struct ref *get_refs_list_using_list(struct transport *transport,
11271147
if (buf.buf[0] == '@')
11281148
(*tail)->symref = xstrdup(buf.buf + 1);
11291149
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);
11311151
if (eon) {
11321152
if (has_attribute(eon + 1, "unchanged")) {
11331153
(*tail)->status |= REF_STATUS_UPTODATE;

0 commit comments

Comments
 (0)