Merge branch 'bc/sha-256-part-2' into jch
SHA-256 migration work continues. * bc/sha-256-part-2: (44 commits) remote-testgit: adapt for object-format bundle: detect hash algorithm when reading refs t5300: pass --object-format to git index-pack t5704: send object-format capability with SHA-256 t5703: use object-format serve option t5702: offer an object-format capability in the test t/helper: initialize the repository for test-sha1-array remote-curl: avoid truncating refs with ls-remote t1050: pass algorithm to index-pack when outside repo builtin/index-pack: add option to specify hash algorithm remote-curl: detect algorithm for dumb HTTP by size builtin/ls-remote: initialize repository based on fetch t5500: make hash independent serve: advertise object-format capability for protocol v2 connect: parse v2 refs with correct hash algorithm connect: pass full packet reader when parsing v2 refs Documentation/technical: document object-format for protocol v2 t1302: expect repo format version 1 for SHA-256 builtin/show-index: provide options to determine hash algo t5302: modernize test formatting ...
This commit is contained in:
@ -41,7 +41,9 @@ struct options {
|
||||
deepen_relative : 1,
|
||||
from_promisor : 1,
|
||||
no_dependents : 1,
|
||||
atomic : 1;
|
||||
atomic : 1,
|
||||
object_format : 1;
|
||||
const struct git_hash_algo *hash_algo;
|
||||
};
|
||||
static struct options options;
|
||||
static struct string_list cas_options = STRING_LIST_INIT_DUP;
|
||||
@ -190,6 +192,16 @@ static int set_option(const char *name, const char *value)
|
||||
} else if (!strcmp(name, "filter")) {
|
||||
options.filter = xstrdup(value);
|
||||
return 0;
|
||||
} else if (!strcmp(name, "object-format")) {
|
||||
int algo;
|
||||
options.object_format = 1;
|
||||
if (strcmp(value, "true")) {
|
||||
algo = hash_algo_by_name(value);
|
||||
if (algo == GIT_HASH_UNKNOWN)
|
||||
die("unknown object format '%s'", value);
|
||||
options.hash_algo = &hash_algos[algo];
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
return 1 /* unsupported */;
|
||||
}
|
||||
@ -231,6 +243,7 @@ static struct ref *parse_git_refs(struct discovery *heads, int for_push)
|
||||
case protocol_v0:
|
||||
get_remote_heads(&reader, &list, for_push ? REF_NORMAL : 0,
|
||||
NULL, &heads->shallow);
|
||||
options.hash_algo = reader.hash_algo;
|
||||
break;
|
||||
case protocol_unknown_version:
|
||||
BUG("unknown protocol version");
|
||||
@ -239,6 +252,19 @@ static struct ref *parse_git_refs(struct discovery *heads, int for_push)
|
||||
return list;
|
||||
}
|
||||
|
||||
static const struct git_hash_algo *detect_hash_algo(struct discovery *heads)
|
||||
{
|
||||
const char *p = memchr(heads->buf, '\t', heads->len);
|
||||
int algo;
|
||||
if (!p)
|
||||
return the_hash_algo;
|
||||
|
||||
algo = hash_algo_by_length((p - heads->buf) / 2);
|
||||
if (algo == GIT_HASH_UNKNOWN)
|
||||
return NULL;
|
||||
return &hash_algos[algo];
|
||||
}
|
||||
|
||||
static struct ref *parse_info_refs(struct discovery *heads)
|
||||
{
|
||||
char *data, *start, *mid;
|
||||
@ -249,6 +275,12 @@ static struct ref *parse_info_refs(struct discovery *heads)
|
||||
struct ref *ref = NULL;
|
||||
struct ref *last_ref = NULL;
|
||||
|
||||
options.hash_algo = detect_hash_algo(heads);
|
||||
if (!options.hash_algo)
|
||||
die("%sinfo/refs not valid: could not determine hash algorithm; "
|
||||
"is this a git repository?",
|
||||
transport_anonymize_url(url.buf));
|
||||
|
||||
data = heads->buf;
|
||||
start = NULL;
|
||||
mid = data;
|
||||
@ -259,13 +291,13 @@ static struct ref *parse_info_refs(struct discovery *heads)
|
||||
if (data[i] == '\t')
|
||||
mid = &data[i];
|
||||
if (data[i] == '\n') {
|
||||
if (mid - start != the_hash_algo->hexsz)
|
||||
if (mid - start != options.hash_algo->hexsz)
|
||||
die(_("%sinfo/refs not valid: is this a git repository?"),
|
||||
transport_anonymize_url(url.buf));
|
||||
data[i] = 0;
|
||||
ref_name = mid + 1;
|
||||
ref = alloc_ref(ref_name);
|
||||
get_oid_hex(start, &ref->old_oid);
|
||||
get_oid_hex_algop(start, &ref->old_oid, options.hash_algo);
|
||||
if (!refs)
|
||||
refs = ref;
|
||||
if (last_ref)
|
||||
@ -509,11 +541,16 @@ static struct ref *get_refs(int for_push)
|
||||
static void output_refs(struct ref *refs)
|
||||
{
|
||||
struct ref *posn;
|
||||
if (options.object_format && options.hash_algo) {
|
||||
printf(":object-format %s\n", options.hash_algo->name);
|
||||
}
|
||||
for (posn = refs; posn; posn = posn->next) {
|
||||
if (posn->symref)
|
||||
printf("@%s %s\n", posn->symref, posn->name);
|
||||
else
|
||||
printf("%s %s\n", oid_to_hex(&posn->old_oid), posn->name);
|
||||
printf("%s %s\n", hash_to_hex_algop(posn->old_oid.hash,
|
||||
options.hash_algo),
|
||||
posn->name);
|
||||
}
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
@ -1499,6 +1536,7 @@ int cmd_main(int argc, const char **argv)
|
||||
printf("option\n");
|
||||
printf("push\n");
|
||||
printf("check-connectivity\n");
|
||||
printf("object-format\n");
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
} else if (skip_prefix(buf.buf, "stateless-connect ", &arg)) {
|
||||
|
Reference in New Issue
Block a user