Skip to content

Commit 667d251

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dc9c16c commit 667d251

File tree

9 files changed

+13
-13
lines changed

9 files changed

+13
-13
lines changed

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ static struct command *read_head_info(struct packet_reader *reader,
21362136
use_push_options = 1;
21372137
hash = parse_feature_value(feature_list, "object-format", &len, NULL);
21382138
if (!hash) {
2139-
hash = hash_algos[GIT_HASH_SHA1].name;
2139+
hash = hash_algos[GIT_HASH_SHA1_LEGACY].name;
21402140
len = strlen(hash);
21412141
}
21422142
if (xstrncmpz(the_hash_algo->name, hash, len))

bundle.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int read_bundle_header_fd(int fd, struct bundle_header *header,
9595
* by an "object-format=" capability, which is being handled in
9696
* `parse_capability()`.
9797
*/
98-
header->hash_algo = &hash_algos[GIT_HASH_SHA1];
98+
header->hash_algo = &hash_algos[GIT_HASH_SHA1_LEGACY];
9999

100100
/* The bundle header ends with an empty line */
101101
while (!strbuf_getwholeline_fd(&buf, fd, '\n') &&
@@ -507,7 +507,7 @@ int create_bundle(struct repository *r, const char *path,
507507
* SHA1.
508508
* 2. @filter is required because we parsed an object filter.
509509
*/
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)
511511
min_version = 3;
512512

513513
if (argc > 1) {

connect.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ static void process_capabilities(struct packet_reader *reader, size_t *linelen)
251251
reader->hash_algo = &hash_algos[hash_algo];
252252
free(hash_name);
253253
} else {
254-
reader->hash_algo = &hash_algos[GIT_HASH_SHA1];
254+
reader->hash_algo = &hash_algos[GIT_HASH_SHA1_LEGACY];
255255
}
256256
}
257257

@@ -500,7 +500,7 @@ static void send_capabilities(int fd_out, struct packet_reader *reader)
500500
reader->hash_algo = &hash_algos[hash_algo];
501501
packet_write_fmt(fd_out, "object-format=%s", reader->hash_algo->name);
502502
} else {
503-
reader->hash_algo = &hash_algos[GIT_HASH_SHA1];
503+
reader->hash_algo = &hash_algos[GIT_HASH_SHA1_LEGACY];
504504
}
505505
if (server_feature_v2("promisor-remote", &promisor_remote_info)) {
506506
char *reply = promisor_remote_reply(promisor_remote_info);
@@ -665,7 +665,7 @@ int server_supports_hash(const char *desired, int *feature_supported)
665665
if (feature_supported)
666666
*feature_supported = !!hash;
667667
if (!hash) {
668-
hash = hash_algos[GIT_HASH_SHA1].name;
668+
hash = hash_algos[GIT_HASH_SHA1_LEGACY].name;
669669
len = strlen(hash);
670670
}
671671
while (hash) {

fetch-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ static void write_fetch_command_and_capabilities(struct strbuf *req_buf,
13421342
die(_("mismatched algorithms: client %s; server %s"),
13431343
the_hash_algo->name, hash_name);
13441344
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) {
13461346
die(_("the server does not support algorithm '%s'"),
13471347
the_hash_algo->name);
13481348
}

pkt-line.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ void packet_reader_init(struct packet_reader *reader, int fd,
617617
reader->buffer_size = sizeof(packet_buffer);
618618
reader->options = options;
619619
reader->me = "git";
620-
reader->hash_algo = &hash_algos[GIT_HASH_SHA1];
620+
reader->hash_algo = &hash_algos[GIT_HASH_SHA1_LEGACY];
621621
strbuf_init(&reader->scratch, 0);
622622
}
623623

remote-curl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static const struct git_hash_algo *detect_hash_algo(struct discovery *heads)
285285
* back to SHA1, which may or may not be correct.
286286
*/
287287
if (!p)
288-
return &hash_algos[GIT_HASH_SHA1];
288+
return &hash_algos[GIT_HASH_SHA1_LEGACY];
289289

290290
algo = hash_algo_by_length((p - heads->buf) / 2);
291291
if (algo == GIT_HASH_UNKNOWN)

serve.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
static int advertise_sid = -1;
1616
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;
1818

1919
static int always_advertise(struct repository *r UNUSED,
2020
struct strbuf *value UNUSED)

setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,11 +2222,11 @@ void initialize_repository_version(int hash_algo,
22222222
* version will get adjusted by git-clone(1) once it has learned about
22232223
* the remote repository's format.
22242224
*/
2225-
if (hash_algo != GIT_HASH_SHA1 ||
2225+
if (hash_algo != GIT_HASH_SHA1_LEGACY ||
22262226
ref_storage_format != REF_STORAGE_FORMAT_FILES)
22272227
target_version = GIT_REPO_VERSION_READ;
22282228

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)
22302230
git_config_set("extensions.objectformat",
22312231
hash_algos[hash_algo].name);
22322232
else if (reinit)

transport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
12431243
ret->smart_options->receivepack = remote->receivepack;
12441244
}
12451245

1246-
ret->hash_algo = &hash_algos[GIT_HASH_SHA1];
1246+
ret->hash_algo = &hash_algos[GIT_HASH_SHA1_LEGACY];
12471247

12481248
return ret;
12491249
}

0 commit comments

Comments
 (0)