]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin: use default hash when outside a repository
authorbrian m. carlson <sandals@crustytoothpaste.net>
Fri, 20 Jun 2025 01:19:35 +0000 (01:19 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Jun 2025 14:17:35 +0000 (07:17 -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 a1e20c593d09032dcb016b15556f43f7694213b3..d642a402516f30ccbd84a573ea09ae297734c919 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 fa963808c31848efac822181619f651647966fba..357702df9efcb7f7fe06848b7708d3f7d8e10e85 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 6a99ec250d028fd39dcba912993722a8b686126f..213a302e05bd288eaf4889b5e987dd9e0902856d 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 bb7925bd29f0aa407c8073718ca871d97d138040..352ce7f88ae0ec4c00099c4579a7583a41092f83 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 01a4d4daa1faba2089b54cc245ba2bb7560dc99b..df09000b30de50e4a124d1928472780c3b62e8ff 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 cdef2ec10abcd595fc4c2425c4883a5188f526b5..26f04b0335da7e3a5d4da6ab0eb4f216f10d4793 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 30075b67be8dac2db7aba793a818f357c7c11cc1..795a6316257ce4f960032e597e437935b1194fbf 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 9d4ecf5e7ba0106985c8f0919e03fffb3a629ddb..2c3e2940ce6bb18571795e4c765438e8101bacdc 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;