Skip to content

Commit dc9c16c

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

File tree

8 files changed

+8
-8
lines changed

8 files changed

+8
-8
lines changed

builtin/apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ int cmd_apply(int argc,
2929
* cf. https://lore.kernel.org/git/[email protected]/
3030
*/
3131
if (!the_hash_algo)
32-
repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
32+
repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
3333

3434
argc = apply_parse_options(argc, argv,
3535
&state, &force_apply, &options,

builtin/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ int cmd_diff(int argc,
483483
* configurable via a command line option.
484484
*/
485485
if (nongit)
486-
repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
486+
repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
487487

488488
init_diff_ui_defaults();
489489
git_config(git_diff_ui_config, NULL);

builtin/hash-object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int cmd_hash_object(int argc,
104104
prefix = setup_git_directory_gently(&nongit);
105105

106106
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);
108108

109109
if (vpath && prefix) {
110110
vpath_free = prefix_filename(prefix, vpath);

builtin/index-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@ int cmd_index_pack(int argc,
20342034
* choice but to guess the object hash.
20352035
*/
20362036
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);
20382038

20392039
opts.flags &= ~(WRITE_REV | WRITE_REV_VERIFY);
20402040
if (rev_index) {

builtin/ls-remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int cmd_ls_remote(int argc,
112112
* depending on what object hash the remote uses.
113113
*/
114114
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);
116116

117117
packet_trace_identity("ls-remote");
118118

builtin/patch-id.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ int cmd_patch_id(int argc,
254254
* the code that computes patch IDs to always use SHA1.
255255
*/
256256
if (!the_hash_algo)
257-
repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
257+
repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
258258

259259
generate_id_list(opts ? opts > 1 : config.stable,
260260
opts ? opts == 3 : config.verbatim);

builtin/shortlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ int cmd_shortlog(int argc,
418418
* git/nongit so that we do not have to do this.
419419
*/
420420
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);
422422

423423
git_config(git_default_config, NULL);
424424
shortlog_init(&log);

builtin/show-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int cmd_show_index(int argc,
4747
* the index file passed in and use that instead.
4848
*/
4949
if (!the_hash_algo)
50-
repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
50+
repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
5151

5252
hashsz = the_hash_algo->rawsz;
5353

0 commit comments

Comments
 (0)