🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #3402

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

#3402
From: Junio C Hamano
Date: Thu, 19 Nov 2026 16:38
55 lines
15040 bytes
"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.
Technical Details
Message-ID: <xmqqmrr4zsi2.fsf@gitster.g>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-75850-linux-kernel-git=dewy.ru
References: <20261108011633.1772000-1-sandals@crustytoothpaste.net> <20261119010612.687733-1-sandals@crustytoothpaste.net>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-75850-linux-kernel-git=dewy.ru
From: gitster@pobox.com (Junio C Hamano)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v3] setup: fix hash algorithm detection
Date: Thu, 19 Nov 2026 08:38:13 -0800
Organization: Usenet Network
Message-ID: <xmqqmrr4zsi2.fsf@gitster.g>
References: <20261108011633.1772000-1-sandals@crustytoothpaste.net>
	<20261119010612.687733-1-sandals@crustytoothpaste.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: usenet.network;
	logging-data="2928284"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:zufwb+Baf9rCcT9eKZMQ7ERsXS8= sha256:y3AlQ/gsPIg3tsNIY0rKxT/71CsCDB8aPed0xWrSwE4=
	sha1:COLVx16t+Wi+thV6KKd8yivddVM= sha256:x47z3VsB1uBup3Kn6mtmvphXqDn/KBReOMW1BGaTA1o=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 94C7F1156E6; Thu, 19 Nov 2026 19:38:53 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.051
X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=pobox.com header.b=JuDBeXoo; dkim=pass (2048-bit key)
	header.d=messagingengine.com header.b=dpc/SI6g
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 5F4x8DLDyLak;
	Thu, 19 Nov 2026 19:38:49 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=git+bounces-75850-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=pobox.com
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 2E2F31156BA; Thu, 19 Nov 2026 19:38:33 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id DC1011A456E; Thu, 19 Nov 2026 16:38:23 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795106302;
	b=QLah7C19lxWVWUTDa3Hy6E3TzYPIf2VjebiVxefsYOt9qglFynTmFz2qeE0ql7o5/Jy1
	 HmY3INY526CN+4MprGlyKgTmcD9WhaA76h9/IRA4b8gZIcPyf7M2SdQBLV5ahSIAGADjV
	 42VO7fmGevoDLyFuhc4PwYbPPs2a7/fGL2ajEHxoidg0zTTTAMZYA6Y1KpMDY560HpIYC
	 2Xvqzi3rQrWttFhrgVe9HrJKjoyL5koRp9jwuDLbblvfZmqKzWhGmIMCPjR0Oa7tZILbA
	 7P65hzJ7ZlGzz2MP9tvxU2SxZauqPR3fI0qqoTu+6ZjyoQmoGKD5mOKz5fRFqZaPxHw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795106302;
	h=X-Original-To:Received:DMARC-Filter:Received:Received:DKIM-Signature:
	 DKIM-Signature:X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:
	 Message-Instance:X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:
	 X-ME-Proxy:Feedback-ID:Received:From:To:Cc:Subject:In-Reply-To:
	 References:Date:Message-ID:User-Agent:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Type;
	bh=Rt7nHHIV85ufBCsQGjDmEVmcDretztNyuDDuXuYtOME=;
	b=qpO4igfQSne0tJVUm1JkIGxg5QaJmiWKaaBOT8TtWTG608D4V6ivXclmg1ApZ1lH44Fa
	 +nXpGL0SN8zIXbsqzTv6+csQfbBz4CrbnNwyps1JJCTPtEduqqY6a1Wp0UUhk8N+TM5ke
	 9ZKnWNq8IS4qybpa2MCxYzfJfLzoFyrGtneusqumnBZLZ4gbQcxmv+Gd7kJiX0cpEJxjl
	 97cnzgphHE2uGxsHh1EXpSbZTMd6CjisskUwT3OxeT3kY2kR3/g5YCZkW+FOdSfCbB1n3
	 uZ4mym3eVF6a5gdn/GBCiaGvfk5ICJfd258bLD2uPQFte/1oAwor0mC7QsGrHIq3uJQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm2 header.b=JuDBeXoo;
	dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b="dpc/SI6g";
	dmarc=pass header.from=pobox.com;
	spf=pass smtp.mailfrom=pobox.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id B0E93606A330;
	Thu, 19 Nov 2026 16:38:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm2 header.b=JuDBeXoo;
	dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=dpc/SI6g
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=202.12.124.152
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795106296;
	b=rRrEHFv/14Ol7lNaymmXs+hYtxh2MbbH4DX33N1WdHLMELLYKiCZUyF9OnyIyKIwLr6n
	 u+iFad1MJyqLoCsWwctyr3IT7OI0ew6mfZDIcp2W6lpjSDVNZxmKXhAoHf/qJGCNTfdik
	 GRbUoK/at9WPTbSNpVuG4QlOQjaYdtGGOVxoNBC/mW8nNhJ4Xgh9AKeDGY3MrAeeSnNY3
	 IeHbwymIMIgQn8oLre1lx5f+3Gtkr9VReoqvnY3o5W34/g3zuX74K0iV5U/ALNPafnfwf
	 lCbZ8OnodnQPZnzQ/Hc5/rrXrxACyS2yPJY4xYDQz/5DAzAeU2erGKsmmcNBiB1ldiw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795106296;
	h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature:
	 X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance:
	 X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID:
	 Received:From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:
	 User-Agent:MIME-Version:Content-Type;
	bh=Rt7nHHIV85ufBCsQGjDmEVmcDretztNyuDDuXuYtOME=;
	b=zrnRyHGA/kd9kWzVs4xRtjgiJKjAKcf7Sl9fw1O+d3miRutDm/vIfp/sD1oIWoa+Ejnc
	 s20I7yFWAqEPSrxdxPL/LTCmHz4DooPLWrbTFi444khk9fu89peX/vuG0pmxtGA0O27Fo
	 l92IiuZ2HyTI2UozkK4aPBUDsgnVhYRaD40ETBrfOH1NfEn/+chnANE10zgV4G+Qxam06
	 pXetPhHxq+B76s26UvvuigqOYL9EFCAS9IJc8w5/E/yJl5IovZxwD6laRX/PHAvTdR+8r
	 VMRSEkNu675/gQWZ+nTwn06haVoHmTislG6RPoSqNjo2AsRC2zPOFsJrq8yvyWzy2bw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=pobox.com;
	spf=pass smtp.mailfrom=pobox.com;
	dkim=pass header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm2 header.b=JuDBeXoo;
	dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b="dpc/SI6g";
	arc=none smtp.remote-ip=202.12.124.152
