git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 03/10] builtin: use default hash when outside a repository

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 20, 2025, 14:19 UTC
Message-ID
<xmqqikkq7awy.fsf@gitster.g>
In-Reply-To
<20250620011943.586596-4-sandals@crustytoothpaste.net>
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
Show 6 quoted lines
> 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.

Nicely explained and this step shows why having GIT_HASH_DEFAULT makes sense very well.

Show 117 quoted lines
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  builtin/apply.c       | 2 +-
>  builtin/diff.c        | 2 +-
>  builtin/hash-object.c | 2 +-
>  builtin/index-pack.c  | 2 +-
>  builtin/ls-remote.c   | 2 +-
>  builtin/patch-id.c    | 2 +-
>  builtin/shortlog.c    | 2 +-
>  builtin/show-index.c  | 2 +-
>  8 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/builtin/apply.c b/builtin/apply.c
> index a1e20c593d..d642a40251 100644
> --- a/builtin/apply.c
> +++ b/builtin/apply.c
> @@ -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,
> diff --git a/builtin/diff.c b/builtin/diff.c
> index c6231edce4..eebffe36cc 100644
> --- a/builtin/diff.c
> +++ b/builtin/diff.c
> @@ -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);
> diff --git a/builtin/hash-object.c b/builtin/hash-object.c
> index 6a99ec250d..213a302e05 100644
> --- a/builtin/hash-object.c
> +++ b/builtin/hash-object.c
> @@ -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);
> diff --git a/builtin/index-pack.c b/builtin/index-pack.c
> index bb7925bd29..352ce7f88a 100644
> --- a/builtin/index-pack.c
> +++ b/builtin/index-pack.c
> @@ -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) {
> diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
> index 01a4d4daa1..df09000b30 100644
> --- a/builtin/ls-remote.c
> +++ b/builtin/ls-remote.c
> @@ -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");
>  
> diff --git a/builtin/patch-id.c b/builtin/patch-id.c
> index cdef2ec10a..26f04b0335 100644
> --- a/builtin/patch-id.c
> +++ b/builtin/patch-id.c
> @@ -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);
> diff --git a/builtin/shortlog.c b/builtin/shortlog.c
> index fe15e11497..60adc5e7a5 100644
> --- a/builtin/shortlog.c
> +++ b/builtin/shortlog.c
> @@ -419,7 +419,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);
> diff --git a/builtin/show-index.c b/builtin/show-index.c
> index 9d4ecf5e7b..2c3e2940ce 100644
> --- a/builtin/show-index.c
> +++ b/builtin/show-index.c
> @@ -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;
>  
Previous: brian m. carlsonNext: Patrick Steinhardt
Message 4 of 47 in “Add SHA-256 by default as a breaking change”
  1. 00/10 Add SHA-256 by default as a breaking changebrian m. carlson, Jun 20, 2025
  2. 01/10 hash: add a constant for the default hash algorithmbrian m. carlson, Jun 20, 2025
  3. 03/10 builtin: use default hash when outside a repositorybrian m. carlson, Jun 20, 2025
  4. Junio C HamanoJun 20, 2025
  5. Patrick SteinhardtJul 1, 2025
  6. brian m. carlsonJul 1, 2025
  7. Patrick SteinhardtJul 2, 2025
  8. 04/10 Use original hash for legacy formatsbrian m. carlson, Jun 20, 2025
  9. Junio C HamanoJun 20, 2025
  10. brian m. carlsonJun 20, 2025
  11. Junio C HamanoJun 20, 2025
  12. Patrick SteinhardtJul 1, 2025
  13. 02/10 hash: add a constant for the original hash algorithmbrian m. carlson, Jun 20, 2025
  14. Junio C HamanoJun 20, 2025
  15. brian m. carlsonJun 20, 2025
  16. Patrick SteinhardtJul 1, 2025
  17. 05/10 setup: use the default algorithm to initialize repo formatbrian m. carlson, Jun 20, 2025
  18. Junio C HamanoJun 20, 2025
  19. brian m. carlsonJun 20, 2025
  20. Junio C HamanoJun 20, 2025
  21. 08/10 t4042: choose the built-in hash outside of a repobrian m. carlson, Jun 20, 2025
  22. 07/10 t1007: choose the built-in hash outside of a repobrian m. carlson, Jun 20, 2025
  23. 06/10 t: default to compile-time default hash if not setbrian m. carlson, Jun 20, 2025
  24. 09/10 t5300: choose the built-in hash outside of a repobrian m. carlson, Jun 20, 2025
  25. 10/10 Enable SHA-256 by default in breaking changes modebrian m. carlson, Jun 20, 2025
  26. Junio C HamanoJun 20, 2025
  27. brian m. carlsonJun 20, 2025
  28. Junio C HamanoJun 20, 2025
  29. brian m. carlsonJun 20, 2025
  30. Junio C HamanoJun 20, 2025
  31. brian m. carlsonJun 20, 2025
  32. Patrick SteinhardtJul 1, 2025
  33. 00/11 Add SHA-256 by default as a breaking changebrian m. carlson, Jul 1, 2025
  34. 02/11 hash: add a constant for the legacy hash algorithmbrian m. carlson, Jul 1, 2025
  35. 01/11 hash: add a constant for the default hash algorithmbrian m. carlson, Jul 1, 2025
  36. 04/11 Use legacy hash for legacy formatsbrian m. carlson, Jul 1, 2025
  37. 03/11 builtin: use default hash when outside a repositorybrian m. carlson, Jul 1, 2025
  38. 06/11 t: default to compile-time default hash if not setbrian m. carlson, Jul 1, 2025
  39. 05/11 setup: use the default algorithm to initialize repo formatbrian m. carlson, Jul 1, 2025
  40. 08/11 t4042: choose the built-in hash outside of a repobrian m. carlson, Jul 1, 2025
  41. 07/11 t1007: choose the built-in hash outside of a repobrian m. carlson, Jul 1, 2025
  42. 10/11 help: add a build option for default hashbrian m. carlson, Jul 1, 2025
  43. 11/11 Enable SHA-256 by default in breaking changes modebrian m. carlson, Jul 1, 2025
  44. 09/11 t5300: choose the built-in hash outside of a repobrian m. carlson, Jul 1, 2025
  45. Junio C HamanoJul 1, 2025
  46. Patrick SteinhardtJul 2, 2025
  47. Kristoffer HaugsbakkJul 2, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.