From: brian m. carlson Date: Fri, 20 Jun 2025 01:19:37 +0000 (+0000) Subject: setup: use the default algorithm to initialize repo format X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d27e4ee557de37841e8898452c15faa6abf61c7f;p=thirdparty%2Fgit.git setup: use the default algorithm to initialize repo format When we define a new repository format with REPOSITORY_FORMAT_INIT, we always use GIT_HASH_SHA1, and this value ends up getting used as the default value to initialize a repository if none of the command line, environment, or config tell us to do otherwise. Because we might not always want to use SHA-1 as the default, let's instead specify the default hash algorithm constant so that we will use whatever the specified default is. However, to make sure we continue to read repositories without a specified hash algorithm as SHA-1, default the repository format to the original hash algorithm (SHA-1) when reading the repository format. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- diff --git a/setup.c b/setup.c index 641c857ed5..fb38824a2b 100644 --- a/setup.c +++ b/setup.c @@ -835,9 +835,12 @@ static void init_repository_format(struct repository_format *format) int read_repository_format(struct repository_format *format, const char *path) { clear_repository_format(format); + format->hash_algo = GIT_HASH_ORIGINAL; git_config_from_file(check_repo_format, path, format); - if (format->version == -1) + if (format->version == -1) { clear_repository_format(format); + format->hash_algo = GIT_HASH_ORIGINAL; + } return format->version; } diff --git a/setup.h b/setup.h index 18dc3b7368..8522fa8575 100644 --- a/setup.h +++ b/setup.h @@ -149,7 +149,7 @@ struct repository_format { { \ .version = -1, \ .is_bare = -1, \ - .hash_algo = GIT_HASH_SHA1, \ + .hash_algo = GIT_HASH_DEFAULT, \ .ref_storage_format = REF_STORAGE_FORMAT_FILES, \ .unknown_extensions = STRING_LIST_INIT_DUP, \ .v1_only_extensions = STRING_LIST_INIT_DUP, \