Use legacy hash for legacy formats

We have a large variety of data formats and protocols where no hash algorithm was defined and the default was assumed to always be SHA-1. Instead of explicitly stating SHA-1, let's use the constant to represent the legacy hash algorithm (which is still SHA-1) so that it's clear for documentary purposes that it's a legacy fallback option and not an intentional choice to use SHA-1. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Jul 1, 2025 at 21:22 UTC 667d251a04c1dd769fb5a71bbe94d6d15ae594f1
9 files changed +13 -13
builtin/receive-pack.c
+1 -1
@@ -2136,7 +2136,7 @@ static struct command *read_head_info(struct packet_reader *reader,
2136 use_push_options = 1;
2137 hash = parse_feature_value(feature_list, "object-format", &len, NULL);
2138 if (!hash) {
2139 - hash = hash_algos[GIT_HASH_SHA1].name;
2139 + hash = hash_algos[GIT_HASH_SHA1_LEGACY].name;
2140 len = strlen(hash);
2141 }
2142 if (xstrncmpz(the_hash_algo->name, hash, len))
bundle.c
+2 -2
@@ -95,7 +95,7 @@ int read_bundle_header_fd(int fd, struct bundle_header *header,
95 * by an "object-format=" capability, which is being handled in
96 * `parse_capability()`.
97 */
98 - header->hash_algo = &hash_algos[GIT_HASH_SHA1];
98 + header->hash_algo = &hash_algos[GIT_HASH_SHA1_LEGACY];
99
100 /* The bundle header ends with an empty line */
101 while (!strbuf_getwholeline_fd(&buf, fd, '\n') &&
@@ -507,7 +507,7 @@ int create_bundle(struct repository *r, const char *path,
507 * SHA1.
508 * 2. @filter is required because we parsed an object filter.
509 */
510 - if (the_hash_algo != &hash_algos[GIT_HASH_SHA1] || revs.filter.choice)
510 + if (the_hash_algo != &hash_algos[GIT_HASH_SHA1_LEGACY] || revs.filter.choice)
511 min_version = 3;
512
513 if (argc > 1) {
connect.c
+3 -3
@@ -251,7 +251,7 @@ static void process_capabilities(struct packet_reader *reader, size_t *linelen)
251 reader->hash_algo = &hash_algos[hash_algo];
252 free(hash_name);
253 } else {
254 - reader->hash_algo = &hash_algos[GIT_HASH_SHA1];
254 + reader->hash_algo = &hash_algos[GIT_HASH_SHA1_LEGACY];
255 }
256 }
257
@@ -500,7 +500,7 @@ static void send_capabilities(int fd_out, struct packet_reader *reader)
500 reader->hash_algo = &hash_algos[hash_algo];
501 packet_write_fmt(fd_out, "object-format=%s", reader->hash_algo->name);
502 } else {
503 - reader->hash_algo = &hash_algos[GIT_HASH_SHA1];
503 + reader->hash_algo = &hash_algos[GIT_HASH_SHA1_LEGACY];
504 }
505 if (server_feature_v2("promisor-remote", &promisor_remote_info)) {
506 char *reply = promisor_remote_reply(promisor_remote_info);
@@ -665,7 +665,7 @@ int server_supports_hash(const char *desired, int *feature_supported)
665 if (feature_supported)
666 *feature_supported = !!hash;
667 if (!hash) {
668 - hash = hash_algos[GIT_HASH_SHA1].name;
668 + hash = hash_algos[GIT_HASH_SHA1_LEGACY].name;
669 len = strlen(hash);
670 }
671 while (hash) {
fetch-pack.c
+1 -1
@@ -1342,7 +1342,7 @@ static void write_fetch_command_and_capabilities(struct strbuf *req_buf,
1342 die(_("mismatched algorithms: client %s; server %s"),
1343 the_hash_algo->name, hash_name);
1344 packet_buf_write(req_buf, "object-format=%s", the_hash_algo->name);
1345 - } else if (hash_algo_by_ptr(the_hash_algo) != GIT_HASH_SHA1) {
1345 + } else if (hash_algo_by_ptr(the_hash_algo) != GIT_HASH_SHA1_LEGACY) {
1346 die(_("the server does not support algorithm '%s'"),
1347 the_hash_algo->name);
1348 }
pkt-line.c
+1 -1
@@ -617,7 +617,7 @@ void packet_reader_init(struct packet_reader *reader, int fd,
617 reader->buffer_size = sizeof(packet_buffer);
618 reader->options = options;
619 reader->me = "git";
620 - reader->hash_algo = &hash_algos[GIT_HASH_SHA1];
620 + reader->hash_algo = &hash_algos[GIT_HASH_SHA1_LEGACY];
621 strbuf_init(&reader->scratch, 0);
622 }
623
remote-curl.c
+1 -1
@@ -285,7 +285,7 @@ static const struct git_hash_algo *detect_hash_algo(struct discovery *heads)
285 * back to SHA1, which may or may not be correct.
286 */
287 if (!p)
288 - return &hash_algos[GIT_HASH_SHA1];
288 + return &hash_algos[GIT_HASH_SHA1_LEGACY];
289
290 algo = hash_algo_by_length((p - heads->buf) / 2);
291 if (algo == GIT_HASH_UNKNOWN)
serve.c
+1 -1
@@ -14,7 +14,7 @@
14
15 static int advertise_sid = -1;
16 static int advertise_object_info = -1;
17 -static int client_hash_algo = GIT_HASH_SHA1;
17 +static int client_hash_algo = GIT_HASH_SHA1_LEGACY;
18
19 static int always_advertise(struct repository *r UNUSED,
20 struct strbuf *value UNUSED)
setup.c
+2 -2
@@ -2222,11 +2222,11 @@ void initialize_repository_version(int hash_algo,
2222 * version will get adjusted by git-clone(1) once it has learned about
2223 * the remote repository's format.
2224 */
2225 - if (hash_algo != GIT_HASH_SHA1 ||
2225 + if (hash_algo != GIT_HASH_SHA1_LEGACY ||
2226 ref_storage_format != REF_STORAGE_FORMAT_FILES)
2227 target_version = GIT_REPO_VERSION_READ;
2228
2229 - if (hash_algo != GIT_HASH_SHA1 && hash_algo != GIT_HASH_UNKNOWN)
2229 + if (hash_algo != GIT_HASH_SHA1_LEGACY && hash_algo != GIT_HASH_UNKNOWN)
2230 git_config_set("extensions.objectformat",
2231 hash_algos[hash_algo].name);
2232 else if (reinit)
transport.c
+1 -1
@@ -1243,7 +1243,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
1243 ret->smart_options->receivepack = remote->receivepack;
1244 }
1245
1246 - ret->hash_algo = &hash_algos[GIT_HASH_SHA1];
1246 + ret->hash_algo = &hash_algos[GIT_HASH_SHA1_LEGACY];
1247
1248 return ret;
1249 }