From patchwork Tue May 7 04:52:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13656222 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 16B783E49E for ; Tue, 7 May 2024 04:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057577; cv=none; b=Eel6j3FyYxN6UrCYLHPfaszQGP9S3YjpaMnGwzEsGkZV2IBASMQ4fFb+HKnIr8STkx+h4z5Gyof26wfRx98XaHCtOoekLJFEUvXg2lrWuaBM8ZUGHz5YlP3Q+lRJ4Cyv6iU+eiadcFCaVkJ4ya3S274unL5qbiQ9vaBlGcpv0AE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057577; c=relaxed/simple; bh=2iX0R8V+7SjkklOvd6v0WL1HoB7jCJFOJ/waVp1uvHI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nl8ibxCGIY0GcvIrqHi6++HqgjZYbyitizA446cjXekm6oolvkwJLdaTN0JFRcR2CcXK46qJQxX4kN+UDFgTs/R+1xfwTNURwr35djV0vMc6By+AQZXO5mKfKN4MSmvcpKjO0jOjHL6vjUeJh7FkzkTk8H6UL7YV2pGULNN/5zU= 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=NuTBwNry; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=DiktOUEC; arc=none smtp.client-ip=103.168.172.152 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="NuTBwNry"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="DiktOUEC" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 4AB1D11400BC; Tue, 7 May 2024 00:52:51 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 07 May 2024 00:52:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=fm3; t=1715057571; x=1715143971; bh=28rnY4ksjL r9Tipqbp3U4BLZo66prUjPCLYu1D45Bgg=; b=NuTBwNry++TshMjuM7qrwCvfZe y8DmTHm09kQakbnF5suGC2+Psnp1Ma3JHROh/OI+UIZBYu69J7DywJBpHE9NiYmd RLq8f/dPiY8eadM+CE8uOPHiC5sGl+Qr7TTmRjtpO5eTT108DeWZ8EQY429yaH4P lH8g9vqS7TJo1lsm9OPy54XZpiVaeojxF8RFvqCk9C0zqN4uBbi6RA2TpIPeCnkx /dnYRK4F+bBW3q1U1zcyLqr2CiaeND1LSDFQubKlD5tfz3U7vOplo3DWACZ32R4v IOzJZKaUVprJ3SuGMYx1/tc5NuZ0jKfdL5DFo3n/eWQbwQFqjAumwpo5IkNQ== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715057571; x=1715143971; bh=28rnY4ksjLr9Tipqbp3U4BLZo66p rUjPCLYu1D45Bgg=; b=DiktOUECEoSH58Aci0SkpDtKLwkf/wUCdVCifRTDq7pk Xz6I6x5GgJhSlb3x6/djf4Sq7SMWPsZtPj17aeFljjf8DDymJP5DUFQXatYz/Lni a2SKVkmRfuHnU/+TlklsZVdEhkvpKGvRxRIsy+26kIaefh9PrRPrkjNQIT2M2sYO gN9pAWmXp0tzdnnWM3DPC5Oqq8lSIE7f1+Ty2iK2lRFuLLuGKPidi1GP3Ai8wgxk sgB6BZRqWrqYNpHLp+voS9zA1/jMHxpvmx2+5zR9g3VURhDfncTL9cDrFFc237rR vGG8oxUicAAohL1YF05FFGz42hC2cWbKaBVMR2RS9g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvjedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 May 2024 00:52:49 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 63435f76 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 May 2024 04:52:42 +0000 (UTC) Date: Tue, 7 May 2024 06:52:47 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v4 01/13] path: harden validation of HEAD with non-standard hashes Message-ID: <5ee372c2d8f98b8cd8c0b51bda15ad5449339776.1715057362.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 `validate_headref()` function takes a path to a supposed "HEAD" file and checks whether its format is something that we understand. It is used as part of our repository discovery to check whether a specific directory is a Git directory or not. Part of the validation is a check for a detached HEAD that contains a plain object ID. To do this validation we use `get_oid_hex()`, which relies on `the_hash_algo`. At this point in time the hash algo cannot yet be initialized though because we didn't yet read the Git config. Consequently, it will always be the SHA1 hash algorithm. In practice this works alright because `get_oid_hex()` only ends up checking whether the prefix of the buffer is a valid object ID. And because SHA1 is shorter than SHA256, the function will successfully parse SHA256 object IDs, as well. It is somewhat fragile though and not really the intent to only check for SHA1. With this in mind, harden the code to use `get_oid_hex_any()` to check whether the "HEAD" file parses as any known hash. One might be hard pressed to tighten the check even further and fully validate the file contents, not only the prefix. In practice though that wouldn't make a lot of sense as it could be that the repository uses a hash function that produces longer hashes than SHA256, but which the current version of Git doesn't understand yet. We'd still want to detect the repository as proper Git repository in that case, and we will fail eventually with a proper error message that the hash isn't understood when trying to set up the repository format. It follows that we could just leave the current code intact, as in practice the code change doesn't have any user visible impact. But it also prepares us for `the_hash_algo` being unset when there is no repository. Signed-off-by: Patrick Steinhardt --- path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/path.c b/path.c index 67229edb9c..cc02165530 100644 --- a/path.c +++ b/path.c @@ -692,9 +692,9 @@ int validate_headref(const char *path) /* * Is this a detached HEAD? */ - if (!get_oid_hex(buffer, &oid)) + if (get_oid_hex_any(buffer, &oid) != GIT_HASH_UNKNOWN) return 0; return -1; } From patchwork Tue May 7 04:52:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13656223 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 877F86BB37 for ; Tue, 7 May 2024 04:52:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057578; cv=none; b=Cm8nQlZRylQfluion4dwPKjoYjPMSsFnwH9KeknkkIDleaE0ZtXbXetI+6xiASUxszvJPSbcJw816l12woFlYJ0Xr9vQBNV68cuThuXMfRR6Xy4Nx5r1lKlaWrUSasKKFQoinZTxaeoL6fwb2y4kJVDplk50SgmbIrHdHwUxUrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057578; c=relaxed/simple; bh=dQzwMM8u84+++nfOuIWCkgTXNVxMebP3HAlJR3crkIg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cGKjcxpFdueeoxH/vRaMOmaRvPplO8ZycDt7zo/b79ZjNkP0FbyGMvq2A0v3DM1j9jsZ6HVWOpDa0P0tmaC+LN99/e+YcQwb0jjmzZ8Cy2GM2BPkWmQMJBjUG0/I1gb8S4NSb2vKHnqM1IK+QqVjoWBI0fx4htYkfgVg7NsQj4E= 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=uB509TeB; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=YjPkI67m; arc=none smtp.client-ip=103.168.172.149 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="uB509TeB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="YjPkI67m" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id A14101380279; Tue, 7 May 2024 00:52:55 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 07 May 2024 00:52:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=fm3; t=1715057575; x=1715143975; bh=rjo3FkQIrX VOfVyprqTfwXD0A20m+BvdiDJGKWsrMPw=; b=uB509TeBmCFb7U3sQGEo3GBOPK ESW7r759PLvEXz2oBuOZPwEndSfunSpUSw+ueI24EGojEonmE7dxaaU4kyEqODXV xrAosOPQLzVOkfmBn5XLMRYspyxzTx11EHSo+WV4cRxvpAAhfyPsTFmntBJQhXcL Bzqugj9q/+98h2bZl/Dx3FqV0zLEr1UdrDCeuOgO9pDn8EaQtUmmRqimwNE/1X4d yRfwsW2UNzLagXBeKktr8ACfZ1jnROmn4vK/cHP53pfhF9milJb/PWaRUviP2v38 KQbZdmHbVG91fHRYkurL0HYI1qy93PHOPTem1ahISZQIWMQVE48XY5TysaPA== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715057575; x=1715143975; bh=rjo3FkQIrXVOfVyprqTfwXD0A20m +BvdiDJGKWsrMPw=; b=YjPkI67mhgEG0EK4oA+ij4gYQM3suymm/c9fOXLUE5eY sFDbwAjUrY2lA+Ij1WKUuak85bMuH/UoBv450YO4Ddh+w022BPQwbUlePlYpfug8 ekVJuu08/CTj5LrD+5HZZPBQECbWULR9vK60b7beke+1PTUBVkccPsgUujFieT5G 6WHNl9OIzEPkO1Svlf2jcAksQBKYehJudTsCGHcbEbe3SA+3QbUX/E+CDVN1isgI 9GQ+l7r2jIP2uNfBbs3BK/GN6wETjujnhKzaETv+AB+10L2gI4J/OZP4cf00vZuz iS0Z+7pdi9OTwHjWp2yde/ajI7pd23VR4tSlRuL9Sg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvjedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 May 2024 00:52:54 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 82364892 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 May 2024 04:52:46 +0000 (UTC) Date: Tue, 7 May 2024 06:52:51 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v4 02/13] path: move `validate_headref()` to its only user Message-ID: 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: While `validate_headref()` is only called from `is_git_directory()` in "setup.c", it is currently implemented in "path.c". Move it over such that it becomes clear that it is only really used during setup in order to discover repositories. Signed-off-by: Patrick Steinhardt --- path.c | 53 ----------------------------------------------------- path.h | 1 - setup.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 54 deletions(-) diff --git a/path.c b/path.c index cc02165530..bd6e25245d 100644 --- a/path.c +++ b/path.c @@ -4,9 +4,8 @@ #include "git-compat-util.h" #include "abspath.h" #include "environment.h" #include "gettext.h" -#include "hex.h" #include "repository.h" #include "strbuf.h" #include "string-list.h" #include "dir.h" @@ -646,60 +645,8 @@ void strbuf_git_common_path(struct strbuf *sb, do_git_common_path(repo, sb, fmt, args); va_end(args); } -int validate_headref(const char *path) -{ - struct stat st; - char buffer[256]; - const char *refname; - struct object_id oid; - int fd; - ssize_t len; - - if (lstat(path, &st) < 0) - return -1; - - /* Make sure it is a "refs/.." symlink */ - if (S_ISLNK(st.st_mode)) { - len = readlink(path, buffer, sizeof(buffer)-1); - if (len >= 5 && !memcmp("refs/", buffer, 5)) - return 0; - return -1; - } - - /* - * Anything else, just open it and try to see if it is a symbolic ref. - */ - fd = open(path, O_RDONLY); - if (fd < 0) - return -1; - len = read_in_full(fd, buffer, sizeof(buffer)-1); - close(fd); - - if (len < 0) - return -1; - buffer[len] = '\0'; - - /* - * Is it a symbolic ref? - */ - if (skip_prefix(buffer, "ref:", &refname)) { - while (isspace(*refname)) - refname++; - if (starts_with(refname, "refs/")) - return 0; - } - - /* - * Is this a detached HEAD? - */ - if (get_oid_hex_any(buffer, &oid) != GIT_HASH_UNKNOWN) - return 0; - - return -1; -} - static struct passwd *getpw_str(const char *username, size_t len) { struct passwd *pw; char *username_z = xmemdupz(username, len); diff --git a/path.h b/path.h index ea96487b29..c3bc8617bd 100644 --- a/path.h +++ b/path.h @@ -172,9 +172,8 @@ const char *git_path_merge_head(struct repository *r); const char *git_path_fetch_head(struct repository *r); const char *git_path_shallow(struct repository *r); int ends_with_path_components(const char *path, const char *components); -int validate_headref(const char *ref); int calc_shared_perm(int mode); int adjust_shared_perm(const char *path); diff --git a/setup.c b/setup.c index f4b32f76e3..7c996659bd 100644 --- a/setup.c +++ b/setup.c @@ -3,8 +3,9 @@ #include "copy.h" #include "environment.h" #include "exec-cmd.h" #include "gettext.h" +#include "hex.h" #include "object-name.h" #include "refs.h" #include "repository.h" #include "config.h" @@ -340,8 +341,60 @@ int get_common_dir_noenv(struct strbuf *sb, const char *gitdir) strbuf_release(&path); return ret; } +static int validate_headref(const char *path) +{ + struct stat st; + char buffer[256]; + const char *refname; + struct object_id oid; + int fd; + ssize_t len; + + if (lstat(path, &st) < 0) + return -1; + + /* Make sure it is a "refs/.." symlink */ + if (S_ISLNK(st.st_mode)) { + len = readlink(path, buffer, sizeof(buffer)-1); + if (len >= 5 && !memcmp("refs/", buffer, 5)) + return 0; + return -1; + } + + /* + * Anything else, just open it and try to see if it is a symbolic ref. + */ + fd = open(path, O_RDONLY); + if (fd < 0) + return -1; + len = read_in_full(fd, buffer, sizeof(buffer)-1); + close(fd); + + if (len < 0) + return -1; + buffer[len] = '\0'; + + /* + * Is it a symbolic ref? + */ + if (skip_prefix(buffer, "ref:", &refname)) { + while (isspace(*refname)) + refname++; + if (starts_with(refname, "refs/")) + return 0; + } + + /* + * Is this a detached HEAD? + */ + if (get_oid_hex_any(buffer, &oid) != GIT_HASH_UNKNOWN) + return 0; + + return -1; +} + /* * Test if it looks like we're at a git directory. * We want to see: * From patchwork Tue May 7 04:52:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13656224 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 E97F16A8C1 for ; Tue, 7 May 2024 04:53:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057585; cv=none; b=u18Hv8vJZwO3A9O8ZfjW/D4SI2xxyPiorlXxbIo7o9wI1qy4jPqLRyAV0yft6qQwjYw5WFiR7cTdR69ffYPSHscKfefBY7RLDAK3bYYEAF2pgQYPd/D1Whne3Y4+rLTkPIJDZjjPGExsX8ZtdcC+Jf3Xj+D270mHPO9uKr7iEWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057585; c=relaxed/simple; bh=4z6VVdXr8vb2a17XIjM1oOFkNbGGLPKEO9Y6A92qzSY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ecOBbEHj+AlDyp/j+/Eu06klGHQFTjn6nWMOYQfWcHJaujDi/yNzSlJbZoSBZMbV2qOq/KvBOyzFW2IUtYku5Mrbn3QNk+ZvEmXX6Rxz4o0VzTT63mV7gIlDy5XlLH4HgjwjTe8pNXpD6jE4ukifRN6S4WzaSCcN78/UyHuGR2o= 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=EexDwsNJ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FbmruDAD; arc=none smtp.client-ip=103.168.172.152 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="EexDwsNJ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FbmruDAD" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 00B3B114012B; Tue, 7 May 2024 00:53:00 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 07 May 2024 00:53:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=fm3; t=1715057579; x=1715143979; bh=19Yy678alB a7qlJ+4Z3NvIW+R7r/nPyIchOt+UuX00A=; b=EexDwsNJ+z2z4a2ownI5eNyd9L Sg2FKSG/wT40YpUx7sudsU7fdjrKBezTexK7hKgJYfLN/rq9HlswmdPUFCoXemtq sRXf4n7+TP3SoHece29P3nodxlwqvajEW4WHWHG6wmbDfq6ngJ8nYVzRE4uWsGfH 3YWDrEantaGVpKA/Qc8th8xvVt3wjQqd+z8xrGWivsg4ZH0KD4ww5xLswLAiRfji x+/4/dFpY2B1Ku6F3o4+FAsXrGvymWrt6PmiN2uR87x0FC60+tg/qVhgxcBrMA5w 5pySWdXCcL7rgxLy4TY/cdVf8AXD82J0hVFDUAgznFmK2r0NPzAHc+eeHyLA== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715057579; x=1715143979; bh=19Yy678alBa7qlJ+4Z3NvIW+R7r/ nPyIchOt+UuX00A=; b=FbmruDADtMR0y0N11V70bLTqJuQMZAng4Ufu5cJx2nnt xfluJtS3yOkmvsVe43ojfBrSMPFkpfUnnDC1n3N59PDW4SMiui1R5/JnUNG5CqJD 7yQjWlOUK7prw1Eeep6MCaVg9mZJD1baWot9Ark00sAWWIESCD3O3JVjHcY7ajAC SFDM9coSdKYdMyFOTuMVg6fB9yNWaHXvD74KXL66A4nPsiPzP3884PqG1FLh6SCG hZmAXnmesNi3c4eJdjBcBzT2So0dUbsHvwt57GkiqwC1Ot8DlVcJpVXJWCYfcHn6 /u86FENr+ABEKmGA+jG+Rur58Tu96S3DXfUfRSBfkw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvjedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 May 2024 00:52:58 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 6577c52a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 May 2024 04:52:51 +0000 (UTC) Date: Tue, 7 May 2024 06:52:56 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v4 03/13] parse-options-cb: only abbreviate hashes when hash algo is known Message-ID: <1a0859eaf118090b4d172792e63ee9a6ba752b71.1715057362.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 `OPT__ABBREV()` option can be used to add an option that abbreviates object IDs. When given a length longer than `the_hash_algo->hexsz`, then it will instead set the length to that maximum length. It may not always be guaranteed that we have `the_hash_algo` initialized properly as the hash algorithm can only be set up after we have set up `the_repository`. In that case, the hash would always be truncated to the hex length of SHA1, which may not be what the user desires. In practice it's not a problem as all commands that use `OPT__ABBREV()` also have `RUN_SETUP` set and thus cannot work without a repository. Consequently, both `the_repository` and `the_hash_algo` would be properly set up. Regardless of that, harden the code to not truncate the length when we didn't set up a repository. Signed-off-by: Patrick Steinhardt --- parse-options-cb.c | 3 ++- t/t0040-parse-options.sh | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/parse-options-cb.c b/parse-options-cb.c index bdc7fae497..d99d688d3c 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -6,8 +6,9 @@ #include "date.h" #include "environment.h" #include "gettext.h" #include "object-name.h" +#include "setup.h" #include "string-list.h" #include "strvec.h" #include "oid-array.h" @@ -28,9 +29,9 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset) return error(_("option `%s' expects a numerical value"), opt->long_name); if (v && v < MINIMUM_ABBREV) v = MINIMUM_ABBREV; - else if (v > the_hash_algo->hexsz) + else if (startup_info->have_repository && v > the_hash_algo->hexsz) v = the_hash_algo->hexsz; } *(int *)(opt->value) = v; return 0; diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh index 8bb2a8b453..45a773642f 100755 --- a/t/t0040-parse-options.sh +++ b/t/t0040-parse-options.sh @@ -175,8 +175,25 @@ test_expect_success 'long options' ' test_must_be_empty output.err && test_cmp expect output ' +test_expect_success 'abbreviate to something longer than SHA1 length' ' + cat >expect <<-EOF && + boolean: 0 + integer: 0 + magnitude: 0 + timestamp: 0 + string: (not set) + abbrev: 100 + verbose: -1 + quiet: 0 + dry run: no + file: (not set) + EOF + test-tool parse-options --abbrev=100 >output && + test_cmp expect output +' + test_expect_success 'missing required value' ' cat >expect <<-\EOF && error: switch `s'\'' requires a value EOF From patchwork Tue May 7 04:53:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13656225 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 B2EEB6BB2F for ; Tue, 7 May 2024 04:53:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057588; cv=none; b=GphzAxzWBqW8V0WLU4vro0HNjP1GEMGOEvPgwFXLHUahFkTKGpdv2+E8IiWfJUDx9ZZ3j3eqxhSQd3Z+vVMplVxZ28j40564Vc5tS7XM67DWg1/9O/dsgTrl8Ot2wph5EtEEn3DVmW9/snPvIxkR09bI2ZXIS8zKDbnZNYGnWj8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057588; c=relaxed/simple; bh=QIxnVT7TP1Z7LKljBJOvXZM0iuHhAxLnkCjJBdWOThQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QjcjMcGVPDPetME1Q0BSJQ2GdjOs3qa/kc4kG9cLwjBXfl3o8d1OuQ7EOLoNNWr0pjRIscQCGFgmP7M0wKaMfjQ42gjrdI3A2Q080iEtO9JEGinTegwMBZhi7Ijsw3ran7vTb1m0zK8Qg59NtaBL8qMhoJULdBsz2hLkTmG3lJ0= 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=jKPwLF5U; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=GqCiez30; arc=none smtp.client-ip=103.168.172.152 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="jKPwLF5U"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="GqCiez30" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 4F8421140166; Tue, 7 May 2024 00:53:04 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 07 May 2024 00:53:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=fm3; t=1715057584; x=1715143984; bh=epubhXTdMf A7w1nIBQEwMEwgpug5cUbu5JXxBDQ3XNc=; b=jKPwLF5UitXmoN5qsIhE5/amC5 18UOqYX++/bW9KPGQWLLoBkqRkQCKWASAQ3LbkTXE0iu3aurWlXXa96QkCZshSri yf1ujVuKQdEtG6HtMx985Jq16W53HvAvzL1Kb2pvutjWur9cJHKd5ys+nZOy4wpv fTmYy6MhvyLrFx3RhX9vu4RttV+DSRq/dBgFyxh2Vr9mvd9ssvNZJu91BmBrvYhS k5XEVHzCU+P9NRYHxUq5qtKsTKjy6Ut4paOKVPRxsvmShFnIj4gW5BJ04t1wAN1+ pn6P+9x9wAzX3yAUkZoHuW+LGDBHK3xubXWNFjjtKfpbzQE4WyJ03V8QxfUg== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715057584; x=1715143984; bh=epubhXTdMfA7w1nIBQEwMEwgpug5 cUbu5JXxBDQ3XNc=; b=GqCiez30lOkLQD0e+t/ytkleWRHQ14Z0tZ1K5AV2DTbe gUObDRqBx1x74YEVeGtLg03YxPmDuSinrOydGaUWM1Al87cHbn8dvZRcPo1H6ags UFssuE2oF0mP2xE4IKyEGrX9lAlQ2Df+matwmW33iEzjRsZHeFNKot4J8Abpkfsf mZMgaGoPl6ZgYLeau7LTiFRJeZdiH5+KqlwlOk14uv6NNlRlgU+mTRdh4TX0aNsp 30X9APOSgm51fLkbPOTfrHxinJYWVAHobvmC83r3TY0ksiOCcPVJShzGk2REB5S3 sjh0ovgQm6wizkXNvflj6ek4P3Mh4qg1bsFFdIT1sg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvjedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 May 2024 00:53:03 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id de05801a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 May 2024 04:52:56 +0000 (UTC) Date: Tue, 7 May 2024 06:53:01 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v4 04/13] attr: don't recompute default attribute source Message-ID: <1204a342161235c38273981874add59031cb554e.1715057362.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 `default_attr_source()` function lazily computes the attr source supposedly once, only. This is done via a static variable `attr_source` that contains the resolved object ID of the attr source's tree. If the variable is the null object ID then we try to look up the attr source, otherwise we skip over it. This approach is flawed though: the variable will never be set to anything else but the null object ID in case there is no attr source. Consequently, we re-compute the information on every call. And in the worst case, when we silently ignore bad trees, this will cause us to try and look up the treeish every single time. Improve this by introducing a separate variable `has_attr_source` to track whether we already computed the attr source and, if so, whether we have an attr source or not. This also allows us to convert the `ignore_bad_attr_tree` to not be static anymore as the code will only be executed once anyway. Signed-off-by: Patrick Steinhardt --- attr.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/attr.c b/attr.c index 6af7151088..a5b717e4ce 100644 --- a/attr.c +++ b/attr.c @@ -1205,41 +1205,48 @@ static void collect_some_attrs(struct index_state *istate, fill(path, pathlen, basename_offset, check->stack, check->all_attrs, rem); } static const char *default_attr_source_tree_object_name; -static int ignore_bad_attr_tree; void set_git_attr_source(const char *tree_object_name) { default_attr_source_tree_object_name = xstrdup(tree_object_name); } -static void compute_default_attr_source(struct object_id *attr_source) +static int compute_default_attr_source(struct object_id *attr_source) { + int ignore_bad_attr_tree = 0; + if (!default_attr_source_tree_object_name) default_attr_source_tree_object_name = getenv(GIT_ATTR_SOURCE_ENVIRONMENT); if (!default_attr_source_tree_object_name && git_attr_tree) { default_attr_source_tree_object_name = git_attr_tree; ignore_bad_attr_tree = 1; } - if (!default_attr_source_tree_object_name || !is_null_oid(attr_source)) - return; + if (!default_attr_source_tree_object_name) + return 0; if (repo_get_oid_treeish(the_repository, default_attr_source_tree_object_name, - attr_source) && !ignore_bad_attr_tree) - die(_("bad --attr-source or GIT_ATTR_SOURCE")); + attr_source)) { + if (!ignore_bad_attr_tree) + die(_("bad --attr-source or GIT_ATTR_SOURCE")); + return 0; + } + + return 1; } static struct object_id *default_attr_source(void) { static struct object_id attr_source; + static int has_attr_source = -1; - if (is_null_oid(&attr_source)) - compute_default_attr_source(&attr_source); - if (is_null_oid(&attr_source)) + if (has_attr_source < 0) + has_attr_source = compute_default_attr_source(&attr_source); + if (!has_attr_source) return NULL; return &attr_source; } From patchwork Tue May 7 04:53:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13656226 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 0613B6A8CF for ; Tue, 7 May 2024 04:53:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057594; cv=none; b=hf5HgO/WAAmeClgra3RnKRKT54ewiK9i47yUo0aqguzkEwubmiQ/QIkYlm2yAaFCVL/I0CpMbpOicvLiwMMW0xNSjiGVDIemiDFASTM9gbwkMeWphwkoHHB043pd2Qp61F5Up5iT/exvVvBzaeUsyXMQYR34Gwc6PRyDnX6Wqoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057594; c=relaxed/simple; bh=eVSKxBKG5Zcaks94GkwuH9/ZK1uXYptOvHxFszcIwnw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=l7xL+y4SpsOzenr6nn8CcRNxC6tpHTPG+0Xq573QEQ8aXq5Y79YlT9ciQMamSAD3gt7bdKZ01r+Ws84YboBgCZjEo9OFO6ZVkDB8asiM5GzHZwgRcWAlXgFvoSfqPOommeOWiAX9dmJs3qaA8FhcRAH0PAs51q8JjgWGNqesze8= 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=l+KbtFxt; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Ritcu0Wq; arc=none smtp.client-ip=103.168.172.152 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="l+KbtFxt"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Ritcu0Wq" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A1E5D1140156; Tue, 7 May 2024 00:53:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Tue, 07 May 2024 00:53:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=fm3; t=1715057589; x=1715143989; bh=yUjhLdCJR3 wpC8t5zUGcB6E0Qq8OZxSX099He/dQgyU=; b=l+KbtFxtTAC0zhhniXYiXZZ+NO WmB1bLQoRqSaLuCt7gCfcVmQp9neA8Rq+DykiJvmPxDe7KVzePRvDRq0SmVoM8gK 0RVhcX6f+f5jwKysFyO9tAHSta32FfC6rtljYnMygy7kk8EyMdYGH49bdbsmSX2I l63rzqKlPeclxnYRr0X0coW2fm3FvvgAZlELNYYRXtpKyZLlzJ7SCBTFwAHDBH2+ wFFnjx3sB1EZGSKnU88vMPggaHoIU7jIsPZEM0Wum6wxMLShw+u6ekl0P/LBj3ov X5QLx3tdU6ZUauIOJqlD0Xs5317jASHTZLT/eDPMvzHcSQhvyKuzHULTMxeA== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715057589; x=1715143989; bh=yUjhLdCJR3wpC8t5zUGcB6E0Qq8O ZxSX099He/dQgyU=; b=Ritcu0WqUQgPWdcu0aE/j/ZmmkeiHYLEwmzFrec3XCN/ 4951S2+VTxeD0XtdQ7xRRgZisY+kQOzn9hjpq7GonrRRZ+gW3C/KeYT8XZZtCGag s/dDPODjWG8Jm0zu2fHMFbsvQ2aJ93ryS2SPFTgCIGhyIWFBH04DP4Ftor5Y4X3+ G7JrERE95WgT/8aqGN5B5QFlgaH10FDqXJ759l+QHQ6zRyutwY56wwH4CK7AEvgL QL/RQvaV/0qFJuEs4v+7WcHTgERVAWGUe5KcnWx9p2WRJLYJC44bzmMCsRDUVc0/ jY6fQZMZQEBjMunf3oYzkZphKHLLv8dbEghqWlj4Zw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvjedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 May 2024 00:53:08 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id cd89540c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 May 2024 04:53:00 +0000 (UTC) Date: Tue, 7 May 2024 06:53:05 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v4 05/13] attr: fix BUG() when parsing attrs outside of repo Message-ID: 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: If either the `--attr-source` option or the `GIT_ATTR_SOURCE` envvar are set, then `compute_default_attr_source()` will try to look up the value as a treeish. It is possible to hit that function while outside of a Git repository though, for example when using `git grep --no-index`. In that case, Git will hit a bug because we try to look up the main ref store outside of a repository. Handle the case gracefully and detect when we try to look up an attr source without a repository. Signed-off-by: Patrick Steinhardt --- attr.c | 6 ++++++ t/t0003-attributes.sh | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/attr.c b/attr.c index a5b717e4ce..c89ab3478e 100644 --- a/attr.c +++ b/attr.c @@ -1226,8 +1226,14 @@ static int compute_default_attr_source(struct object_id *attr_source) if (!default_attr_source_tree_object_name) return 0; + if (!startup_info->have_repository) { + if (!ignore_bad_attr_tree) + die(_("cannot use --attr-source or GIT_ATTR_SOURCE without repo")); + return 0; + } + if (repo_get_oid_treeish(the_repository, default_attr_source_tree_object_name, attr_source)) { if (!ignore_bad_attr_tree) diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index d755cc3c29..72fadca1e8 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -433,8 +433,23 @@ test_expect_success 'precedence of --attr-source, GIT_ATTR_SOURCE, then attr.tre test_cmp expect actual ) ' +test_expect_success 'diff without repository with attr source' ' + mkdir -p "$TRASH_DIRECTORY/outside/nongit" && + ( + cd "$TRASH_DIRECTORY/outside/nongit" && + GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/outside" && + export GIT_CEILING_DIRECTORIES && + touch file && + cat >expect <<-EOF && + fatal: cannot use --attr-source or GIT_ATTR_SOURCE without repo + EOF + test_must_fail env GIT_ATTR_SOURCE=HEAD git grep --no-index foo file 2>err && + test_cmp expect err + ) +' + test_expect_success 'bare repository: with --source' ' ( cd bare.git && attr_check_source foo/bar/f f tag-1 && From patchwork Tue May 7 04:53:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13656227 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 A3E7D6A8C1 for ; Tue, 7 May 2024 04:53:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057599; cv=none; b=Z263GOPBubB1IOXF2n5BmkS0R2qhv5e4JWx38R8eKgX80VMD435W7wO6TRzLUYmZ6vlgn4Gs/1bhsHpA4f0YJKDN0x0cJ2IfxL+ygQ+HUMe+4cXmrxormUPvWHrkhglWYaK9XYARi06CWnTYZUMBsXAkXRT3na8bCvIFUZ9luxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057599; c=relaxed/simple; bh=GFI2JGbExCAMSOpN0wtY8xvHAByNkoq+sYaPRxtSIHI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JmP1znWyp2RB0+Z1/YXp0SpjBssE/R8QWXABBkN9MWTgYaoVf8jhdBdcS7HQ0ym9xAYKkBpUEscRFsPlAgUdv3FJEQo8qQmUmx5n24oYIKaujXkAkyeaBHHK1rZ9w/YDn91EmhYL2I8SiYVQUozWO3D5qq15+feozx1bqFq26gY= 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=bEpLH8iz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TSvgWG1l; arc=none smtp.client-ip=103.168.172.152 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="bEpLH8iz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TSvgWG1l" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id E2895114012B; Tue, 7 May 2024 00:53:13 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 07 May 2024 00:53:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=fm3; t=1715057593; x=1715143993; bh=3Sxt1xLk90 E0Xa30iUrw3cey+3Vp1+vDyrXofV66Jd0=; b=bEpLH8izK1R0j3QLcPDkRaNdRU DKgPnFbo+tK3Wk6xW4nr1spVNxzepyx0RSnOWbgHlp6dXsT6rMCEHi6J/e+NDjVP dRKQfvB2I0xo3nSg6ppkt5Bi41hS3xfQFl4QjUinHdsaD8vuhbQfyGV4hSa/oatl 9lJxTt77IKvcOY6RbO6DjVdgi9WNJKPYNm3zsE1CibxK4KkbbZ8dQPx595iSaU0c VHnmLps1DMy5qXL3+gc2Gwouj36jGzqszKnRrXwuMWiFwzhGXvjje/kcx+vcWorp USFw1ZExxR6+zLMx8lCNK2GXh6tMgu6zt89/X5T5izvS8ZuK4bXBNXLGZtFg== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715057593; x=1715143993; bh=3Sxt1xLk90E0Xa30iUrw3cey+3Vp 1+vDyrXofV66Jd0=; b=TSvgWG1lq+LvA2f2V/zZHlEgh4GyWa85J6Q2e+vOS4dF 84EZCnDNBLhZWWAPdH5sn2AhfzJHzSSTV4AG1y3zHsKfGrnnMcASNfKc1OCRXNPG JyNOzahe8FcG0Y85cfIDdv+p5k83023ywyx4+wG2sLd7tQq6WKhqiDPL72/m6Jyl yWeh+JblCmXuuThVC0MirtKyNPxdA+0gWo0SgtT96PDUggutrBXmC0CFApc1e7sa cYZifERVYWvDBYVjISPO0hcL/ImXkXAq6y4O+PD8zo4wEgDJm0ZYJlI8cJDRMuGR RbT4iPDfMMuHN946nfnTRg/xQ3+8+LsRiuSYwGVubg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvjedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepjedvjedukedtvddvleejjeefudefgeettdegffdtleekgeehvdfffeeitedviedv necuffhomhgrihhnpehhthhtphdqfhgvthgthhdqughumhgsrdhshhdphhhtthhpthhrrg hnshhpohhrthdrrghsnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghi lhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 May 2024 00:53:12 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 5df331ea (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 May 2024 04:53:05 +0000 (UTC) Date: Tue, 7 May 2024 06:53:10 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v4 06/13] remote-curl: fix parsing of detached SHA256 heads Message-ID: 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 dumb HTTP transport tries to read the remote HEAD reference by downloading the "HEAD" file and then parsing it via `http_fetch_ref()`. This function will either parse the file as an object ID in case it is exactly `the_hash_algo->hexsz` long, or otherwise it will check whether the reference starts with "ref :" and parse it as a symbolic ref. This is broken when parsing detached HEADs of a remote SHA256 repository because we never update `the_hash_algo` to the discovered remote object hash. Consequently, `the_hash_algo` will always be the fallback SHA1 hash algorithm, which will cause us to fail parsing HEAD altogteher when it contains a SHA256 object ID. Fix this issue by setting up `the_hash_algo` via `repo_set_hash_algo()`. While at it, let's make the expected SHA1 fallback explicit in our code, which also addresses an upcoming issue where we are going to remove the SHA1 fallback for `the_hash_algo`. Signed-off-by: Patrick Steinhardt --- remote-curl.c | 19 ++++++++++++++++++- t/t5550-http-fetch-dumb.sh | 15 +++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/remote-curl.c b/remote-curl.c index 0b6d7815fd..004b707fdf 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -265,14 +265,25 @@ static struct ref *parse_git_refs(struct discovery *heads, int for_push) return list; } +/* + * Try to detect the hash algorithm used by the remote repository when using + * the dumb HTTP transport. As dumb transports cannot tell us the object hash + * directly have to derive it from the advertised ref lengths. + */ static const struct git_hash_algo *detect_hash_algo(struct discovery *heads) { const char *p = memchr(heads->buf, '\t', heads->len); int algo; + + /* + * In case the remote has no refs we have no way to reliably determine + * the object hash used by that repository. In that case we simply fall + * back to SHA1, which may or may not be correct. + */ if (!p) - return the_hash_algo; + return &hash_algos[GIT_HASH_SHA1]; algo = hash_algo_by_length((p - heads->buf) / 2); if (algo == GIT_HASH_UNKNOWN) return NULL; @@ -294,8 +305,14 @@ static struct ref *parse_info_refs(struct discovery *heads) die("%sinfo/refs not valid: could not determine hash algorithm; " "is this a git repository?", transport_anonymize_url(url.buf)); + /* + * Set the repository's hash algo to whatever we have just detected. + * This ensures that we can correctly parse the remote references. + */ + repo_set_hash_algo(the_repository, hash_algo_by_ptr(options.hash_algo)); + data = heads->buf; start = NULL; mid = data; while (i < heads->len) { diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh index 4c3b32785d..5f16cbc58d 100755 --- a/t/t5550-http-fetch-dumb.sh +++ b/t/t5550-http-fetch-dumb.sh @@ -54,8 +54,23 @@ test_expect_success 'list refs from outside any repository' ' nongit git ls-remote "$HTTPD_URL/dumb/repo.git" >actual && test_cmp expect actual ' + +test_expect_success 'list detached HEAD from outside any repository' ' + git clone --mirror "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \ + "$HTTPD_DOCUMENT_ROOT_PATH/repo-detached.git" && + git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo-detached.git" \ + update-ref --no-deref HEAD refs/heads/main && + git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo-detached.git" update-server-info && + cat >expect <<-EOF && + $(git rev-parse main) HEAD + $(git rev-parse main) refs/heads/main + EOF + nongit git ls-remote "$HTTPD_URL/dumb/repo-detached.git" >actual && + test_cmp expect actual +' + test_expect_success 'create password-protected repository' ' mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" && cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \ "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git" From patchwork Tue May 7 04:53:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13656228 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 5FC9D6A8C1 for ; Tue, 7 May 2024 04:53:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057603; cv=none; b=IJZExB1Z2StoQDL3yr1T4Lr+twFFQnTaVCXYHMeA0/iVVJEkFJdMZP/45stq/OSuSzOnajtv8LWVAodog9uftq0qCchpsZWBlF3uMN+ySEMltvolBAhG8HVWmgYvyfcLQH8WNOmA6+MEqxJ0kzjemCkfMt+x21YsqecMpW4wzho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057603; c=relaxed/simple; bh=956tmkVUNeefWKEKcwlJ+A7TfxGB/XAsKrOR4yPki/I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RbXTm6jZYnKy3796PHXHAcH1jtm7+B5S7sisYnPCGshz0N/0xi3u4UdJDmmKawBxcTm8ZDWDUzOxWcq9Qt/C65O5nm2KonrCG5ZigdiN4buakJZofjnsIh0+TUZwXl7yBWZJaH6eecPGxLuSxCypDhXtIIzdLSBtRcgaXyukP0E= 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=Y1N6y6Cv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ePREl3iv; arc=none smtp.client-ip=103.168.172.152 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="Y1N6y6Cv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ePREl3iv" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 438DC1140156; Tue, 7 May 2024 00:53:19 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Tue, 07 May 2024 00:53:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=fm3; t=1715057599; x=1715143999; bh=PT0SB9neb1 VZnjfqJKi683mf08Bhxkth5m2j6tonsgw=; b=Y1N6y6CvFJPAvXYzbqnehkJsJv Ox25PXqmqcWRvsZ1+uiM7Fc8S06b6/G+erlFcMbnYxb/3edY3K4IE63hdHzjDsAX 9AeGfctHo3fuqnBpOYzZLRn/0LAdpdFs25AU5nuJd9vUp42CI3oYxgg2kxZq6Rt7 b/cK+ITYbxxlDuTzSm9kwuCQNcYfkqKW0NDe/mLkShhLoBF3ALbTiNKXFk5c73M9 RcO2pHcPHGPxvoSAXKj5pgjUhF/vcXjHB8HGtFWX/4Suyy+e70HULmTyAwEcOXPE s0MiIhGoucOBhF4k3A0MvdDgTrQTwSQzYDno+jiKsWYaR0l8rVIF9tIqxhrQ== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715057599; x=1715143999; bh=PT0SB9neb1VZnjfqJKi683mf08Bh xkth5m2j6tonsgw=; b=ePREl3iv+czeV2lJQLIwXl3Y3JhbCxnI6kaYmtvuMXv3 MckPzdMo8LZiCkfrtwS4klrJf9C0GKwcJS6HGr+MwPxArRCNsgtI7DHNjnhM14Bi sKFeJvQqFsts1dP78HWh6aojAsUm8MRY5mmTBN5+SMucwBtzwAtJwReVBqJtgwC5 kXYIp38SvZfn0ATo6VBha1pCYRQfD319a4+VgNukFEoLXK67VNHxIF82+ykPM8rS A9ZQQqh7nyqulAmLAViQDejhNsYdbWXUq38rHQGLlfSfdV6hD0WoB+lxlWXyK5ia O/yB1cEWScIaQacNorXn7EdGVa4MRwHzDwkmSplHew== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvjedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 May 2024 00:53:18 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 4d3a81e6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 May 2024 04:53:10 +0000 (UTC) Date: Tue, 7 May 2024 06:53:15 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v4 07/13] builtin/rev-parse: allow shortening to more than 40 hex characters Message-ID: <61160303108133f0225aae0f0776fa15c7ee07ec.1715057362.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 `--short=` option for git-rev-parse(1) allows the user to specify to how many characters object IDs should be shortened to. The option is broken though for SHA256 repositories because we set the maximum allowed hash size to `the_hash_algo->hexsz` before we have even set up the repo. Consequently, `the_hash_algo` will always be SHA1 and thus we truncate every hash after at most 40 characters. Fix this by accessing `the_hash_algo` only after we have set up the repo. Signed-off-by: Patrick Steinhardt --- builtin/rev-parse.c | 5 ++--- t/t1500-rev-parse.sh | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index af79538632..7d10ee33c4 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -686,9 +686,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) unsigned int flags = 0; const char *name = NULL; struct object_context unused; struct strbuf buf = STRBUF_INIT; - const int hexsz = the_hash_algo->hexsz; int seen_end_of_options = 0; enum format_type format = FORMAT_DEFAULT; if (argc > 1 && !strcmp("--parseopt", argv[1])) @@ -862,10 +861,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; abbrev = strtoul(arg, NULL, 10); if (abbrev < MINIMUM_ABBREV) abbrev = MINIMUM_ABBREV; - else if (hexsz <= abbrev) - abbrev = hexsz; + else if ((int)the_hash_algo->hexsz <= abbrev) + abbrev = the_hash_algo->hexsz; continue; } if (!strcmp(arg, "--sq")) { output_sq = 1; diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh index a669e592f1..30c31918fd 100755 --- a/t/t1500-rev-parse.sh +++ b/t/t1500-rev-parse.sh @@ -303,5 +303,11 @@ test_expect_success 'rev-parse --bisect includes bad, excludes good' ' git rev-parse --symbolic-full-name --bisect >actual && test_cmp expect actual ' +test_expect_success '--short= truncates to the actual hash length' ' + git rev-parse HEAD >expect && + git rev-parse --short=100 HEAD >actual && + test_cmp expect actual +' + test_done From patchwork Tue May 7 04:53:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13656229 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 16D516BFA0 for ; Tue, 7 May 2024 04:53:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057606; cv=none; b=AWpkHVUw37MN9FB5tNhlyLIUQSr7DJP3DwtOAeofKexW5KxmfQG74jnwf7tBnA5/uKbnyDltJeM0XnOA2pAeXUymgcqKnfvOG+3hlJUArsUyvE++ADNW+HJv1PTM6E21s9NxzEZYUS3vzrn4v7yKhKhnBoEWal24otrALqiE5C4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057606; c=relaxed/simple; bh=CSxceVs6ZOAx4ML0QqmsLp0B3wdboywMUpjfRnlCqlo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IQEw8d6nBm3k8onruWO8BlxrcCtDjcidFTYK3bMaK7bGedXGxbvvivCrM/1IwcQGdwaDdU46CZBCralequEPJhligvNgUEQSR+JMf7fYQjT/WLx2C8dAUaruimBbDI4gAMxyxUWRjbPjCkm0syVBjOacaUE5fy+wYugc7Gf3n0U= 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=vGvfJEhg; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gE0LFL/D; arc=none smtp.client-ip=103.168.172.152 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="vGvfJEhg"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gE0LFL/D" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A99961140166; Tue, 7 May 2024 00:53:23 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 07 May 2024 00:53:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=fm3; t=1715057603; x=1715144003; bh=QKtN/dQTo5 KnjBmOWpBuzEnquFlfVByiSmpDqhMYVlo=; b=vGvfJEhgmQB4dSkCj3GCIGQe+N sL0s21edeKQHHusuZNmlHJKDQ/ASAoTsEoALHOyKIqXc5S8Lj9o/u0lk210vzDEt CbygXod8xX0+HSzoi3fBoe9i5xdjfFWC9AmrRUxxbbXp/dVNMMFBsul9rmnV9TBo 7Ey/bT8bl5H2tB8Cq/n8Na6nwPaVstz8K3y2lroVwueLz5B66GgrUNGwM7afMqCF iPgMdJg+7W2FpomoNVkWlDyAiz57SADxhA8tumClvXYh5NKIraL67mKnPMhQ0nbo kjF64/NX9RcTz3oGs1uGhzn4nHHWuM1EKCm3ohNnOb63306KSgpNAv14tDDQ== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715057603; x=1715144003; bh=QKtN/dQTo5KnjBmOWpBuzEnquFlf VByiSmpDqhMYVlo=; b=gE0LFL/DBsas678nI4TTW39QZTaKJkDEGJaJidFu94mD +BSvyCsgbaneBX9wN759qbVNxvUpgUiAtDMbFdAp6yMT/KeBhOkP64WAgMaiVot9 o7kGKEBgjsVKjlWAeOBYjrVl8cxsjhLVrMESR8a3cbMU+CzTFgLTSr1gX/D6Np93 4qAK/Xf3wRloMKDdaTBhSNaxHqMeLdGjK8hsHMoW3mY8i8ORRxUx8keCcwLUSBj2 aHD9hNdx1dgKi2jQlELoReApAXrGEqDUL/sD6eZwv4ooD4Rrgdfh1T7UYw8D1T74 Icy2qm9+6xwny07Lqejmw0csA12ZT6k2vWZYaaT0jg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvjedgkeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 May 2024 00:53:22 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id afd65ab3 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 May 2024 04:53:15 +0000 (UTC) Date: Tue, 7 May 2024 06:53:20 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v4 08/13] builtin/blame: don't access potentially unitialized `the_hash_algo` Message-ID: <872ded113ef3cc97cfdaa7f199ffe6aca45c6067.1715057362.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: We access `the_hash_algo` in git-blame(1) before we have executed `parse_options_start()`, which may not be properly set up in case we have no repository. This is fine for most of the part because all the call paths that lead to it (git-blame(1), git-annotate(1) as well as git-pick-axe(1)) specify `RUN_SETUP` and thus require a repository. There is one exception though, namely when passing `-h` to print the help. Here we will access `the_hash_algo` even if there is no repo. This works fine right now because `the_hash_algo` gets sets up to point to the SHA1 algorithm via `initialize_repository()`. But we're about to stop doing this, and thus the code would lead to a `NULL` pointer exception. Prepare the code for this and only access `the_hash_algo` after we are sure that there is a proper repository. Signed-off-by: Patrick Steinhardt --- builtin/blame.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index 9aa74680a3..e325825936 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -914,9 +914,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix) int cmd_is_annotate = !strcmp(argv[0], "annotate"); struct range_set ranges; unsigned int range_i; long anchor; - const int hexsz = the_hash_algo->hexsz; long num_lines = 0; const char *str_usage = cmd_is_annotate ? annotate_usage : blame_usage; const char **opt_usage = cmd_is_annotate ? annotate_opt_usage : blame_opt_usage; @@ -972,13 +971,13 @@ int cmd_blame(int argc, const char **argv, const char *prefix) show_progress = 0; } else if (show_progress < 0) show_progress = isatty(2); - if (0 < abbrev && abbrev < hexsz) + if (0 < abbrev && abbrev < (int)the_hash_algo->hexsz) /* one more abbrev length is needed for the boundary commit */ abbrev++; else if (!abbrev) - abbrev = hexsz; + abbrev = the_hash_algo->hexsz; if (revs_file && read_ancestry(revs_file)) die_errno("reading graft file '%s' failed", revs_file); From patchwork Tue May 7 04:53:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13656230 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 CAB246A8D2 for ; Tue, 7 May 2024 04:53:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057612; cv=none; b=XNCfZuAkBbCnoUlZoX+LuK8lxSpCv4G3cZ/Rh/MTjmrqv5IcfLbGSRorlO/KExWV75F2AMjHZNQ1I6NH2xDM4q6gFq1oLXSjGbg5BolQftQi7I05KitsMGExMlhw1AiIB1g3pM+uIAI9glkw2vvTm5KdDRADQi0x7N5kxD0JPG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057612; c=relaxed/simple; bh=MxkTOvUeYDsurSYf5qJiwM1COXlPupFAyybOcGj4bZo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GyCpQ79VXzvC8NBk4kZn+in7khGqONMnbLK7qGjwksLsGtF7GZ1mKH1JnGHxj6+5soCL3XHQ0nLqbs36TcGgxWr3sCYBLchOY4noGwuajM4/7VzkDeZKSRfZZSXrpWNnUL9OsCbuO7LKsO7rwmAr/OIJQhU/gLW/7vVxGmSCTP4= 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=Z4hIf2kc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fFpcw/+Q; arc=none smtp.client-ip=103.168.172.152 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="Z4hIf2kc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fFpcw/+Q" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 155DE11400BC; Tue, 7 May 2024 00:53:29 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Tue, 07 May 2024 00:53:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=fm3; t=1715057609; x=1715144009; bh=1EBXPu+Szj eLGiRqXKtCHQryxhm3tHYEFg6pBaf+akQ=; b=Z4hIf2kcA5lcqEz8G8JUwVxF+u /bcoAZE4lA/z0+UmGqBDGS6hTOUnxsWcc8L3wekHEZeMcfiEo8d/cx33b/CDYm9t e9ITOKU/oIR6Eho9I54tsFfEtB2apTf/FzlqUz7pcHPLGOiFpgHG+JXQdmBbjoK6 57/uWd37zne3ErT6+fS7KZv1RF645BJNpeWLl0C4182Z0fSVw+vGl4IPMo1YUvTl g73m6/CVFRbiQ13pt7dYr3PgvWJvliNZEkTD5BrmSWOVnDPQgkBTpDIbOu2Wf9Cz GGIhMM46eodtH/g4taiIS4HiHzFcqYeaZ76ToOIrS8Cz9feXSZ9pKGxFqtOQ== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715057609; x=1715144009; bh=1EBXPu+SzjeLGiRqXKtCHQryxhm3 tHYEFg6pBaf+akQ=; b=fFpcw/+QEQEj6F6S6c4MK5FrF+r4PLuLLwJHponUerKc gd3AUo69GolCPAIeM8DInIhBJEmy9ChIDndE3wA7ENvy0voEt/APf1jzE2poHncg Wmxq6za+iLeLjezrgoZlFqhpioSPYqtYT4hFGbwBkd/FLCwZG12gvriZz9uEfhiD kGapPi531g2KMK7VQLx0UTwoYo52oAYbcPRm4H81/z176QWGOzx7egFlLw6qJrDD qka4LMzq2cYBtGXlhBYwLlH53p6qQwRUh9M4MUSdzV+hOAayfS0VMgPi7pdwzrkg er1hUaXYbDxLN7sB/q6vSWbJcWlNuh7VCziVnmI7wg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvjedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 May 2024 00:53:27 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 64d5baf5 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 May 2024 04:53:20 +0000 (UTC) Date: Tue, 7 May 2024 06:53:24 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v4 09/13] builtin/bundle: abort "verify" early when there is no repository Message-ID: <5b4a21d2ce791a2ae45ce91ff3ae4f4a03efecb8.1715057362.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: Verifying a bundle requires us to have a repository. This is encoded in `verify_bundle()`, which will return an error if there is no repository. We call `open_bundle()` before we call `verify_bundle()` though, which already performs some verifications even though we may ultimately abort due to a missing repository. This is problematic because `open_bundle()` already reads the bundle header and verifies that it contains a properly formatted hash. When there is no repository we have no clue what hash function to expect though, so we always end up assuming SHA1 here, which may or may not be correct. Furthermore, we are about to stop initializing `the_hash_algo` when there is no repository, which will lead to segfaults. Check early on whether we have a repository to fix this issue. Signed-off-by: Patrick Steinhardt --- builtin/bundle.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin/bundle.c b/builtin/bundle.c index 3ad11dc5d0..d5d41a8f67 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -139,8 +139,13 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) { argc = parse_options_cmd_bundle(argc, argv, prefix, builtin_bundle_verify_usage, options, &bundle_file); /* bundle internals use argv[1] as further parameters */ + if (!startup_info->have_repository) { + ret = error(_("need a repository to verify a bundle")); + goto cleanup; + } + if ((bundle_fd = open_bundle(bundle_file, &header, &name)) < 0) { ret = 1; goto cleanup; } From patchwork Tue May 7 04:53:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13656231 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 3234B6A8D2 for ; Tue, 7 May 2024 04:53:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057615; cv=none; b=TbxzrVAC2u2+vfa2C/l20yjybGtPxtSKod+VTcOABPdMNsvK/9F97Z7X3Q1hs9jYMtRBfLTGLVIrJeB7VUegRgCo48czHsZdJoA3Vd6Q+/K8/PrmeLb81II8ISfZ1AwRW2gk0F5/HKjrN/4cEx/j3fo5rUhSMkZgDt7SfDI02Cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057615; c=relaxed/simple; bh=E51zcTX+liZay6CUrXNT74OlitW6o+CrYmKL5dThJFo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MGLCFJpBcWFgXD6eFYjbVNCBBU/9AGXKq5eRUbIxr6QE8sdnSu1CgYm77LzhPF+oT5ELaB1Zt2iHNtgZJyHuwSgW1LmRP+ods05VYLnUe9nWAEE33GM2Zp58mboTG1mOyuLRJlw8PLmhYBy6C4EqiVH6JZsLuCVjxSyI4jWWhr0= 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=l8m4E++I; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=AUZIP1h8; arc=none smtp.client-ip=103.168.172.149 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="l8m4E++I"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="AUZIP1h8" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 72CC8138024A; Tue, 7 May 2024 00:53:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 07 May 2024 00:53:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=fm3; t=1715057613; x=1715144013; bh=T5FQCQqFmr 6H4P8sIjfXs42aRmtm1ntm0z0T2ZcyRmM=; b=l8m4E++IdNgJRVgAiHZKPOPOQw YX3APwgpkYGtdGws2xmlIG+B5pV+m818SZgGgHkuLzvog/gNFiUq8AKyCcuAkkFq gXMG5Jz8VREEzxm6TLsnXBzJXjxcfQ0hspDES5thqzF6DxQ6oCXG6GfiJm8QN7wx IRXckuixPpNe8y94PhDoS/E0qbAeg6Ducz4Jo0+HkngN6O8NMVpoF2wkilYX1s6G cqaK+qWwZVBM+yV3/CvEUZ1jx8d3Irg6psMFkoiaMySbf0BrtmTAwQCiCHgz5Iw3 vxk+47xAamJvlpLHzJkirRIBPuBEbr54R+g1o89tUdz0cZ9JkStCkgq/gJdQ== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715057613; x=1715144013; bh=T5FQCQqFmr6H4P8sIjfXs42aRmtm 1ntm0z0T2ZcyRmM=; b=AUZIP1h8HfrH1Mh+BosrPOusyNtgMOv+gyz7Axidfor4 fOP/zq1KPf5mpsqqXp84Kz5FWIGlzRv2w7Z2NiogtsbcMhklHcfRKcMGKxFw9aQi 2DC05hznvqZBTtMn0sAhrC03nfPXMS+RNWDplkG32pF3h1HaHgyStDUahcWXBe6+ X45ujNuzSXqqM5tXornzgzXk6pUNZA4kSNrv0GpaUaxw3WiIxAEKhgNGbcvf0jk5 8nv4nWicQoT9rtCR5sODnyYbXtlYkaWbau2Vw7tzh5ezFBnOTmSBPEfHXuD0YkAL ORSvxE0hQVcFPHia/tGB8Q0BCaY+76+WGDgAF28BAw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvjedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 May 2024 00:53:32 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 5022651e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 May 2024 04:53:24 +0000 (UTC) Date: Tue, 7 May 2024 06:53:29 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v4 10/13] builtin/diff: explicitly set hash algo when there is no repo Message-ID: 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 efc37483b3..9b6cdabe15 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -464,8 +464,17 @@ int cmd_diff(int argc, const char **argv, const char *prefix) !path_inside_repo(prefix, argv[i + 1])))) 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); From patchwork Tue May 7 04:53:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13656232 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 7FBBA6A8C1 for ; Tue, 7 May 2024 04:53:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057620; cv=none; b=rIdVrhcH9UML4J6kj33lS743dhsISLEKA5n3/Gw0rahUWDqXjruXBgY0tjtlLg8s8BrGAyDje8r+LoPDYkk8vXqCooGfwrSAT4rmE0KZziM1yclHfb5FaHhOR/soTBzQcmQEiFvR4HzR2YeQLsjI9bmqMJvdm70hi/dNAQgXnW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057620; c=relaxed/simple; bh=um/ZiYIjRyHmiatTbwJwRJ62jGVzBwK3/FD+Bf+i6Ys=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sigArcvRelliaCIPJ8GQ33mlHf2TOl8gZnBsjpH8rQmEL3BXn7JaJNUyyeddj81Rgr30jsAmNoTW/hGqg7e5BC6DAElT5oanl2f6XpSw4PojZTOikUrhHV179H5J7yJSICsZ6SUWn6/hoAjKBFmEMGbW65muG2bCtahhpn2lNsg= 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=tO993VDF; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=D28jrKob; arc=none smtp.client-ip=103.168.172.152 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="tO993VDF"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="D28jrKob" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id D2A8311400BC; Tue, 7 May 2024 00:53:38 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Tue, 07 May 2024 00:53:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=fm3; t=1715057618; x=1715144018; bh=YxvvcvgkVU OqrSf9YV8Wf5dWTkAsYFc8yeRTzteR+GU=; b=tO993VDF2f/v4jHJd/5NsM0IFD TRZlnzreFrLL6lCG+u8DyXcTj4mVSpzAzFHEbr2eSXCrWqC49AH0BHqRdtJZLpds d7ojjzccWchR4Y9Ff2ZjxtubshdHSAnDsfwz/JLoeWMBuW1XudxDPKUCjZjN8BBE rgBfXQZg92YV/icYMKpZ63szziN1pEZtKV5lnwi+aUauPEcNff9ACA20TJePDyRx v1Lt9vp0cmAr3jxbG944WgeHwbls1eeWIsRQvSOV4Wm9LW3SCLxUhOQ3N7fg8iLH eSbwEuw08sqUmwWGZQV6EqPtXB30V2dmSH5NX+MypZbNvR0R9GmLRN/XY+gQ== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715057618; x=1715144018; bh=YxvvcvgkVUOqrSf9YV8Wf5dWTkAs YFc8yeRTzteR+GU=; b=D28jrKobbnXb/2nI6IsfyUCjXeVssrQDlcwkP60vs3bd oDA+aJrAvC7z22NBwQc2AGNq6VXCKdpJutWUtF6T5jfVcz6hKsdAnsP6C9rOiF1p Yb9qPPxP5ESvorzzGq8179Dk27NWn2fgtCOEl1zl98wf0sAKSvf3jAO5ld+dwmoP q26XJGHqypgT29/infp7cG9mgVgQgIPAsnw1GYLrAt+a4bs57I5qycIzT5MY5N/C Xwshfs0tXrSUyCHFDh1Ehbkji1jLxvbCjMtwmJl0LPPFw88R1VAsgomXaYc+I1F4 FehgEyou9ao8qUNyUg8xsv0rnqCgs7ZpDFK2D4N1pw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvjedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 May 2024 00:53:37 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 009af09f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 May 2024 04:53:30 +0000 (UTC) Date: Tue, 7 May 2024 06:53:35 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v4 11/13] builtin/shortlog: don't set up revisions without repo Message-ID: 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: It is possible to run git-shortlog(1) outside of a repository by passing it output from git-log(1) via standard input. Obviously, as there is no repository in that context, it is thus unsupported to pass any revisions as arguments. Regardless of that we still end up calling `setup_revisions()`. While that works alright, it is somewhat strange. Furthermore, this is about to cause problems when we unset the default object hash. Refactor the code to only call `setup_revisions()` when we have a repository. This is safe to do as we already verify that there are no arguments when running outside of a repository anyway. Signed-off-by: Patrick Steinhardt --- builtin/shortlog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 3c7cd2d6ef..d4daf31e22 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -434,9 +434,9 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) error(_("too many arguments given outside repository")); usage_with_options(shortlog_usage, options); } - if (setup_revisions(argc, argv, &rev, NULL) != 1) { + if (!nongit && setup_revisions(argc, argv, &rev, NULL) != 1) { error(_("unrecognized argument: %s"), argv[1]); usage_with_options(shortlog_usage, options); } From patchwork Tue May 7 04:53:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13656233 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 2809E6A8A7 for ; Tue, 7 May 2024 04:53:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057626; cv=none; b=ZhTGtJ9WsZ2geXGluC7jqyygSLv66FMUurVurwhu5PY7SN8PR95mqEwOaL1DEfU3PQEroXaQIaUl4cbTAQGXxjSD0b38x7hNE9woXaZ7Onsj64RCgYjvq20uYHymN0cAf5AVp+hynjtffABw8jcbmRaI4kiYTgq3UwgS6TlNJ5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057626; c=relaxed/simple; bh=SFkonS1Deut8+sOzXo3R7d2TU6wio+VaWoiIFo7PSig=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=e4estba4R4GyKMnXhgz5vK0HW3xM6IzNrzDjwG640BDj5+Je2iI4NVnVACH78Ye93Davfo4HgWnt8hhSFuHDfwxW0kQcGRiMw0xLjnSyfVzSLoMovGHZOUNnPGA+6EgAF9mWF7I8WSMJbPJasPDkloHmqosm6GccMjb9sH72XHU= 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=sf38DCAv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gLn16HZF; arc=none smtp.client-ip=103.168.172.149 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="sf38DCAv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gLn16HZF" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 3763D138024A; Tue, 7 May 2024 00:53:44 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 07 May 2024 00:53:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=fm3; t=1715057624; x=1715144024; bh=C2kQmGl05J jE+HaDHK30rr/Q7Q7WFj1mzvzVKnUZ6CY=; b=sf38DCAvlR7ZCiM3jG3F5rjO4J XPiYtmo7Z+xZLz83+xBzh+YFLiwqqME4B1bX0HK9AvENsvtbFPy6+NYaiblczGxo JDGPmPyYmQz3QN/W3N2LBQw/TOIsznm6a4RNMF50c6fPyeXfrLWwqVCsUurkGMUf LvzT/y+AU0tXBY4y0kY0VJ9syzaXSwfXV28BhRdY8O25mO+Hoxs7bulryTFzS57e Qtv2vtT96rzEm+10q5FRdrmUQom2+x3fdQBfLUySVmITsOzkIzDavACgJ3vojPtJ u4DX0UF0Aiq7s/FN+gUTJST9RsGgYlF2Np8vqOS7H6YfdlqZ4T27oZ+BjqWA== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715057624; x=1715144024; bh=C2kQmGl05JjE+HaDHK30rr/Q7Q7W Fj1mzvzVKnUZ6CY=; b=gLn16HZF4A/JMPu9q02WrxogDDhgIidgOwkN7A9x6gn+ j3B1YuOcfA7RjSf3OGHCJoYXRwhkO3A/SlYzEspWnuftby6UK3ujYXhs/uRXsUKY 6pQgPsjIs5g1NvBAfm52NCDinleKXsVBTB/L/TI0dFpF0S6w2PwpIz3Z7gKDFsWB YAObhBQkh3rXdLfNhVnX+iiRVNOMiYhzRmEwwF3l4/wOAq7ElNcLYlSFZSr84LCJ 5VQb8q8HwfZx+RIlm1T1Ohm2IiRXr5361Mw4Zi2zmg6C7hmc42ICR6DDXePngAL9 4dd5bwqXsE/Bf6HZFxGpU+K75+DW7JaGb3zC/bTlJw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvjedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 May 2024 00:53:42 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 827b26cb (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 May 2024 04:53:35 +0000 (UTC) Date: Tue, 7 May 2024 06:53:40 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v4 12/13] oss-fuzz/commit-graph: set up hash algorithm Message-ID: 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: Our fuzzing setups don't work in a proper repository, but only use the in-memory configured `the_repository`. Consequently, we never go through the full repository setup procedures and thus do not set up the hash algo used by the repository. The commit-graph fuzzer does rely on a properly initialized hash algo though. Initialize it explicitly. Signed-off-by: Patrick Steinhardt --- oss-fuzz/fuzz-commit-graph.c | 1 + 1 file changed, 1 insertion(+) diff --git a/oss-fuzz/fuzz-commit-graph.c b/oss-fuzz/fuzz-commit-graph.c index fe15e2c225..75e668a057 100644 --- a/oss-fuzz/fuzz-commit-graph.c +++ b/oss-fuzz/fuzz-commit-graph.c @@ -18,8 +18,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) * normally be read from the repository's gitdir. We want to avoid * touching the disk to keep the individual fuzz-test cases as fast as * possible. */ + repo_set_hash_algo(the_repository, GIT_HASH_SHA1); the_repository->settings.commit_graph_generation_version = 2; the_repository->settings.commit_graph_read_changed_paths = 1; g = parse_commit_graph(&the_repository->settings, (void *)data, size); repo_clear(the_repository); From patchwork Tue May 7 04:53:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13656234 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 68E796A8A7 for ; Tue, 7 May 2024 04:53:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057630; cv=none; b=Gh67dHz9hz4jItmxKezKffvFgnhnKdZLATUaA/ncEQs5MuP2Eb9K72CTqkGx80MhnPuJDimIvKh3DHDWOGl9a3HMIxFLZzQ5+ECCkE9S7sAF7NeyVI2KhqjxxDL+zDNLu2u8A0BSGksD/3G3ioNV/Lgd0YUX8VhDvrj5+ByndXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057630; c=relaxed/simple; bh=m4eTzM+HkFfPxdYmAwjVsJKQRsUj1U3ioXiaH+8A89s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qlVsE1l7oi/4K8BShIRAj4/Umzb+tCcGEO6dEARFiBKS/BFlgFzthmoXi7NNPJbafOg169EVz1k4xjC5EAsvuRc95hiNpPO0NiOzB/DRA6EGNTZ2j6TPe4Fq/ZLAQo2iDCmM4DdyEwmIE0XHR+ynZHTPMlvVQc3gEKo9x1B3eF0= 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=NgpshvOa; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=GD+01PU9; arc=none smtp.client-ip=103.168.172.149 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="NgpshvOa"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="GD+01PU9" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 7C446138024A; Tue, 7 May 2024 00:53:48 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 07 May 2024 00:53:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=fm3; t=1715057628; x=1715144028; bh=mvGNzcKym1 jNRBcbY5mALWha3y1wILNnyHEbRcy0bKs=; b=NgpshvOam0ZhM0+hp3zyEqNo17 4IlskxhhVCuqRhXRqwoh5e5DWZNHyQKkxnJPWwInH59UV1l9iQUknkDS4yvykLdS ToYs4/awVh5g+8Eej3YA3ABpvPdxfNerxSWt05CbGQCFFj314RmaA2wF3J3KrzVs nXORtjJQle6Zg+j8Utq9rgLZt6gT3qMPVwnK9AcgxJUlaB03tzSCzFOrewgrr98u osorgrzE2etk5ho2S/lapV3zM1WceVMfJ7+NOWwzLuIbEla7d4RCp4uV/0Rbl/Ff WbQM6xZzUspsgDuMpR3fdPsYGeeHNR50m50uTjIWYy3Xu0NM9SZ77MezKenA== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715057628; x=1715144028; bh=mvGNzcKym1jNRBcbY5mALWha3y1w ILNnyHEbRcy0bKs=; b=GD+01PU9u7aCV5u4c+do/qgHh6YJOCkH8Pb0duTVcYUG sBIP/lRfDwExT/KIXmP+0ABuqYKAEAWg3PrfpzoG4RnWrKaHNrAio1hsk2Vj9V8K JcTxrHElikdfmmt+/sPog0/jP63KC9UpX4ic9XyAJ8WVK6qkaTLTRC3H5Ccht9G5 l65/JwHOVipF9h6wAgAIudmYi4HbNGGdaFD31P2UVbBhBorhhQ99oOfrhs2D8LTj iVc9yysSBPDudkpkws7eseY7IycDknh+080Ke32OpildGQIOxrAzZ4jiR7ubOnSl Z3P5RGt0Tn51wQZeJoirZ/fs4U/gPJO+eI5bk6qcRA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvjedgkeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 May 2024 00:53:47 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 59c793e9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 May 2024 04:53:40 +0000 (UTC) Date: Tue, 7 May 2024 06:53:44 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v4 13/13] repository: stop setting SHA1 as the default object hash Message-ID: <950b08bc78a76a6f627698372306e2eccc0f3c39.1715057362.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: During the startup of Git, we call `initialize_the_repository()` to set up `the_repository` as well as `the_index`. Part of this setup is also to set the default object hash of the repository to SHA1. This has the effect that `the_hash_algo` is getting initialized to SHA1, as well. This default hash algorithm eventually gets overridden by most Git commands via `setup_git_directory()`, which also detects the actual hash algorithm used by the repository. There are some commands though that don't access a repository at all, or at a later point only, and thus retain the default hash function for some amount of time. As some of the the preceding commits demonstrate, this can lead to subtle issues when we access `the_hash_algo` when no repository has been set up. Address this issue by dropping the set up of the default hash algorithm completely. The effect of this is that `the_hash_algo` will map to a `NULL` pointer and thus cause Git to crash when something tries to access the hash algorithm without it being properly initialized. It thus forces all Git commands to explicitly set up the hash algorithm in case there is no repository. Signed-off-by: Patrick Steinhardt --- repository.c | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/repository.c b/repository.c index 2118f563e3..15c10015b0 100644 --- a/repository.c +++ b/repository.c @@ -25,28 +25,8 @@ void initialize_repository(struct repository *repo) repo->remote_state = remote_state_new(); repo->parsed_objects = parsed_object_pool_new(); ALLOC_ARRAY(repo->index, 1); index_state_init(repo->index, repo); - - /* - * Unfortunately, we need to keep this hack around for the time being: - * - * - Not setting up the hash algorithm for `the_repository` leads to - * crashes because `the_hash_algo` is a macro that expands to - * `the_repository->hash_algo`. So if Git commands try to access - * `the_hash_algo` without a Git directory we crash. - * - * - Setting up the hash algorithm to be SHA1 by default breaks other - * commands when running with SHA256. - * - * This is another point in case why having global state is a bad idea. - * Eventually, we should remove this hack and stop setting the hash - * algorithm in this function altogether. Instead, it should only ever - * be set via our repository setup procedures. But that requires more - * work. - */ - if (repo == the_repository) - repo_set_hash_algo(repo, GIT_HASH_SHA1); } static void expand_base_dir(char **out, const char *in, const char *base_dir, const char *def_in)