builtin: use default hash when outside a repository
We have some commands that can operate inside or outside a repository. If we're operating outside a repository, we clearly cannot use the repository's hash algorithm as a default since it doesn't exist, so instead, let's pick the default instead of specifically SHA-1. Right now this results in no functional change since the default is SHA-1, but that may change in the future. 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
dc9c16c2fc8222364277696cb4d70782281d3c06
8 files changed
+8
-8
builtin/apply.c
+1
-1
@@ -29,7 +29,7 @@ int cmd_apply(int argc,
29
* cf. https://lore.kernel.org/git/xmqqcypfcmn4.fsf@gitster.g/
30
*/
31
if (!the_hash_algo)
32
- repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
32
+ repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
33
34
argc = apply_parse_options(argc, argv,
35
&state, &force_apply, &options,
builtin/diff.c
+1
-1
@@ -483,7 +483,7 @@ int cmd_diff(int argc,
483
* configurable via a command line option.
484
*/
485
if (nongit)
486
- repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
486
+ repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
487
488
init_diff_ui_defaults();
489
git_config(git_diff_ui_config, NULL);
builtin/hash-object.c
+1
-1
@@ -104,7 +104,7 @@ int cmd_hash_object(int argc,
104
prefix = setup_git_directory_gently(&nongit);
105
106
if (nongit && !the_hash_algo)
107
- repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
107
+ repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
108
109
if (vpath && prefix) {
110
vpath_free = prefix_filename(prefix, vpath);
builtin/index-pack.c
+1
-1
@@ -2034,7 +2034,7 @@ int cmd_index_pack(int argc,
2034
* choice but to guess the object hash.
2035
*/
2036
if (!the_repository->hash_algo)
2037
- repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
2037
+ repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
2038
2039
opts.flags &= ~(WRITE_REV | WRITE_REV_VERIFY);
2040
if (rev_index) {
builtin/ls-remote.c
+1
-1
@@ -112,7 +112,7 @@ int cmd_ls_remote(int argc,
112
* depending on what object hash the remote uses.
113
*/
114
if (!the_repository->hash_algo)
115
- repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
115
+ repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
116
117
packet_trace_identity("ls-remote");
118
builtin/patch-id.c
+1
-1
@@ -254,7 +254,7 @@ int cmd_patch_id(int argc,
254
* the code that computes patch IDs to always use SHA1.
255
*/
256
if (!the_hash_algo)
257
- repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
257
+ repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
258
259
generate_id_list(opts ? opts > 1 : config.stable,
260
opts ? opts == 3 : config.verbatim);
builtin/shortlog.c
+1
-1
@@ -418,7 +418,7 @@ int cmd_shortlog(int argc,
418
* git/nongit so that we do not have to do this.
419
*/
420
if (nongit && !the_hash_algo)
421
- repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
421
+ repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
422
423
git_config(git_default_config, NULL);
424
shortlog_init(&log);
builtin/show-index.c
+1
-1
@@ -47,7 +47,7 @@ int cmd_show_index(int argc,
47
* the index file passed in and use that instead.
48
*/
49
if (!the_hash_algo)
50
- repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
50
+ repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
51
52
hashsz = the_hash_algo->rawsz;
53