On 2026-11-19 at 16:38:13, Junio C Hamano wrote: > "brian m. carlson" 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? I can expand on that. > > 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? It should not as far as I can tell, but we have a bunch of different cases, including the clone case, and I'm not 100% sure if that actually ever happens. > > - /* > > - * 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"? I'll rewrite the comment. The "user has specified one on the command line" means with `--object-format`, but the user could specify one with `init.defaultObjectFormat`. The difference is we scream if the former mismatches with the repository, whereas if the repository is already initialized, we ignore `GIT_DEFAULT_HASH` and `init.defaultObjectFormat`. -- brian m. carlson (they/them) Toronto, Ontario, CA Speaking for myself only