X-Received: from fhigh-b1-smtp.messagingengine.com (fhigh-b1-smtp.messagingengine.com [202.12.124.152])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BE83606A320
	for <git@vger.kernel.org>; Thu, 19 Nov 2026 16:38:16 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7BE83606A320
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com
X-Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41])
	by mailfhigh.stl.internal (Postfix) with ESMTP id 8B5187A02F2
	for <git@vger.kernel.org>; Thu, 19 Nov 2026 11:38:15 -0500 (EST)
X-Received: from phl-frontend-02 ([10.202.2.161])
  by phl-compute-01.internal (MEProxy); Thu, 19 Nov 2026 11:38:15 -0500
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc
	:cc:content-type:content-type:date:date:from:from:in-reply-to
	:in-reply-to:message-id:mime-version:references:reply-to:subject
	:subject:to:to; s=fm2; t=1795106295; x=1795192695; bh=Rt7nHHIV85
	ufBCsQGjDmEVmcDretztNyuDDuXuYtOME=; b=JuDBeXoo+EG6E2r3v7UAv+gAMh
	XdrbykTrKWo2sLJtseAmMtvSGZ7mXfbrSxgsjCiJ3GueNcihN7GNWt88qosi86QI
	755C2peGpce/RmIFxvcY1+i5F/omAgqD9Acj01qz18pihHzzr5eU42UeYVNKHmJV
	G2Mw6soWtDvGqnFW6e3rKr9A9zJ9ppe1lI9qh5gYPizdQ4sq3O1toyE0SxyI/tyX
	tO8qj9aEYbw3+AHUEjHe/fcQB8u8CC7zvGCNyduihj+zgB7rjVRIqh/YLEBONHtQ
	DnPTaxdG5vODABsFTUQM5VI9jHfNBvTavBWvnCDfp/GGgem2J7spUARVM8vg==
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
	messagingengine.com; h=cc:cc:content-type:content-type:date:date
	:feedback-id:feedback-id:from:from:in-reply-to:in-reply-to
	:message-id:mime-version:references:reply-to:subject:subject:to
	:to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=
	1795106295; x=1795192695; bh=Rt7nHHIV85ufBCsQGjDmEVmcDretztNyuDD
	uXuYtOME=; b=dpc/SI6grxEH/hINcQWhGLkcUMrCmXGkV4rSVNZYV3RzgyWEjVl
	8hUto81cjHBJgpNkP5WjXQZCJjpRIn8UaUxFjORcCzPpiesmKlS2rnHI5rLf/SG4
	7lUt+S8EJ51Dpqf3ISUVBagzSZ04Kn6H5T7uvdvNbxyZyHv3JPsDxcIhu0c8YGHj
	/gF9GwAzY49wShQTaVkR64LOLB4GFs1UP+gGlC9UCRlQNr9f2LGy92QDmpATz3GO
	Fl7Z6PRkUdsaDKzgxuGD0iCLGrv9N3jJ9vupTEXeEhtQgPMW4qdujgB4wOU/LBEi
	3zq/TNQBPzzz4qvB5fCuFq6TrDooHYnnoUg==
X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09;
	repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox;
	action=sign d=pobox.com a=rsa-sha256;
X-DKIM2-Signature: i=1; m=1; t=1795106295; d=pobox.com;
	mf=PGdpdHN0ZXJAcG9ib3guY29tPg==;
	rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+;
	s=fm2:rsa-sha256:U87WWt30Rqqgn6R4tn1Dx5MrHVVav7aHECcCGT3rEpZFnAK
	74fn8raoVAeaGgDTyf/nZp50vbzjjvwHZZkUGbGiny03bND2bdmF84cfciNeETQa
	5tCsJ6upoFuhKryWuQOvQodcyeSFrJuY02eTCVzH+zG0jfUrMWLY3Ky8j+Lf4Ch/
	r5XWKZNaahgAFLlHEl6sa/NlRMFC2IvbrJTcJsLwdzvsjQvz56H/JjQdfz20uTTi
	P8v5p/MqLt45yj2x+iGSRUMtWtOEjuVURVeRGMclLGvEFkWtS/21BH0575p+z8wZ
	1aIuIEolG9o/l8IErTi7BU1xVjFwYgfjfzJZqAA==;
X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09;
	repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox;
	action=mi-m=1; hc=12;
	hn=cc,content-type,date,feedback-id,from,in-reply-to,message-id,
	mime-version,references,subject,to,user-agent;
X-Message-Instance: m=1; h=sha256:taB5zGJ70i+RI+Ayrcb5kaztuATlX+VJTeXeO8k9Puc=:kx9pHOWI0v2cWZX6/7/mGJiGvflX1mXi/eGSywdpMxQ=;
X-ME-Sender: <xms:9yX_anDMSWBol2Mn3GznxtXgj6N25aOFsMA8UEubXMK3h117M9MLKA>
    <xme:9yX_akaShf98taqaVOCRAIXzCiunJqwVQ8qLW1BCV-Qw9UWfsBwQDlcGJeLXIE8bM
    lai4dGQMswTbtnG9b-eEuwoHyGyx4c8LaNrRp1Z-cqCSRVjm11yuMk>
X-ME-Received: <xmr:9yX_aq6-5PzvVelM0m2oV6ow-EDKaJPh_zyQzzjh8tLH5zvQbv0B4-8h1qhYLseJ527Gizy16t4I3vzLte670Al7PXyN_XkKJhkk>
X-ME-Proxy-Cause: dmFkZTEzI4GJtRtPqTaz0KDa/xZpm8OVYhJiwurIGJrbhEFkFDdxjNORPbuV7UGHMtD73r
    L+DzFHQq2nf4MnXyn5R52JAVKDKiW9RKERVX9lkmdaQX4cL51HCpBXjQsp2iRrsCY7t47W
    yuujVU5lzko3XaYnI8jD8giJ3E0F2+NFL5LYxxXOyzHQBilFrO5BterDg80ygUe2g46AqF
    4v0oon9GEIVWqNlOsOCYvhQWmdwEdfdOe3LmB+JRRijZJbBGurEY1inHvL2PzrAa57ozkb
    MCF3OT7kBccPVdnAy8C0qcxUPIT1Vy94S8R2VCYXAmiep4gYvMH7r+swCrrswUjIkZlTH8
    bnB9ItfpnXJ35y8PgiZ7d4LZnrSmuLkWgE8xRyf2m7w1cJd4WTlKZhLJCRI/AiGJM/fMFa
    YnGCGU0PWOYY3WdIMcj/ogW9MurlNfX+0jiCJbY09SUcPx7aPJEohrS/Zd/BXZY1clUdO/
    JutkvoPPxx9RT9aT5xpgSX/B93KwMXocvpg5QvXwDsitVAfuJpLxfw42Wvpf5k2jPaQtwX
    80WeLNvysGrvStZDkim/VzhqwjOl0CZYHd/5wgv+FZtarhg0t5FyAoFHBguAMrT1DP+fpo
    GQ/K1TCxA3twfCIStrcGTQR0Ynkw8tMZKkO/xWxbl0zqjjYtyrxJBFN2VamQ
X-ME-Proxy: <xmx:9yX_alauvmKyVo_0mO1oiB055U9QxasUT70ZOk09nqfFAt37wL4wTA>
    <xmx:9yX_apg7L9zN0YvDy6gMlMEl0NJKtLc4tJZA1AU2BIhyLtUntV34ZA>
    <xmx:9yX_am9Jw_MGuIcNTd113ROzqGjRD84-qWJLA0RUNJZeNdni_YKvEw>
    <xmx:9yX_akpGrYhU668Yoo8WuuitWOH2BItZ_EHF1yAntkOvlktYsWYtyw>
    <xmx:9yX_aroerbflRikMBzmBdEU6H1ubh5doOIKntkZUCw8xetzvMBgWimTm>
X-Feedback-ID: if26b431b:Fastmail
X-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu,
 19 Nov 2026 11:38:14 -0500 (EST)
X-Cc: <git@vger.kernel.org>,  Patrick Steinhardt <ps@pks.im>,  Adam Dinwoodie
 <adam@dinwoodie.org>
X-In-Reply-To: <20261119010612.687733-1-sandals@crustytoothpaste.net> (brian
	m. carlson's message of "Thu, 19 Nov 2026 01:06:12 +0000")
X-User-Agent: Gnus/5.13 (Gnus v5.13)
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list