Git fork

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>

authored by

brian m. carlson and committed by
Junio C Hamano
dc9c16c2 1f68f3da

+8 -8
+1 -1
builtin/apply.c
··· 29 29 * cf. https://lore.kernel.org/git/xmqqcypfcmn4.fsf@gitster.g/ 30 30 */ 31 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 33 34 34 argc = apply_parse_options(argc, argv, 35 35 &state, &force_apply, &options,
+1 -1
builtin/diff.c
··· 483 483 * configurable via a command line option. 484 484 */ 485 485 if (nongit) 486 - repo_set_hash_algo(the_repository, GIT_HASH_SHA1); 486 + repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT); 487 487 488 488 init_diff_ui_defaults(); 489 489 git_config(git_diff_ui_config, NULL);
+1 -1
builtin/hash-object.c
··· 104 104 prefix = setup_git_directory_gently(&nongit); 105 105 106 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 108 109 109 if (vpath && prefix) { 110 110 vpath_free = prefix_filename(prefix, vpath);
+1 -1
builtin/index-pack.c
··· 2034 2034 * choice but to guess the object hash. 2035 2035 */ 2036 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 2038 2039 2039 opts.flags &= ~(WRITE_REV | WRITE_REV_VERIFY); 2040 2040 if (rev_index) {
+1 -1
builtin/ls-remote.c
··· 112 112 * depending on what object hash the remote uses. 113 113 */ 114 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 116 117 117 packet_trace_identity("ls-remote"); 118 118
+1 -1
builtin/patch-id.c
··· 254 254 * the code that computes patch IDs to always use SHA1. 255 255 */ 256 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 258 259 259 generate_id_list(opts ? opts > 1 : config.stable, 260 260 opts ? opts == 3 : config.verbatim);
+1 -1
builtin/shortlog.c
··· 418 418 * git/nongit so that we do not have to do this. 419 419 */ 420 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 422 423 423 git_config(git_default_config, NULL); 424 424 shortlog_init(&log);
+1 -1
builtin/show-index.c
··· 47 47 * the index file passed in and use that instead. 48 48 */ 49 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 51 52 52 hashsz = the_hash_algo->rawsz; 53 53