From patchwork Fri Apr 19 09:51:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13636076 Received: from wfhigh7-smtp.messagingengine.com (wfhigh7-smtp.messagingengine.com [64.147.123.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C06B80020 for ; Fri, 19 Apr 2024 09:51:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520313; cv=none; b=oqFyVfZiybfrd3N3lu1dGS8alfOTpX5pN3STXI0JAXd1h8dOIUkEmdSfExUgC7kXEw5ggVXp4q7tqwF25dARjijaxrDGnxJtQjxImfIYrUP864tY//AN7VF2KoWxICYMXOpqaRDcMygEfqBLaBhK6Ezi7/VerftTzXyAxwCSIbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520313; c=relaxed/simple; bh=5pWIr8ZAVZBb3u5AI/noPd7aL7JD1V4atl6Au/vVspI=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=u1dauAHA/wjasWy9vVtSFwFaW+cj4Qt859copUb/VKED3bS4jNRPZOC5t+FwjQ0fwLIVnfTb8hGY9RoSopeJIm/P+iVtocv3DYP0k7cd2bVQbDboDDw1YeIOLlaZtcvmEOLLsI2B5ZDbKjTZvtXjlQiuXy5eGbQtEUNbkRn6j6g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=aGvKy020; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ALGcu+H0; arc=none smtp.client-ip=64.147.123.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="aGvKy020"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ALGcu+H0" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id ABD0A1800095 for ; Fri, 19 Apr 2024 05:51:51 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Fri, 19 Apr 2024 05:51:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=fm3; t=1713520311; x=1713606711; bh=bHmmacWlTO bewMKDDGwrn3Qz46ifsBO7sBiNKa+/Fbk=; b=aGvKy0200WzsAtxWNfGxsgFmWS XRt1Tz8cIR7qdKMxGljiw+oIJNH8YtONTPp/tpiwGpHx3s8Ydgv9ZgihO+VwdGNi e+MOGPYjJVNrXcfP9qAOs5eFqYw01nwHomv2XbzFYDYskYPKdQy9DZJlKf0SzVtc l4ya6Bk0XC1ePYYPx5jl4EhTfGkmrFUWsTIA85sLCFzDvgvZB7FmYsuSvwRcHgWO ULpIJVWtpN4lw458aa5jlNXB0Cbr3Xke77PrVsG0nlG48tNx60ttyTiJ8Pv6Rluz WYrO2l2ApLUlE2xWfZZEAkHkBTyu50F88WMl7m8ap1O9OadBNgP8ToJTus1g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1713520311; x=1713606711; bh=bHmmacWlTObewMKDDGwrn3Qz46if sBO7sBiNKa+/Fbk=; b=ALGcu+H0FWiKk0CZwfFkVdYNsUbQ2YTplMJnqrmM3tyl uaS7vSFYCDL7OfJB1ILY2wKQOQB/7LsMjkb7k7lzlU0v3LZfDjDronGvju1RmQzb QsSFb38FCbi7x6uweMmg0KQMlZBx8E7RmIVTVxpo36sw0KX8fdcIT5OxrG/mLPK7 T90t9WNQwVa7dZunhsMDhd6xbKvqzcEFG0qDsGD7csCtLVFLZuR/jBmIgSB9BCmq O96UBf3PjmhnV+VilSvn5/Ibeap6JK9L/2QBS9UyopILUrbCIBx2aLHH4XTqNtUs l61JBs6qIfvBaCu9BCJ+dpmInqVp/QhfoD691Gssdg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekvddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 19 Apr 2024 05:51:50 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 718e3080 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 19 Apr 2024 09:51:23 +0000 (UTC) Date: Fri, 19 Apr 2024 11:51:48 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 09/11] builtin/diff: explicitly set hash algo when there is no repo Message-ID: <39e56dab621a2a1e0cbaf67f8de44614c354dcb1.1713519789.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The git-diff(1) command can be used outside repositories to diff two files with each other. But even if there is no repository we will end up hashing the files that we are diffing so that we can print the "index" line: ``` diff --git a/a b/b index 7898192..6178079 100644 --- a/a +++ b/b @@ -1 +1 @@ -a +b ``` We implicitly use SHA1 to calculate the hash here, which is because `the_repository` gets initialized with SHA1 during the startup routine. We are about to stop doing this though such that `the_repository` only ever has a hash function when it was properly initialized via a repo's configuration. To give full control to our users, we would ideally add a new switch to git-diff(1) that allows them to specify the hash function when executed outside of a repository. But for now, we only convert the code to make this explicit such that we can stop setting the default hash algorithm for `the_repository`. Signed-off-by: Patrick Steinhardt --- builtin/diff.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/builtin/diff.c b/builtin/diff.c index 6e196e0c7d..58ec7e5da2 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -465,6 +465,15 @@ int cmd_diff(int argc, const char **argv, const char *prefix) no_index = DIFF_NO_INDEX_IMPLICIT; } + /* + * When operating outside of a Git repository we need to have a hash + * algorithm at hand so that we can generate the blob hashes. We + * default to SHA1 here, but may eventually want to change this to be + * configurable via a command line option. + */ + if (nongit) + repo_set_hash_algo(the_repository, GIT_HASH_SHA1); + init_diff_ui_defaults(); git_config(git_diff_ui_config, NULL); prefix = precompose_argv_prefix(argc, argv, prefix);