Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "brian m. carlson" <sandals@crustytoothpaste.net>
Cc: <git@vger.kernel.org>,  Patrick Steinhardt <ps@pks.im>,
	 Adam Dinwoodie <adam@dinwoodie.org>
Subject: Re: [PATCH v3] setup: fix hash algorithm detection
Date: Thu, 19 Nov 2026 08:38:13 -0800	[thread overview]
Message-ID: <xmqqmrr4zsi2.fsf@gitster.g> (raw)
In-Reply-To: <20261119010612.687733-1-sandals@crustytoothpaste.net> (brian m. carlson's message of "Thu, 19 Nov 2026 01:06:12 +0000")

"brian m. carlson" <sandals@crustytoothpaste.net> writes:

> 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?

> 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?

> 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"?  

> -	/*
> -	 * 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.

      parent reply	other threads:[~2026-11-19 16:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 16:50 Default object format for new repositories in Git v3 Adam Dinwoodie
2026-11-06 20:46 ` brian m. carlson
2026-11-08  1:16 ` [PATCH] setup: default hash algo to GIT_HASH_DEFAULT brian m. carlson
2026-11-08  4:42   ` Junio C Hamano
2026-11-08 14:38     ` brian m. carlson
2026-11-08 18:22   ` Junio C Hamano
2026-11-09  2:21     ` Junio C Hamano
2026-11-09  9:54       ` Patrick Steinhardt
2026-11-13 22:17   ` [PATCH v2] setup: fix hash algorithm detection brian m. carlson
2026-11-14  0:16     ` Junio C Hamano
2026-11-16  6:22     ` Patrick Steinhardt
2026-11-19  1:06   ` [PATCH v3] " brian m. carlson
2026-11-19  9:52     ` Patrick Steinhardt
2026-11-19 16:26     ` Junio C Hamano
2026-11-19 16:38     ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqmrr4zsi2.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=adam@dinwoodie.org \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox