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

Re: [PATCH v3] setup: fix hash algorithm detection

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 19, 2026, 16:38 UTC
Message-ID
<xmqqmrr4zsi2.fsf@gitster.g>
In-Reply-To
<20261119010612.687733-1-sandals@crustytoothpaste.net>
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
Show 5 quoted lines
> Our current hash algorithm selection code has a few different problems.
> First, we do not actually default to GIT_HASH_DEFAULT.  Second, if we
> have an algorithm chosen by init.defaultObjectFormat and we re-init a
> repository, we will change the hash algorithm, which is very much not
> desired.

Can we end the "first" sentence with a reason? We do not actually default to GIT_HASH_DEFAULT because we initialize a variable to SHA1_LEGACY and we do not consider it as "nowhere the user specifies which algorithm they want", or something?

Show 6 quoted lines
> Let's restructure this code slightly.  First, if an algorithm was
> selected on the command line, assume that's what the user wanted.
> Otherwise, the other options should only be chosen if our repository
> doesn't exist (that is, repo_fmt->version is -1) or it's specifically
> detected as having no hash algorithm.  In that case, first use the
> environment, then the config, and finally, the default algorithm.

In the current code, does "it's specifically having no hash algorithm" ever happen? Or is it our wish in near future to have such a state to allow "the first use determines the hash algorithm used" mode?

Show 8 quoted lines
> Then, if the algorithm does not match the repository, complain loudly
> and refuse to reinitialize the repository with a different hash
> algorithm.
>
> With this change, we will choose SHA-256 in breaking changes mode and in
> Git 3.0, which is what we want.  Add several tests to cover this case
> and several others discovered along the way.  Remove the now-inaccurate
> comment.
Is the comment "now inaccurate"?  
Show 5 quoted lines
> -	/*
> -	 * If we already have an initialized repo, don't allow the user to
> -	 * specify a different algorithm, as that could cause corruption.
> -	 * Otherwise, if the user has specified one on the command line, use it.
> -	 */

I think the first two lines is still relevant and serves as a caution to whoever will be mucking with this function in the future. The last sentence is not quite right in that following the user's wish is not limited to the command line instruction (if they tell us via an environment variable, we would honor it).

Oh, it just occured to me while I was writing the above parenthesized comment. If I have ~/.gitconfig that was modified via "git config set --global init.defaultObjectFormat sha256", would that count as "the user has specified"?

Thanks.
Previous: Junio C HamanoNext: brian m. carlson
Message 15 of 17 in “Default object format for new repositories in Git v3”
  1. Adam DinwoodieNov 6, 2026
  2. brian m. carlsonNov 6, 2026
  3. setup: default hash algo to GIT_HASH_DEFAULTbrian m. carlson, Nov 8, 2026
  4. Junio C HamanoNov 8, 2026
  5. brian m. carlsonNov 8, 2026
  6. Junio C HamanoNov 8, 2026
  7. Junio C HamanoNov 9, 2026
  8. Patrick SteinhardtNov 9, 2026
  9. setup: fix hash algorithm detectionbrian m. carlson, Nov 13, 2026
  10. Junio C HamanoNov 14, 2026
  11. Patrick SteinhardtNov 16, 2026
  12. setup: fix hash algorithm detectionbrian m. carlson, Nov 19, 2026
  13. Patrick SteinhardtNov 19, 2026
  14. Junio C HamanoNov 19, 2026
  15. Junio C HamanoNov 19, 2026
  16. brian m. carlsonNov 19, 2026
  17. Junio C HamanoNov 19, 2026

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.