Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-07-07 08:09:13 +0300
committerJunio C Hamano <gitster@pobox.com>2020-07-07 08:09:13 +0300
commit12210859da0c16c644dab658d9e1ef671ec28788 (patch)
treee8035e6e8412b45972e8836399f531c6379313f8 /remote-curl.c
parenta08a83db2bf27f015bec9a435f6d73e223c21c5e (diff)
parent3716d50dd5c8ee7e5ccaa89fcbfff2cd1b82ad1d (diff)
Merge branch 'bc/sha-256-part-2'
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 ...
Diffstat (limited to 'remote-curl.c')
-rw-r--r--remote-curl.c46
1 files changed, 42 insertions, 4 deletions
diff --git a/remote-curl.c b/remote-curl.c
index 75532a8bae..5cbc6e5002 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -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)) {