From patchwork Fri Apr 19 09:51: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: 13636068 Received: from wfout5-smtp.messagingengine.com (wfout5-smtp.messagingengine.com [64.147.123.148]) (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 7A66E7BB01 for ; Fri, 19 Apr 2024 09:51:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520276; cv=none; b=uqVTbAamTU7q+N/Awhmrig8Q7ql+xMX1B7X3U6pHgCIX/XaKwEyy7gKhtLe1HtwTkj2Bi/41n+o8kbjJKuhxSYekGmBmY5d+Aph9MA5wc1qcK6+DbRdVu4bkt2a/Drg/CS4vGWC4znyyriWTP69n0TXU3wgbZW1FikrqpFw1cNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520276; c=relaxed/simple; bh=BQcyCJAdnCIWQd1Gl1uede934WjBtMmByH9nTZf5pIQ=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WumA8Z7tsxE/+8ewXMM5oPpjrDzZ9q+B0GXPyIKkESjrIVsVVZeo9gCgGpW9/Qevtiqh5FLn6qXL+cwtH+7B7uyj5YhHeJcyndGyk90bXIehcKxyOL734TPMPRpQ1g0NlXc/AbXXv1RoRNxH6cjh1oMt73Z8fzwEXTKWgHrMoZg= 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=E9zuLhY9; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=H7DGWbWm; arc=none smtp.client-ip=64.147.123.148 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="E9zuLhY9"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="H7DGWbWm" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.west.internal (Postfix) with ESMTP id D45561C00148 for ; Fri, 19 Apr 2024 05:51:14 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 19 Apr 2024 05:51:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1713520274; x=1713606674; bh=wJq9K7g/wj Sy+aiO3mwHEOfHWBCcq6riUgB8PR/85FQ=; b=E9zuLhY9sw556ad1mWnM+Z1mIy Bb5PPU1ihrHyJsMzeZt5OIWLnx817WpwOJGjgHQGnvB3xzLOzPyuw8Jle2Zz85QZ 3LR/2IbDzo8x8NW6ZnPzsF4tVMRSu2UiumY59kBl6RI9Z+4B2iUtwnO5qHwV7RHC d70WETAy2qLhUvfvXPggdCP2xz7UmZYitHebi6JKkslpdwRPbQKUhI4gzDUL1Kf3 Dbz3kqMcDT25wsYN5DO6P77SXHdA6YQsROGRLfGGhc9XsDEx2lmK/VYwJFuqgua0 jlDvm6i1CuXKJ1oOl+epINwODs75UGVNoCnCwyAXdrGdeLkCrWJjNWJ/+o2w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1713520274; x=1713606674; bh=wJq9K7g/wjSy+aiO3mwHEOfHWBCc q6riUgB8PR/85FQ=; b=H7DGWbWmTkEJKugkxXn5pC6aFQn8tl5FQ6seS66aEru1 NhJ+3wtkRBs/YeyWlqH400ZZv3I750rGr+EzqY1SSaEaWk4kVXEnRIDUNw6vLthb 8qcip2jvDBudNolfp9GxtVd4zxatNkxTU4L4xA5qJh/nZc63o2u5NfriUByqzIld 2L78E/CEx9zHEALjawFHxvPdjSNTjHNcFG+O0Wy7miAHSkq4n++bspql6by/TsvM U485mUS9uQWmRU+RUab46KYjOGxRn2MxVFUqMRK9lP4xG33CXCqJRlIFstyYy8sZ SzhlaRcMMTMBLWhD6exmxhyZFAePEZ+6yn4tfV512Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekvddgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 19 Apr 2024 05:51:13 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 7fb2e957 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 19 Apr 2024 09:50:46 +0000 (UTC) Date: Fri, 19 Apr 2024 11:51:10 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 01/11] path: harden validation of HEAD with non-standard hashes 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 `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 repostiory 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 repositroy. 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 @@ -693,7 +693,7 @@ 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 Fri Apr 19 09:51: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: 13636069 Received: from wfout5-smtp.messagingengine.com (wfout5-smtp.messagingengine.com [64.147.123.148]) (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 9C8C07EF0D for ; Fri, 19 Apr 2024 09:51:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520281; cv=none; b=g7in81/HdZwPFlTc/Iki89E/v5A7kt2+gXGXTHP6WI5McmsWfxL7dH8KoTJXgRQC7LHjSghKIFlFbhLARYK+9ppLrYT0aHIlGo9xgtErhim1nYMgA+PFhE5CozI8mTy/qL8KzCbAbNDtCuOyyACZ42LUP+67iHDeDf/mCV+MozI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520281; c=relaxed/simple; bh=d5A/LlYiZO7YIwy6qOv+3uRbQCrk+UPy0OYN2xJQaoc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cJeWKKHNyjvereY7ixmQSI7/+MoJOg/KW8AaLDVPNT9OIyngtR2/ohcfnisUW42RTUhqcTid8uCLmcmTAtQNXZTZvsfB4QxQvFcQOf5gt2XF0X322VViSzZP+5ld90la88A+qBqLrvedsVPsFM0mJyG1405KGfJvbiPW3Jfa70E= 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=s+8U+aCT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Nry7p3Hg; arc=none smtp.client-ip=64.147.123.148 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="s+8U+aCT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Nry7p3Hg" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.west.internal (Postfix) with ESMTP id 915F41C00154 for ; Fri, 19 Apr 2024 05:51:19 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 19 Apr 2024 05:51:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1713520279; x=1713606679; bh=YfMZr7reAX e4PX9Qnk3B4tf2yY1EDDtJt1qVwkFjH0o=; b=s+8U+aCTFuwEBfVOU0cfxhHbaq vu5+QVGfGFYstzD8ZPHEdhaVw5Eq+pJGlF/LvFDd9IbmQzwqJ7wiiBa7OYpx7huk oCCDW58mqCv9XklRKNIDykYN3nXNL0HPnuADp1dh/u9bF461AMlmysjToF83zGaZ 41po+Zusm4v/3SdjduEo98SPxH0dOarqCp6pmZ9BDHzRP04cVzTaigJjwOngNmQd cUx0mzBqywikesPr4WT7rWIJWSsstu4SL46HVVzIW0xoV1iXMj5zEWdoHM/Ypyyu Z6D4kvpw10n4OKqvUzQDVoraVspaiiXe1df9yDG/T7fNtPU87KLnpwoZ9QKw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1713520279; x=1713606679; bh=YfMZr7reAXe4PX9Qnk3B4tf2yY1E DDtJt1qVwkFjH0o=; b=Nry7p3HgfRIYQ1Qxr1iE9puS53zeFYTeSb0YVM6Slt9o 3xpJAlkAwpvI2Q9yxboC+VyY3g3xCFK1DBRmfOTmjiq54Foqyal0GJ1PAGHGQ9C9 uEVuvpIIBxtFbX0PgAN3QvQtOjfmwSnTwDZ3aAeIToHe4o0zpEBVwE7jJiN5i07Z N6a5OEZOvs0c7IWueo4GBcgd+2iAyA6XWCm5U/x4DA7uMfIM+GwSrBz0V6DlGwU0 nn//Bo+6dUEY5m4ffHN7I+FQxSiIpaNJdf606p75Qg3u2BjJVDvGaJz2tWOsz7nS R7MbKhOoun7FrsB9XqZkRUkw/XteCU5oKXqptLWjWg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekvddgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 19 Apr 2024 05:51:18 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id bb749787 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 19 Apr 2024 09:50:51 +0000 (UTC) Date: Fri, 19 Apr 2024 11:51:15 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 02/11] parse-options-cb: only abbreviate hashes when hash algo is known Message-ID: <5daaaed2b961841d539eb88e104db57ed95809f9.1713519789.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `OPT__ABBREV()` option can be used to add an option that abbreviates object IDs. When given an 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 algortihm 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 @@ -7,6 +7,7 @@ #include "environment.h" #include "gettext.h" #include "object-name.h" +#include "setup.h" #include "string-list.h" #include "strvec.h" #include "oid-array.h" @@ -29,7 +30,7 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset) 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; 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 @@ -176,6 +176,23 @@ test_expect_success 'long options' ' 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 From patchwork Fri Apr 19 09:51: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: 13636070 Received: from wfout5-smtp.messagingengine.com (wfout5-smtp.messagingengine.com [64.147.123.148]) (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 0194F7EF1D for ; Fri, 19 Apr 2024 09:51:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520286; cv=none; b=QrMfyGlEv8ycCJAuySPe2/N2kHxnUX177Lt8S3fgvJy19ifSQNrPf5bZClh8YKbDNEhS1fE0PMFSllyw/w+GThydel6JQH2ijO/PHCqWqQKj260XVJib76BrCuiutt4G1pn05b0UbuPLLGh4bvNrAoul/SsN7cmC/4HLLLWfslM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520286; c=relaxed/simple; bh=Sqi5IsOHQj4VL0KH8ywbMnnrwarM5PJAMKl/XZy56+k=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nAxXeK8A7lZmJyzT1s3WFQILhrDO10Bxlz3KDTt3meGFjLXzBew8ZW+xWAYdLrWAZhH7tM9K4PgIBV1uluxOYeQxylmGey1DOqkgC43hcP/9N5Kl0K2G5ea11J5Qq/A8UaUmXrdte+nSvaPF4hpq8hDylEA6rerUTGmeL9h4vKQ= 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=aQ9uuilz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=BuBOljBZ; arc=none smtp.client-ip=64.147.123.148 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="aQ9uuilz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="BuBOljBZ" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.west.internal (Postfix) with ESMTP id 49B531C00065 for ; Fri, 19 Apr 2024 05:51:24 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 19 Apr 2024 05:51:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1713520283; x=1713606683; bh=+91OPIMdlZ sv806CmkuEY1Uu/HnAyYmOwciQVm6o2Rk=; b=aQ9uuilzMvlEh54Amj0iYq1gcm 7Da/Eqx74S2i4U7JBTV0mnIzpQxmta5GQn0c0yIeo6d+qVFwpStA75uQZTbF7rkC WAsR1LZZcVqiM8AJAms9L822nqx+QXIbAvAyD8IFfsCI9hRlykgBEKe0+FSSStik fIbmZsk5gWn0FmuhIIi639KShHyUwPTiwae77ojzI2JqZUVoyYRvp789e72piTFp RM/M65DLjt/HpA5AQ/wXgfTYsxCEThj5H0dvwN08jsEFBWI8D/vaY4ekCJTBxjYJ 3PeTFddze4zXjXCS5Igb220yL+IBfwITZ9iiWy10xNfL1Ors8+OO91qvqvuA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1713520283; x=1713606683; bh=+91OPIMdlZsv806CmkuEY1Uu/HnA yYmOwciQVm6o2Rk=; b=BuBOljBZ/Bazy5Ohv92P1fakyMBMzgUP7MEpqVlFDelS QsLb08LYVSalF26CQzwRcgACvSynGXTW8EEAwlpWQn2N61dlD7KC0so0q37/HpVD MdtUZw3tL4S2FEXOVOLh2YctIREInzzn/3EndfXkFgsx4qb+oFnuUQACNsVwx4xW IFN70XF/uPQMyCn/OwtBArCWRAfk8iHwoqZ1dc2zpicgd8jnbN6isRFTqehHpjuA +bKerE7MflvZMv2Csgff1Zn6N82tupmV66Ta4GoIAaRpm63m/A48hg8+NQCawAd0 YzEDE2Cvvxo5RDSEsWOR/I723lmGQstSDTzTXasIUg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekvddgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 19 Apr 2024 05:51:23 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 049e9f0a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 19 Apr 2024 09:50:55 +0000 (UTC) Date: Fri, 19 Apr 2024 11:51:20 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 03/11] attr: don't recompute default attribute source 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 `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 has 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 679e42258c..9d911aeb31 100644 --- a/attr.c +++ b/attr.c @@ -1206,15 +1206,16 @@ static void collect_some_attrs(struct index_state *istate, } 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); @@ -1230,22 +1231,28 @@ static void compute_default_attr_source(struct object_id *attr_source) 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 Fri Apr 19 09:51:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13636071 Received: from wfout5-smtp.messagingengine.com (wfout5-smtp.messagingengine.com [64.147.123.148]) (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 B08F17CF17 for ; Fri, 19 Apr 2024 09:51:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520291; cv=none; b=nMyx9MgCcLPLe3X7/I5FWAvxLPycPeGzAoB9a4Jj1YSPvCYSIMP+Qh6SeRAKm1OEj/Cq56E8H6Mvg0B/I2OCp8qepsKcYDrXrmorBwSjgkng3H0gFvWfQtzvk+1xk2oMYbLf98RgIaDkg8ekY0VreKfKbfQyj3Y+Bf/chyrKB/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520291; c=relaxed/simple; bh=KqXq2Xu+bSPdPJzPxdBlUECFMJvzyExtByOLQ2+gBDY=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nPxHbscZHGmfeO+r5ZrCqz6Vuk7YeK1xohzWWcK+/G8i5w5/FEcbu0RwKsyfOMPHAwmtq58uH6EpdL+o1lTl/3s1gdL5S4KytCaCq6EaaD+UfhkfxKtDp27TZQJtnF0I4vx8w8UjusjTUEi2rA2U1IAe+3DAy0TXmpaMDkQTYi4= 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=jsP4qLi4; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=BeCsm3pq; arc=none smtp.client-ip=64.147.123.148 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="jsP4qLi4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="BeCsm3pq" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.west.internal (Postfix) with ESMTP id 028501C0008A for ; Fri, 19 Apr 2024 05:51:28 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Fri, 19 Apr 2024 05:51:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1713520288; x=1713606688; bh=6+8uq3MDGQ VjY6pjK00jntgOR1dI8zDflctoRtJ4x1k=; b=jsP4qLi4aPbtYDUtIj0UwYXzNJ TGm8RTMtwOiZM/beIVvh6XVhg1VqsvXWDs83tagGrFluWl2pafbYmsW/F9suHf5H r8Aw/bNXh26Pn1rHdmlhJGchBD5Lr4BuO5feMKzAiUUlqBbgqTTrfwezKsYwfNwJ iUMWGJGp08bpRd+0DXb7ZPkXY9VdKxjSEYwwXldBNsP9frJUkXmAXhAxK+5dL3g1 WJbEGGM1JLjTt5TyzweAnU8juZ844bBWS44rXiiqsvIaTaVq+ehUwsJyyZArDtRS zEC29pm2aFU4K6nytHKcpaKhquEK3dW0KMYpzvsak+USgx/tQ1r2RbdCe6/Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1713520288; x=1713606688; bh=6+8uq3MDGQVjY6pjK00jntgOR1dI 8zDflctoRtJ4x1k=; b=BeCsm3pquHXNvMQ9PnEniX3RxpHi9uTkvRK8gLAwvY+i e543+bKFm61eYs2E/F8p605NCEsBtdMwtWcNs8GigFF5TNMxxB+ekp+YEgmqHrIi iJNocb96UF/NVif/i9dxozpXzB8/8n8kBXkEzD8xq5SLgyABK4fEfKx+4mrqvDRW 2odyrsEoJlY8YteM4gWU5cZ+Udi7Jifs64aw08IyIexWhEORbEKZOsL47Cmj8qfJ iaSBs2I1h2jnuQn0ZIZeSp/k6S6WOqNtEHz9hboXi9HNEM1/kaCwuhjnlCgiXkOi aAc5g5wo/KNGpy7VN1mVGTfFZmYVk1PeyADrOEdsDw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekvddgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 19 Apr 2024 05:51:27 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 419c4ade (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 19 Apr 2024 09:51:00 +0000 (UTC) Date: Fri, 19 Apr 2024 11:51:25 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 04/11] attr: fix BUG() when parsing attrs outside of repo Message-ID: <53c8e1cd7c62e641439b19447525194137a9285d.1713519789.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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 9d911aeb31..4bd09bcb4b 100644 --- a/attr.c +++ b/attr.c @@ -1234,6 +1234,12 @@ 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)) { diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index 774b52c298..3efdec54dd 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -428,6 +428,21 @@ test_expect_success 'precedence of --attr-source, GIT_ATTR_SOURCE, then attr.tre ) ' +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 && From patchwork Fri Apr 19 09:51: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: 13636072 Received: from wfhigh7-smtp.messagingengine.com (wfhigh7-smtp.messagingengine.com [64.147.123.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 965077F499 for ; Fri, 19 Apr 2024 09:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520296; cv=none; b=qfc1W33TXsOClWMBRIHt4uS5aJGqmAXBBQkIKPIjd29hUPCrSpFu5Xi9WzHMjKF+RIuTlG6EMO6+EJmz+stebczVrb5tHR1hwQKshR2MhHFRS8jOx/ZA1bMoVSPXCP0Jpe69pEwCokMCoYPTGeDPiAMzMW+ts8CI/Q/q0kc1O3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520296; c=relaxed/simple; bh=MJjmsqplFL8VDYSUFuiJ8M4wKfIXj7jSTU+yaF+FGLQ=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=miuY/beVkAE7MB2240ji17gftIqh3MljgKWRx2zvVljl5A+CZ01/0AjZin1uxB7ffKuPrmFVgNC6I6j4rFcasB/FsJ73xY6jSuXSKc/L586K2R40SvwstUm6ASJ1ajNSR2IELtfg9iAIK8CWSLM6bdEmZ0P4LpWfjNdUGi/ouvk= 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=kWsh64Wl; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XDPYbCif; arc=none smtp.client-ip=64.147.123.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="kWsh64Wl"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XDPYbCif" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.west.internal (Postfix) with ESMTP id B14211800096 for ; Fri, 19 Apr 2024 05:51:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 19 Apr 2024 05:51:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1713520293; x=1713606693; bh=uxJtBXlUKy MrsIw/cigzKcFa2mOXYyqTNB0W9iCI1uM=; b=kWsh64Wl06mhYeuPlt/+bgeUuE HXGOhssleL60YxBbi8F2mqANzQRNXumwbY2lON8YZsvFcJB5oPKG/H+gP2Kw6lQw TujW6SrLfs3IrKpBk/zqG3GvP63RSDGT4lQGGmlqm2PAr6/W8fr1jZ46GFQah2v0 /iXomXfA1kHgLrdxiHdXGx1r/qkByho8QUpzF+8agnVZbtRsA/SgpmMpYnHRgfgp tMel6Dwo0m7ENXTfMCfScM7gOdupqnr9w30gAQfs4Vmr0HZIOqXt0zEmebfxwIRW UfW0vcYiqQZ/LuCLB1QbmgJlT7a8b58VyhPya8rK1yOuRBQfcsed5eZ3rpCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1713520293; x=1713606693; bh=uxJtBXlUKyMrsIw/cigzKcFa2mOX YyqTNB0W9iCI1uM=; b=XDPYbCif6e1f5bPWYIFFoKpcpFzw8Z0bl0CqLWmWn77G e7T/CF8B57Fw47hM/eHstWKoYyQK4AhoxLO4VVrNsERc6BCjmtN2NHzV4ccRjHjx 9A7ee2lGFrR/zK9jRva9Ijh5YWd5Qu8KU77/diBvMcveYKDCJtHamKVU7WqpzCQl jH5Al3A6ff9Lm/YdgCO5B6/QHPkg11WdEKu33iJGO9PI4aj/yjpWzORCM81iPaUd phDXeCtQS44rLD/sEYssj3OIaJRmgf7SQPYLFtQ7b1JWA1EOiu+4uQ4OStPe47wD I2DWVeeXf76fv+KYMFB204VFzcp9yprTnurHO9QKsw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekvddgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepvdelgeekfeefjeelfeethefhheetvdejhf ejkeduieffjeeklefgteekieeffeejnecuffhomhgrihhnpehhthhtphdqfhgvthgthhdq ughumhgsrdhshhdphhhtthhpthhrrghnshhpohhrthdrrghsnecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 19 Apr 2024 05:51:32 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id e731274e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 19 Apr 2024 09:51:05 +0000 (UTC) Date: Fri, 19 Apr 2024 11:51:29 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 05/11] remote-curl: fix parsing of detached SHA256 heads Message-ID: <32a429fb60e4a7e80afdbcf9f874d2b2d921badd.1713519789.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The 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 @@ -266,12 +266,23 @@ 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) @@ -295,6 +306,12 @@ static struct ref *parse_info_refs(struct discovery *heads) "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; 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 @@ -55,6 +55,21 @@ test_expect_success 'list refs from outside any repository' ' 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" \ From patchwork Fri Apr 19 09:51:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13636073 Received: from wfout5-smtp.messagingengine.com (wfout5-smtp.messagingengine.com [64.147.123.148]) (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 F17D576402 for ; Fri, 19 Apr 2024 09:51:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520300; cv=none; b=kLwaLHRs97Mq0yhNCCkjzWKeh31b/8OVB3GGNuCs8Ihih8NYoMaZV+0n9DCYtghv3zGeQ+litNRI/lx1se7FLjLvEQx+sgqkWGQVPN7/jBBTdpX5qG2874gjFuE5CfU8jZO0+vFPrvAuZYHwpdQul8VrUQWz4zHzaGAAsbkY2PE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520300; c=relaxed/simple; bh=PONfmiGeRHTRM7v9AmD3ETWgTxwok7Ks6ZiHcgFPHA0=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=c2/Qdb3eNkH2l408nEWfVdRGKkE0HKgr648q4IuLKFwMO+gKH8tWZRYGUgLoGD30xGIueBafUGH9754qmPtOcoHS6S6CaBmw8Icb9dIp++wNLl9hm073M+SQ0NGvn/BnlL47m3wFgZ2gsUZElTIfRvxfgx7DPCA89HPbnSGk0Vc= 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=fKtxkdKM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Q4ntT72m; arc=none smtp.client-ip=64.147.123.148 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="fKtxkdKM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Q4ntT72m" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.west.internal (Postfix) with ESMTP id 6B4511C000CE for ; Fri, 19 Apr 2024 05:51:38 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Fri, 19 Apr 2024 05:51:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1713520297; x=1713606697; bh=5FVypehmGd HDkCBluyaMY64AfAPbSoZNM/Wr9qpEtvY=; b=fKtxkdKMYhn63fIfEte1ca1M3I Ix5nzWVOBRO0W3PqfFu2TR+qqkCir7FfrFmpg6K3Ye7ej2NquvA58ATVBtzUiyo8 4htxhNOA6oKiSzeTYbeKdgD8nqppg5UKnY6uzHKmYyDNSHkssWMwri4Z3gLKalhW 2B+g6tz/OktqTvh2WjLTBk+rYEG129LVi71YGKK0GuaJBccPybuMyj3v1ftjPtaa IBcSgp2PbsmySF92vcqZ5d5rhrxshvdMq8MzTUQiWks+neuQRSdztz73vA7YoS4Q gYn4EQ+RVRl2pKNqQpd2W8uJK4EFKcDu+vnI5t5Tk55FI+HtXQ/7YZ99w9MA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1713520297; x=1713606697; bh=5FVypehmGdHDkCBluyaMY64AfAPb SoZNM/Wr9qpEtvY=; b=Q4ntT72mVwErpxsXspDSd3EALq17cks0aAb60av/qKoe WGyZpx3Q+17JnIvk3/itJlKBIynSipVSvLmoGILEWajF+L+SLQD53+sN6gjHBVEt 7jYYG+XAOpWNO58Yau82oAq1tSWlT6Sf+DmK7sQtfOFooFVl8UrNyUpAgI9sBFwK 5//5L5OYenbVueJayMrY0l4AUHWsnJJjixOYYCd9l7+fbWTeiOrq3AWtc08FUFxy k3w88/3xoDqx1vWq555Q0BU+U76ZKtXP22fH8RcPs68Mzg8EKwSE7gaHmlKGznlu pyz1usWhWq9Mhxx4lvSTf5yFnKMw9oLRWwkAdsKLZg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekvddgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepudenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 19 Apr 2024 05:51:37 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 8733714a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 19 Apr 2024 09:51:09 +0000 (UTC) Date: Fri, 19 Apr 2024 11:51:34 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 06/11] builtin/rev-parse: allow shortening to more than 40 hex characters Message-ID: <9cb7baa50c6df77adfc2017a16883b3cb0c587e2.1713519789.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `--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 624182e507..d7b87c605e 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -687,7 +687,6 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) 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; @@ -863,8 +862,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) 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")) { 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 @@ -304,4 +304,10 @@ test_expect_success 'rev-parse --bisect includes bad, excludes good' ' 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 Fri Apr 19 09:51:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13636074 Received: from wfhigh7-smtp.messagingengine.com (wfhigh7-smtp.messagingengine.com [64.147.123.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F1877F49B for ; Fri, 19 Apr 2024 09:51:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520304; cv=none; b=qy/+r2botO0UzleREMra4sYFWpxraNuLgjJf2eDDKb43lELAawHn2fzcGvZINvcsvQLsUmxykJyXrNoMXrFtje2CrygmpelMUtnqlJG4/OvTQbKRuvan8gso9U1Mb+9avydn4yUO0EHiqyEzuUGlEKOi0zPvzZyWIJ/HfPgvLuE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520304; c=relaxed/simple; bh=7Eqtdk6lGd46dee0fWUHtgqfzuWnFppKS0flS2gaSQ4=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cCimVZfj2y8fdMkTglAszwukMcGdpufb8uKSLTLM/VcSmfLCk562a9e3a3H+xEMnPITiShYHelXgtxarmPpPW8lgpbMi1/OyZy6Y4Z2krTX1M5FfZSxSSyXcd9cacgKPm2G0zT2UmDy0rtFilk/y8+B7JbtTG30OCH9ewcAsz2I= 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=g1lgUQSv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PcVQpsfk; arc=none smtp.client-ip=64.147.123.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="g1lgUQSv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PcVQpsfk" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.west.internal (Postfix) with ESMTP id 2146118000D3 for ; Fri, 19 Apr 2024 05:51:42 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Fri, 19 Apr 2024 05:51:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1713520301; x=1713606701; bh=Ws+Icsa0m0 o/RElShCPyupFZx1DnlkfPmgMhf+7BEqs=; b=g1lgUQSv+YaHvRSujecjpsBFLU CsEMFgda298An6Hn3uii0E64Sq+RHSZwwnhJ9Hmhj1eo2HZGEPZcsl6yjgXUg0QA s1lzQys1erIkGAWtegHHXHz46xZLUw/dW8x97qgTVJ5duQkLdyioFzDICzIbOktq 1IL6SAVDmkrUDHXdyYK93oh1X1jZOsemD1vgUXC1VuOhxTqjZ+vuoAm7zulSn9RC TatccP6AN0zRJA641AFaVE16I1jzD0JbgsL6uMyjl5XEL6qM0i+2jx4O4N862o/0 CYGgA7nqxvgtUsNfTqTH7xQgFyPL1pyWicHe824ZYCfAgDw8rdGKkfgPY6iw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1713520301; x=1713606701; bh=Ws+Icsa0m0o/RElShCPyupFZx1Dn lkfPmgMhf+7BEqs=; b=PcVQpsfkBdToHnkVo4Amxal6CEvF1zj7UlxHMTCo/5G4 pR9ghhwWPSxBB9htliT2lY1tpZ6iO+MaUSq4UEJMJhyDGVdtiwyzBgi/W8B93e/l XChQAaSX7F4+SHnJPNJcU/49Ogx2msYJcpkATKUZ1HXzr81gPwXT0LlJsWkZnyrZ ayqjZAY++LoLmICYiAQiK1NJbOHMtxnAr26/8ESCWXni+i5zu3lFY6RjpVMRbvWw Bs3c33CGtUMG/tuVmSSigaEv23Rgtx6QzY1gyg1MWPg/dxBJhQpKEtac24Zm4DwA mopBtszB+jeagVPIwP03DQBsHOEqQHb2vJ57gHuNMg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekvddgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepvdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 19 Apr 2024 05:51:40 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id e83b718a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 19 Apr 2024 09:51:14 +0000 (UTC) Date: Fri, 19 Apr 2024 11:51:38 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 07/11] builtin/blame: don't access potentially unitialized `the_hash_algo` 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: 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 @@ -915,7 +915,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix) 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; @@ -973,11 +972,11 @@ int cmd_blame(int argc, const char **argv, const char *prefix) } 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 Fri Apr 19 09:51:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13636075 Received: from wfhigh7-smtp.messagingengine.com (wfhigh7-smtp.messagingengine.com [64.147.123.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3DBC7FBCE for ; Fri, 19 Apr 2024 09:51:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520309; cv=none; b=bvPtnC0staYz8quRzp5YeSP1mDHwwPAVYYA+qM5xtjrQZ93GU8UmoZCaX+VarJkvGijC6oRPlFfDDzBskjRSwjf9y8wLySkEzs0UAFEfEqQeeVJLUWZsJz9e7s0TlJalAEu8YhTqmSwR+/upDWLk0b+7N5HnjOq8XDjO6C+YG2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520309; c=relaxed/simple; bh=VorqWIQYVMZXnKL+awTu/3AWoDWOXwiXa4Iq3+348rE=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KNiKVqynF+xoQbTrv4PzXR9n0+i8M4u3kt1hIhJkRfTjDIieHf6oUHaAtYPQdOReBhl8Pd0S6AQ+Q8WOxPTtjAGtr9ST34R67a0k52V7j0VWZyHutTsZ1l+ezNkCtgsD3Ju9NctWAtcF4ZudAUQwJPNYBIKl/yRIPYtTlHL7ffM= 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=qFI0H7vD; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gPIZTzEQ; arc=none smtp.client-ip=64.147.123.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="qFI0H7vD"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gPIZTzEQ" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.west.internal (Postfix) with ESMTP id EA164180008D for ; Fri, 19 Apr 2024 05:51:46 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 19 Apr 2024 05:51:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1713520306; x=1713606706; bh=OSEIt4xkbg DRrJncCAIen+6gxaNbOxF7JrkRRQY91So=; b=qFI0H7vDASvdnsUyqlbO06KhkO AyJ58EmqphrFrgZqhRw9nQ8PKAfgBICRV9la+7r35dsOpCYHJMoFUeiWRN3aLCPs hjYz7DLN1Nie7PlwlHKINfR1EFkKvBat1a609xO5R3Ch+Lo36b/f2Qtka0E+VWD+ IxBOPFLZrJjFsXHEoe9nO46isUaQ8kT0BzmZJ0aWOBf/wocMMC70Xkp/7/3TKkQt /bXdSYVEkTszOpLVgz7+LAKGR2Ez4DVly67/1IHZM9AyuYid0/ZKEmdcrHfZSDdn kV+z+8ySraXCF7cDrMVnYl66jlhoX1MOJ/YvgdcPHomQ18fgCpau5ASmeWxQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1713520306; x=1713606706; bh=OSEIt4xkbgDRrJncCAIen+6gxaNb OxF7JrkRRQY91So=; b=gPIZTzEQjdfl2SrJCGizaaG/7IChwj6Y2UzJ2fgLqk8a v5xVWIkuBFhgRITagZA7TKJ0bbr88YEQs3+gLrLjT3tasW4i5+fimdEGPvh36gAt G04Q4s/Fn5Ws52BmFhOJG7YlIpVa7FwAlWAUHxhcefkM83cpFHWESo7MgJ+d30yq ozeWctt7map6uaABZxn3auZ95MeWIH4iceKZDCUpzGUxEvucy2REnfPTyTpaFSdn vPU5dUjM4tbZ4gEsX0Y6tJKm7FrNKBtFU4bIzHuSuO4GVslSUKiU+dRIZTEx/+vV joMGfS45+zsPHv7o5/EOSAGUEmhtV7WRYMKkk5J08A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekvddgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepudenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 19 Apr 2024 05:51:45 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id fe14caa2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 19 Apr 2024 09:51:19 +0000 (UTC) Date: Fri, 19 Apr 2024 11:51:43 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 08/11] builtin/bundle: abort "verify" early when there is no repository 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: 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 @@ -140,6 +140,11 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *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 Fri Apr 19 09:51:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13636076 Received: from wfhigh7-smtp.messagingengine.com (wfhigh7-smtp.messagingengine.com [64.147.123.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C06B80020 for ; Fri, 19 Apr 2024 09:51:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520313; cv=none; b=oqFyVfZiybfrd3N3lu1dGS8alfOTpX5pN3STXI0JAXd1h8dOIUkEmdSfExUgC7kXEw5ggVXp4q7tqwF25dARjijaxrDGnxJtQjxImfIYrUP864tY//AN7VF2KoWxICYMXOpqaRDcMygEfqBLaBhK6Ezi7/VerftTzXyAxwCSIbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520313; c=relaxed/simple; bh=5pWIr8ZAVZBb3u5AI/noPd7aL7JD1V4atl6Au/vVspI=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=u1dauAHA/wjasWy9vVtSFwFaW+cj4Qt859copUb/VKED3bS4jNRPZOC5t+FwjQ0fwLIVnfTb8hGY9RoSopeJIm/P+iVtocv3DYP0k7cd2bVQbDboDDw1YeIOLlaZtcvmEOLLsI2B5ZDbKjTZvtXjlQiuXy5eGbQtEUNbkRn6j6g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=aGvKy020; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ALGcu+H0; arc=none smtp.client-ip=64.147.123.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="aGvKy020"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ALGcu+H0" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id ABD0A1800095 for ; Fri, 19 Apr 2024 05:51:51 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Fri, 19 Apr 2024 05:51:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1713520311; x=1713606711; bh=bHmmacWlTO bewMKDDGwrn3Qz46ifsBO7sBiNKa+/Fbk=; b=aGvKy0200WzsAtxWNfGxsgFmWS XRt1Tz8cIR7qdKMxGljiw+oIJNH8YtONTPp/tpiwGpHx3s8Ydgv9ZgihO+VwdGNi e+MOGPYjJVNrXcfP9qAOs5eFqYw01nwHomv2XbzFYDYskYPKdQy9DZJlKf0SzVtc l4ya6Bk0XC1ePYYPx5jl4EhTfGkmrFUWsTIA85sLCFzDvgvZB7FmYsuSvwRcHgWO ULpIJVWtpN4lw458aa5jlNXB0Cbr3Xke77PrVsG0nlG48tNx60ttyTiJ8Pv6Rluz WYrO2l2ApLUlE2xWfZZEAkHkBTyu50F88WMl7m8ap1O9OadBNgP8ToJTus1g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1713520311; x=1713606711; bh=bHmmacWlTObewMKDDGwrn3Qz46if sBO7sBiNKa+/Fbk=; b=ALGcu+H0FWiKk0CZwfFkVdYNsUbQ2YTplMJnqrmM3tyl uaS7vSFYCDL7OfJB1ILY2wKQOQB/7LsMjkb7k7lzlU0v3LZfDjDronGvju1RmQzb QsSFb38FCbi7x6uweMmg0KQMlZBx8E7RmIVTVxpo36sw0KX8fdcIT5OxrG/mLPK7 T90t9WNQwVa7dZunhsMDhd6xbKvqzcEFG0qDsGD7csCtLVFLZuR/jBmIgSB9BCmq O96UBf3PjmhnV+VilSvn5/Ibeap6JK9L/2QBS9UyopILUrbCIBx2aLHH4XTqNtUs l61JBs6qIfvBaCu9BCJ+dpmInqVp/QhfoD691Gssdg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekvddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 19 Apr 2024 05:51:50 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 718e3080 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 19 Apr 2024 09:51:23 +0000 (UTC) Date: Fri, 19 Apr 2024 11:51:48 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 09/11] builtin/diff: explicitly set hash algo when there is no repo Message-ID: <39e56dab621a2a1e0cbaf67f8de44614c354dcb1.1713519789.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The git-diff(1) command can be used outside repositories to diff two files with each other. But even if there is no repository we will end up hashing the files that we are diffing so that we can print the "index" line: ``` diff --git a/a b/b index 7898192..6178079 100644 --- a/a +++ b/b @@ -1 +1 @@ -a +b ``` We implicitly use SHA1 to calculate the hash here, which is because `the_repository` gets initialized with SHA1 during the startup routine. We are about to stop doing this though such that `the_repository` only ever has a hash function when it was properly initialized via a repo's configuration. To give full control to our users, we would ideally add a new switch to git-diff(1) that allows them to specify the hash function when executed outside of a repository. But for now, we only convert the code to make this explicit such that we can stop setting the default hash algorithm for `the_repository`. Signed-off-by: Patrick Steinhardt --- builtin/diff.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/builtin/diff.c b/builtin/diff.c index 6e196e0c7d..58ec7e5da2 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -465,6 +465,15 @@ int cmd_diff(int argc, const char **argv, const char *prefix) no_index = DIFF_NO_INDEX_IMPLICIT; } + /* + * When operating outside of a Git repository we need to have a hash + * algorithm at hand so that we can generate the blob hashes. We + * default to SHA1 here, but may eventually want to change this to be + * configurable via a command line option. + */ + if (nongit) + repo_set_hash_algo(the_repository, GIT_HASH_SHA1); + init_diff_ui_defaults(); git_config(git_diff_ui_config, NULL); prefix = precompose_argv_prefix(argc, argv, prefix); From patchwork Fri Apr 19 09:51:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13636077 Received: from wfhigh7-smtp.messagingengine.com (wfhigh7-smtp.messagingengine.com [64.147.123.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 594527C08E for ; Fri, 19 Apr 2024 09:51:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520318; cv=none; b=p2FbEbBqrTtGLAE21RZ4obmzRpiRGSxHMuzW86783TgsCwJF5o3pdg8yv0peBnOtPjmBl0KPzgfwik67dMsmIb2w6JpuA7h1MuZhHFsRt/W5JO2vT9c0Ufg2uOes/1dUhGvot3/sn9x/Q8orYZ+jekVx1dc+Q5S2bcxNtTKEbXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520318; c=relaxed/simple; bh=BomxAql219KiCcUf2UPYs0hdooTVxeLtzqX3+SWqnbE=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=i5HinQIng6XBYF3RBYn7UjFe6x+IWbDbKZHndjURAl223VG21oFdkwP0g3mLBkZp1lXttHcQHyFGMDrQMFTVcqKAlX6nDIlDcXfrII3nsd6abHPA//fL6ONFAsBJ1cKYd+vsTPdvSh9RSVQ2Ik0ZljY0E8VrY2wVupYti5IfU8g= 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=nhC5G2FR; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bW5vjXww; arc=none smtp.client-ip=64.147.123.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="nhC5G2FR"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bW5vjXww" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.west.internal (Postfix) with ESMTP id 70D2418000A7 for ; Fri, 19 Apr 2024 05:51:56 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Fri, 19 Apr 2024 05:51:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1713520315; x=1713606715; bh=6vpZf8ZGqW Koa+XaQL0ADDhbgXDCtyX06uA3fpwJzlg=; b=nhC5G2FRlxDOllkkVU9vWsU8wN Pxnw85NBzuEnVOFcqRPXi1vVMNL5wj2X31Obsk1B0SsLioC3zNFqPQxhc32RJBTc 2fwrKA4OT3oWJCbSvQ2ZAeBf9bka/F4nyHtyVLzcQ/gUGOqW/6N5jp6EdroFq4f1 +9/YL6e1fA+IX9pn9q5uQYzWDF8y6tXWGCcemHlE+9kxxps2NLgede55rOZ8kMDN 4cqnLe8fnBP38AX58Rdh2o844QB5FhBk8TgduOoBVLIZZ8pTVVeNh86eh46ZUwtJ lOl3288wmvQDDErtA/flqinAHL2AySe/VL2SrvqPTPjj+u0HrQt0rFc/+mGg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1713520315; x=1713606715; bh=6vpZf8ZGqWKoa+XaQL0ADDhbgXDC tyX06uA3fpwJzlg=; b=bW5vjXwwDLIJeJ/uUqLRlY4E/EMSvJ9nw85CCAwcj5XV 6Gc3oN/M70vKqj+x64D1KxcETeGlKv7FBCa9bD4FjPS9z9tACL+Xw58XdYphTIx7 E52f0RI3ew0igpn8SroNa5gM8jVLAw8g6C1CncNSCnAFbaYhs4+box03CbnaPEWx UrYjMv9k2192YSR67Vh0VhSLrEPox8rr7JYO8okS7K+Vu14s3ESwbQGmmz3nNUQy 9TWt0qE9FwnEm+L5o9O/Wvx9swcJ4azdfhcRovFHAX5O4515K9YnKyxhYH16xutc 7oouio4shbk5o68Uq834NcaZsPIBULqYdxKXKLC/1g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekvddgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepfeenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 19 Apr 2024 05:51:55 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 124f7516 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 19 Apr 2024 09:51:28 +0000 (UTC) Date: Fri, 19 Apr 2024 11:51:52 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 10/11] builtin/shortlog: don't set up revisions without repo Message-ID: <508e28ed1e21e9c646cec8473a65137d33f1df23.1713519789.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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. Reghardless 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 @@ -435,7 +435,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) 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 Fri Apr 19 09:51:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13636078 Received: from wfout5-smtp.messagingengine.com (wfout5-smtp.messagingengine.com [64.147.123.148]) (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 1906B80BF3 for ; Fri, 19 Apr 2024 09:52:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520323; cv=none; b=YTXpg2sUHjyw7jg62apwdwYequ+ZvtaohwSVL8w8KjWM14u7Ouj/GiN3I7fO6wTmtJNrzq+jhoTvmZ73Jmyb45a/bFYsg4KGBaIO+0WKTYJ70cjgxOCdbqAMRu/R1hvkzt1jO8UFRa98N8tgOQovy2Gm7K7Us/Z3zYoYlbcDSVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520323; c=relaxed/simple; bh=5JTYXzFQk62mTmsgeQkqpATIExe8gePNDzfOGW08YRY=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=s23SBuctr60nezAvItV5xgm/1G8mWb3a1otAe1L7PG0Heq/IYAhACiuP+KKwnYz3kUyvjnzLA40ZcYiVWcqYIrXgIyamTkkZYCshfNRyGJxlqi3Wa23RYDzETB86N/nkgUcL6WuPOOTEj9bTplpYTWVMpHU4ZLcUNLFHTWE0eT8= 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=rxDJLcGc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Yuinbsnl; arc=none smtp.client-ip=64.147.123.148 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="rxDJLcGc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Yuinbsnl" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id 32FB71C00101 for ; Fri, 19 Apr 2024 05:52:01 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 19 Apr 2024 05:52:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1713520320; x=1713606720; bh=GSrw647tXA LmlW53RqGKmtmsZCk1pmApVoVZpiGYsfM=; b=rxDJLcGcyoLNMIg6Ps601vkE/X eR6/KAIlNTtduOlwYcCRNJLsWb0ujFSTuoQda4vAsWOMUNLTqPGffG+8i2fJD6xy V5Hs9mJaVHK2QKLTzBVYQbPgp/1asq5gbbS9VHfH93FPAP3QPs1vnIn10d7OlSaw VV7kdWh88DD9zpvwQxE8XyCE/anVBlIZkgbpGVEqeEX+Lf6+d/Fr48TW4u85dhK9 doXUyMrQJrLG/KoFbioFs2cJK/eFmrrZrSGxfI/ba0dVol/oryfnhOel2Kheyayb YA1gBkPeAb9lw4K5wFecZdWlnYhY+ggSVMFmBrGpFjFB3qeOlzSAPhlBGQ2w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1713520320; x=1713606720; bh=GSrw647tXALmlW53RqGKmtmsZCk1 pmApVoVZpiGYsfM=; b=YuinbsnlVh+S/l4i1oPqLV0xvXGT5yU67z+mkCeKYz53 xnGliBBNyJN9liAGGvwy1rMMd/aj9Bhm02YCtDfKs9E6+GwmZaX//2eGh+gw4Oo6 AvaHtL0HyUyBTLHG9KjhiVRwBjk/s5UfGA5ev6tV80B2UTNa7Zlg4A43ecEMe78f xqAca6DwfjX/dVaoOVoci+87o5nP4Qw4eUWDpY8nCP6Av1EoQ8tthdl82eiw3Z8t bdTaaDwRXaXlmxL3B9lqeC03QzQ9jMNtwW5tSpEJ0x35kqkiImOKOBWLvOeGdUVl 2f049EMtjSRRUIIJgxqCdIFxRgHtV5ZJwlHKnznhsw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekvddgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 19 Apr 2024 05:51:59 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id ba95ce2f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 19 Apr 2024 09:51:33 +0000 (UTC) Date: Fri, 19 Apr 2024 11:51:57 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 11/11] repository: stop setting SHA1 as the default object hash 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: 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 | 2 -- 1 file changed, 2 deletions(-) diff --git a/repository.c b/repository.c index e15b416944..b65b1a8c8b 100644 --- a/repository.c +++ b/repository.c @@ -35,8 +35,6 @@ void initialize_the_repository(void) the_repo.parsed_objects = parsed_object_pool_new(); index_state_init(&the_index, the_repository); - - repo_set_hash_algo(&the_repo, GIT_HASH_SHA1); } static void expand_base_dir(char **out, const char *in,