]> Kevux Git Server - rit/commitdiff
builtin: use default hash when outside a repository
authorbrian m. carlson <sandals@crustytoothpaste.net>
Tue, 1 Jul 2025 21:22:29 +0000 (21:22 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 1 Jul 2025 21:58:24 +0000 (14:58 -0700)
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>
builtin/apply.c
builtin/diff.c
builtin/hash-object.c
builtin/index-pack.c
builtin/ls-remote.c
builtin/patch-id.c
builtin/shortlog.c
builtin/show-index.c

index a1e20c5..d642a40 100644 (file)
@@ -29,7 +29,7 @@ int cmd_apply(int argc,
         * cf. https://lore.kernel.org/git/xmqqcypfcmn4.fsf@gitster.g/
         */
        if (!the_hash_algo)
-               repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+               repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
 
        argc = apply_parse_options(argc, argv,
                                   &state, &force_apply, &options,
index fa96380..357702d 100644 (file)
@@ -483,7 +483,7 @@ int cmd_diff(int argc,
         * configurable via a command line option.
         */
        if (nongit)
-               repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+               repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
 
        init_diff_ui_defaults();
        git_config(git_diff_ui_config, NULL);
index 6a99ec2..213a302 100644 (file)
@@ -104,7 +104,7 @@ int cmd_hash_object(int argc,
                prefix = setup_git_directory_gently(&nongit);
 
        if (nongit && !the_hash_algo)
-               repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+               repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
 
        if (vpath && prefix) {
                vpath_free = prefix_filename(prefix, vpath);
index bb7925b..352ce7f 100644 (file)
@@ -2034,7 +2034,7 @@ int cmd_index_pack(int argc,
         * choice but to guess the object hash.
         */
        if (!the_repository->hash_algo)
-               repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+               repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
 
        opts.flags &= ~(WRITE_REV | WRITE_REV_VERIFY);
        if (rev_index) {
index 01a4d4d..df09000 100644 (file)
@@ -112,7 +112,7 @@ int cmd_ls_remote(int argc,
         * depending on what object hash the remote uses.
         */
        if (!the_repository->hash_algo)
-               repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+               repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
 
        packet_trace_identity("ls-remote");
 
index cdef2ec..26f04b0 100644 (file)
@@ -254,7 +254,7 @@ int cmd_patch_id(int argc,
         * the code that computes patch IDs to always use SHA1.
         */
        if (!the_hash_algo)
-               repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+               repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
 
        generate_id_list(opts ? opts > 1 : config.stable,
                         opts ? opts == 3 : config.verbatim);
index 30075b6..795a631 100644 (file)
@@ -418,7 +418,7 @@ int cmd_shortlog(int argc,
         * git/nongit so that we do not have to do this.
         */
        if (nongit && !the_hash_algo)
-               repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+               repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
 
        git_config(git_default_config, NULL);
        shortlog_init(&log);
index 9d4ecf5..2c3e294 100644 (file)
@@ -47,7 +47,7 @@ int cmd_show_index(int argc,
         *       the index file passed in and use that instead.
         */
        if (!the_hash_algo)
-               repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+               repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
 
        hashsz = the_hash_algo->rawsz;