From patchwork Mon Apr 29 06:34:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13646342 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 CA46810A09 for ; Mon, 29 Apr 2024 06:34:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372460; cv=none; b=Js78eU8Wjb96Y+kz3kE3TrUjwK5rieraH93GI+9Zi0S81KvzajDsEYnwnYijvImTftPC+oP/gWAkGYowrKM5TPZdllaTQt4SDRg+P5zlEn6ilB1CgAQ9rw909uRtPlpCK0ueVtnHF+jZpj0+kUrhtQ/P+LVByreHj6FDRowouiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372460; c=relaxed/simple; bh=d1Dn3I3xfnLEPKudiY60dhrflIRa3n03bCWMQLa4mX0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ro4/PWFA8eYhNQEMsu5hckdhQffhtct5KuFM5JTqV9zPFtO+wpJjD+/N11aIGiK4MpdcffzRzsPiWQqiSveb/wxLg4QmBQem+yBCVMghJovOU/7H+nyN8AYUWs2MXtSaVSIX5fbAbWj4aoO+sjRRKsm2HicL+UirD0RKbe51lSE= 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=exVL4NWk; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=DzGaAMOa; arc=none smtp.client-ip=103.168.172.154 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="exVL4NWk"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="DzGaAMOa" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id C25AC1140130; Mon, 29 Apr 2024 02:34:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 29 Apr 2024 02:34:17 -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=1714372457; x=1714458857; bh=D0ghfovaq2 0IIn5GY0Y3kJWG//lxFNukmGwIdIwSSdc=; b=exVL4NWknlGsb6FTNb68CIgTqz uwsuGigsAiObAZLZV7nM9GZtidBei4tEZcZ+C9NrMc2p19e8NM8CmctPnJXSuITt Jx4QdBlcixUn2acLk7YMStNGLFI0gwVMyc2lCThsV+A3vhL++EH88laAX681YP6R yKI5Y+SyLm+SyffFGGMNPz/kEczHDUi59xV8T6V/9pJAT/vwqhBYLdS3n+AIzO6X gBVTvNwqdm0Y4z0FisqmBozxjSm7xRuzPFZpmvGXVnaRP4F4qCd7I/j3wqBoBAL9 KTW/Cxk/Nwbra1STYEUAvYnlvTCZRIlsgOW7Gq8LxjRKNXCnYvlpICQIXoMw== 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=1714372457; x=1714458857; bh=D0ghfovaq20IIn5GY0Y3kJWG//lx FNukmGwIdIwSSdc=; b=DzGaAMOay/rbED9G8z+pTwZsKB2VDDi14wbGKzZ3I1rg sG48WRyKNYZG2aYpR1jZSFROeuxYE8kuWdiiuJgr49csd+mR0p3/H7+6VdrgaFLx BZ5D5mb9uQsBF96DX3rvhvlqhv9XbcD2309VDNbPvwMpRYslYFQ5QtJI5nzTJGxq tAz+C3dSvpnHOULyKh9PRHjGhIpIBpivxSALslTISbhNo/oPHrp0uctxDml39sck /C20zH4zwWTnu2Gzy1QMvWa1EWrfgSevFXZKOSIOZlHHco2+OcZ1Z1HGwfvJx8UT i2QkNB2ZHMGvA5vEKVMhx8KYCsqL+vM8yk+Eg2AViQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddutddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Apr 2024 02:34:16 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 5dbbcfbc (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 29 Apr 2024 06:33:57 +0000 (UTC) Date: Mon, 29 Apr 2024 08:34:14 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v3 01/13] path: harden validation of HEAD with non-standard hashes Message-ID: <5134f35cda5ab47429411293dbc0a987a306c9d1.1714371422.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 @@ -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 Mon Apr 29 06:34:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13646343 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 E444412E6C for ; Mon, 29 Apr 2024 06:34:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372465; cv=none; b=gq1I+DW0HdWzjde1Lv/lH1p2S965xR5HpC8vN+VuHQs6Tiqhq5/4VPsaj2EOsGHkyRqswBO0XyClOSWbjzgFvhcFLeKIR/b0jKJj4qpKCqio9ICWdWY9+pLSF7TH8Kqczh0UlmV7voCE4aQMr6b04e6nyLxcl7thoC3I5mqegaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372465; c=relaxed/simple; bh=hzAUqwYVuhPIYWWYP8bBt3yVGWUwzLNc6EQ0Ldz8+yc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RUET31IFedmhRZzRWEB3Wl7iKcjL/Wj93FTN/bh+xrr+afpI3zQ+NCcuCSrcVuQCmtdw2VE9c13KfOZ2S0qvu+waujEZ4AsJ87shGED9Z8Ndvi15sODBhO7LhzP/9IA/I8KcLV7kTmdhvuEcvQEv+tyw0eTKsjwEFh5YRD06TNc= 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=PAI6k7DX; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=GrQiltKb; arc=none smtp.client-ip=103.168.172.154 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="PAI6k7DX"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="GrQiltKb" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 02E0D114013A; Mon, 29 Apr 2024 02:34:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 29 Apr 2024 02:34: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=1714372462; x=1714458862; bh=8g+TjoU8t9 ypQnLOQD3udlc1e6VSJOF+bZzXtimWr2s=; b=PAI6k7DXCiYSVzm+g9yOTEcHO6 vBR0nmS1CRx2NQzQvlclc6us2fgf2pr434IyWm4I8BiqXZff/z1qArgtooK1DVcR lqnn9MQCyjusbm08VQNFZvGwsBA0poV6gypNDrWpfgsifL7S7r6kkjJDdXKmL6CM Gk5KbNkZgMZpLZX4oEgWOUxQd/az7ueq+2C5h3wv9PaPlvvPFk5TwTGeEFrUyXKL 6MN1M/3tvP96b8VdMZuhI3r2A0bYNuCTkFE8x8khCeigWYjkhohAr5wLNC/H5A55 9crk9QGxYSxxlSD2lzLwizeo9DwHu3RHEKuS2krS4IfqLfHbSsXfciwRw4fQ== 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=1714372462; x=1714458862; bh=8g+TjoU8t9ypQnLOQD3udlc1e6VS JOF+bZzXtimWr2s=; b=GrQiltKbtDFFdqFCIk/snsUuTxE4EYzF7+DyuUfZK+7c AtedZ7eqtnrvgLQJLPbsiz0WgSk14Nxx0Km61iPbRC2lJtO7kX1mRJUBN/f2tWej 1PrRG26gbOayK+Jq7peVfrFrSQnw7k36e9hwZENSCARKaXHBXX7Xe8W89GJs/AJS 4WAFFCZuQMs2XzbqnTar6c11B2a07vY60cc2jYlKw8f1gMYiN4gZpkKBHIlUSDVz 9zT1d2drlT/nL3atOTAdLPXF5yDuCXP4na0BxkUzYMjBc1jK5NI02i2yBZ0mcms8 z46NXg+8UJ9vANd5LWyZ55t7uKtUQbH5mDNZPn3eTQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddutddgtdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Apr 2024 02:34:21 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 0b9b6f41 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 29 Apr 2024 06:34:02 +0000 (UTC) Date: Mon, 29 Apr 2024 08:34:19 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v3 02/13] path: move `validate_headref()` to its only user Message-ID: <589b6a99efffc9d3f5800cc3dea8ce3367d1e9fe.1714371422.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: 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 @@ -5,7 +5,6 @@ #include "abspath.h" #include "environment.h" #include "gettext.h" -#include "hex.h" #include "repository.h" #include "strbuf.h" #include "string-list.h" @@ -647,58 +646,6 @@ void strbuf_git_common_path(struct strbuf *sb, 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; diff --git a/path.h b/path.h index ea96487b29..c3bc8617bd 100644 --- a/path.h +++ b/path.h @@ -173,7 +173,6 @@ 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 @@ -4,6 +4,7 @@ #include "environment.h" #include "exec-cmd.h" #include "gettext.h" +#include "hex.h" #include "object-name.h" #include "refs.h" #include "repository.h" @@ -341,6 +342,58 @@ int get_common_dir_noenv(struct strbuf *sb, const char *gitdir) 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 Mon Apr 29 06:34:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13646344 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 3A21B12E6C for ; Mon, 29 Apr 2024 06:34:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372469; cv=none; b=Jkqr637yVLP5XmVvCLJff3wxUlmR3U/ySXzmb/gSi+qTFSxTlSHSwBpP4SCXIzOiPQPQbR5rjxQc8DIAH0IMyBdQLz1ePAcGiS2wv7Cmjk8LAp1vdaYQfLRK6qOSTw3JXgziQX0Ucx1L7SepsnxH7sxvAlK1dDx21H7y9AjCelA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372469; c=relaxed/simple; bh=lq1/Q4NcbAOzb4qnG4cjgoWsOJzEhCV4TB1a9vrV2fA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qtObgCvPjXRr9psb4k5cBR1KYnd8/gE/Ws2zVYyEZCsrau8NIj4FZ+PtkIBzGrzsV4mtubWT8ZkRqEkTVym/78DO7U2ZqsJD7WZT0LuA+3IwmLDFrgTWI6pHA0mSjveX1xQzm0Cs2ZCyMVU/xk+rtR1D8Z8Ha4GZhu/4CKwCq6A= 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=E66zncUk; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=EXx7dv0m; arc=none smtp.client-ip=103.168.172.154 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="E66zncUk"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="EXx7dv0m" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 37CFB1140136; Mon, 29 Apr 2024 02:34:27 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 29 Apr 2024 02:34:27 -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=1714372467; x=1714458867; bh=u2I5oCWjaI 0xikJwQ7ebCKKH0awgUhxgKfsdpvUWxWU=; b=E66zncUkC3IzVyzVgolzVRVk3r tP3JPSA0zegD6VH/pyatNm10KBDunsmgcsWOJq25hL+bHlUY09d+pzq7WpYxy/tv 1NGmOqYtRz1xU7zm6rSQEbt+bUq2qDkHBPNpoUUbcuxqZffbwhwhoP40LxvMukNl D4ZRxSK+JBpidFv8z/tNfZ8hH1QhLHh5lhIf8L+t0pyGbuI/ma3O351lrk3Po+HN Y3LhjXkNqkNqDnNhVspNnF1C9tRSPkJsfjvb4yYTY3BeCyyeuCoFhPPGFW2Ewpqb HyEPUvJ6G6LRHDtGXaUpSCQ5tiqBQJFW8lZ8xk0eJlfOlRc8ZoFtJRnetuKw== 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=1714372467; x=1714458867; bh=u2I5oCWjaI0xikJwQ7ebCKKH0awg UhxgKfsdpvUWxWU=; b=EXx7dv0m8bUEWKJ2xIx+5RUy+0OwqcNT1fuL/+yAqllp u3fadJ4b3PDa25Nt4O4sFGSdIL2/uWDQAc64K8rS/clwVKQnjCiiiJTLOwcVHrhF OrFj6TVyYOAdAXYouod4XjAq6911GOpYkiqhW4/cEaPrgn7J2O9h7muPrrPM8PmF CVh7KQJhxIRjIK4fbrNqWEIxCLE2Ah+ecTPTvApL3e18mVDG7mHMtmeZSvvW8Ffw e949+kahE223t2teVWMOoAv4+wFy30GKkhqhbKHv30WjSXZ2x3sbYpIMgReaQMRd zb58+UHHDG6QRTZNLixX0AJ5BykDMQkB30msdy8iGQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddutddgtdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Apr 2024 02:34:26 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 31754d62 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 29 Apr 2024 06:34:06 +0000 (UTC) Date: Mon, 29 Apr 2024 08:34:23 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v3 03/13] parse-options-cb: only abbreviate hashes when hash algo is known Message-ID: <9a63c445d21fb6d9179c6fb8a96e0c221ddf16a4.1714371422.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 @@ -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 Mon Apr 29 06:34:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13646345 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 64032134BE for ; Mon, 29 Apr 2024 06:34:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372474; cv=none; b=s904CvmuN6wwuvUO1YdjNp+vdHPtfMNVVdoAcozaWJrRMgfvj4pGn53QxxLCVPqvco8HG/ZfIEZ0JlmMngQA7mqVoY9ZzLszWZelU1ePa54/F7yRUr8tzQUiJTa0a/nyodD53SQAYjDXnLKCFQbq9/Hzrtio8eNta9LBx9oYHFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372474; c=relaxed/simple; bh=p/X1yBt1q08IomtAyxeha6FvfE6uMvpiNgZujoQk9Kw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RfKX3rm5tkVFP50PJVbciL1yNv6iI6HhIF3w+odS8RxnKdeXhQ6LMXnz1SkeSXbl9bx4w6VbdaTZcDCfMuDVd3Y9TKv3tDTmvg7/aGdwgSukIegAtd+OdBhbFuSoP5wuSWciWU/5T5GkCilAwSKZ9KITEFTe8CeVpVaXE3cKUTI= 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=C3EdX5ce; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Oo1yp3zM; arc=none smtp.client-ip=103.168.172.150 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="C3EdX5ce"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Oo1yp3zM" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 80A381380388; Mon, 29 Apr 2024 02:34:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 29 Apr 2024 02:34:32 -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=1714372472; x=1714458872; bh=ywSYOnWNB2 iP06q+nHlh2dy9PYmPNclr8uRKOMQvpBM=; b=C3EdX5ceFXm5VBWkdyMSSKa0yW 75EsmyoxU029+07R/1gxa7nrRNw9yYsot1o2UHiC70FXsNepr8gidfg50VhyGKVK PwpVGTe64n1/EyKC0mHXApEfkXLXGzucRKTv0UyHqKwZyu8h5JIxdqWIy+FVPegp iLWOZ2eVeHn8w5SPOcE/wjcABIIcrg1EXLaYHFKxFvagxMnsiZOGyDIi23oMODVQ Gae0KV/nVdk5z1YUYiJih3WvODFtJvetvzzGHTMPMi+G0qxv+ezjFyG0UCSz4S/h V5JA5CdZJ1xhlK9ekgUFUqYKiAE3si0XwpuNVeFiPwEpx8fXLfhcUGywrTSw== 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=1714372472; x=1714458872; bh=ywSYOnWNB2iP06q+nHlh2dy9PYmP Nclr8uRKOMQvpBM=; b=Oo1yp3zMIMcFjRPwDvhrZ0xcXA5cuWK8b73GZm8Iqp3P 5IGy+FfYSK2ZbYKqv6honyJorO8vfiXwZVB6a61uNrwxk0T5gsX4KtIZBV740OJH qT6RE/cqQqE67Ue7sc3134hgy0it2D/N9BkW6a2xMmqeteuKXmvhIjQy9RD90F4r l9hocSjKYMySUHyif6jgYUlScsUDyqREOQrftvn+/qzD+WULUcMZ5uG+RGqof9Ii 3FDA/iUOwE5iTS05WGWB+bTfZk3IPtOlldb65befJFQLxYuLn/YvFqosp5hpsEKk vnQdcV0SLVn2WucqyGmH7WJuu1dtB1IsODefJPzbow== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddutddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Apr 2024 02:34:31 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 4da46d85 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 29 Apr 2024 06:34:11 +0000 (UTC) Date: Mon, 29 Apr 2024 08:34:28 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v3 04/13] attr: don't recompute default attribute source Message-ID: <929bacbfceeb1627b257f68d9f66155878a11e18.1714371422.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 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 Mon Apr 29 06:34:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13646346 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 B5F0D134DE for ; Mon, 29 Apr 2024 06:34:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372479; cv=none; b=tbdXEgUR648A0UE6FhpXuPvPWioy+V9Hv/K4OQd4dUq8qJmK1Q8wp0nlXcgCIuU9+x4EEVgYJ8OF0kfV1G+t9mqynu7BbJl9a4Okse+zQposTGGMUi0e0WLhcunHwmCtfgRfTghTT8ZEwbp4fql+e1ZjqqcENoVox4Bn0nvAzaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372479; c=relaxed/simple; bh=LCYBPCEuIcOLsRNAv6zwSCrz3FM5VFSfpjHuU93jskQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XWdwrN5OwPMfv0jj+J0VINTQ3kFXoeSH/i4K0zo9imZOomvJ6TDYaNV3esni+TOxuyJ2IMb4aPrH2B0nW93TsfPQGKduSSkIXOhAbVplURmH8yCF+PtEhhymE8L/LATyys7KyPlleVu8YZhJEZ+S37BMC2jw+4pDsV2emPRpA7c= 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=TCiRIIdj; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=G8fcxaH4; arc=none smtp.client-ip=103.168.172.150 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="TCiRIIdj"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="G8fcxaH4" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id BD4CF1380385; Mon, 29 Apr 2024 02:34:36 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 29 Apr 2024 02:34:36 -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=1714372476; x=1714458876; bh=4tP9kvEHKU BWIkdRMPa4vtycJ6BmA1wWOTWn7xK7oRQ=; b=TCiRIIdjNsk4kdFfLIKQBKo16D aUuGGS7QDffyuGJxbhxFewuvcsKlwEMIEvjiYacvlvu7Ta/sy69/icoA88/RGvNO U2id1C+KrtLcRieNpQ3K6qlT27gKau5UW1RxF/einyoUa8G1s67ekS5J805q5E6n rSxXVk3gwk5uEBhQBdXzu5umdGLj8LEBSKx+5viGUC8WCjavk4g3NMSnTlT8tjp8 V0JauTEBQFXsVQCnhOVh+yCh72S/Gtka58bwCofbrm7zZgquGg4Up9gCQoDkaUGT wcxhjlaFHUSdvaLpKjdX5Y9k+SyktjzIH1L8wUX23S+wtdBQGj+22JkdTf/Q== 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=1714372476; x=1714458876; bh=4tP9kvEHKUBWIkdRMPa4vtycJ6Bm A1wWOTWn7xK7oRQ=; b=G8fcxaH4oFCRFe46A5oglwe/QtZ01/D52ULYK0P+bb+z I++VoJqrdF7nwvz77yzPSI2O7dfxt7NvEYV8EpzdZZZY++UxuEsWYDHszwRdmjWJ bROoKqTCdzf3rYajcevFSorbakYkwXUhUDno+AKr1540umnXN3sbumC/kkw36gpv DdP6fvuMrj3PbAcNxBlvfDMmsFTDnLgStzQ7zpr1pCh8ktNJhQXkCeTixovZfKnn bnkwka4w2PIKakVDKAzpRvg/nRLEO2jMtppSdMmSOExm4GU27MJZ6t64uZt7ZfDv 1dL/ZyH4HQ1NEtPDgF4kwae4KqyxBzp3FQjM/VLR9Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddutddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Apr 2024 02:34:35 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 0fadaa66 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 29 Apr 2024 06:34:16 +0000 (UTC) Date: Mon, 29 Apr 2024 08:34:33 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v3 05/13] attr: fix BUG() when parsing attrs outside of repo Message-ID: <8f20aec1ee046ca5d21fe4ce2b19e24869545a42.1714371422.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 Mon Apr 29 06:34: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: 13646347 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 E658213AE2 for ; Mon, 29 Apr 2024 06:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372484; cv=none; b=FQTUmBLOW3Sf9gO05V89UqZx+2vD2Sj4Gmm+V4FMHyskxPF0O+Mw06Qgg6Vu4hv07XfbhDrl+Daa3c2ld6vJjWzJUzyTzLfudeWjCYYgwisCJ5h4ZkbTVbtNI0BYbsWCqq5MgWmOttYZCkfHzEO9X3QPrDyIU9gdhONcAvVJb1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372484; c=relaxed/simple; bh=VtRXmU3OY1pf6shxLSkWHvS4cFLELcUan2P9dGNOFDM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gcPAwz2QGrQSfSxQKwyuVa3DoHwfwWGzv73u6x1dEtyavIEPFCYNWVnGFKavoOtcGbU4K5CVlK2KSMpxW+TqiZ9/Ntg8cNmR6xCOQC1xNLmKCaj5FTEALEZ94ma1wMYaCJWZGvjI7Y7tvtxgSn46qlTPAV/S9sGFeXQeYq1Qz+A= 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=CzRcwNeS; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=UbYBbC8U; arc=none smtp.client-ip=103.168.172.154 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="CzRcwNeS"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="UbYBbC8U" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id EA36011400DC; Mon, 29 Apr 2024 02:34:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Mon, 29 Apr 2024 02:34:41 -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=1714372481; x=1714458881; bh=0KZMQVqegZ OlKViKapt//A9VOtNn9wYHnoX3582WEIY=; b=CzRcwNeSG6RsgDRkzBuFZyzlR8 FxFIZx37LAWgwnOBia1+UIKGc377wiPC9Hq7pLrQc0SNz+De0C/z+8XdHIwQzPOi 8hW5WA9TgIH9z7DyWw/7wdrbhAFXjtkyUBkY6SmrrskNsBrdmlt2TdVqv0Yju9nS EyrBeE71r70mKjiFAlYbCWxoZnv3hZpNVpc24I671FqL4G1Xb9QA7SYFOGSF49or GxWg6nkf77aHBodg4ttodp5gH8gd5xg4sCfj5gjG/HR5xFf2dTmEk1eYOseCo/d/ q/bEL/3lAUap2PWRvtaBnNjXJ1VANJ7U4yz//HOo/T5xHQ2Rwb0ctJHz3AvQ== 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=1714372481; x=1714458881; bh=0KZMQVqegZOlKViKapt//A9VOtNn 9wYHnoX3582WEIY=; b=UbYBbC8U/bTKz0qwHZgCoYEGEYcdbRfcpa8GQcN594zY VKKT8W2L2xAAP35qy6E1YWMTYBUwfEQceXgIM3vTUH5Ghwo4cwE4k8BVIFmfk2K1 lMYQIt6dl1yeyvgStiVyfhBkUds367coXd9UTdJFH6kVe+bm5+PyV98mIk/iSI6/ NMGbuN9KKRvPeL2kIIo7+cO9+Po0oR3KqFOfqtONKqEEuFDkl7GHoqGn5yIb5eP4 Nnrd8mDLSOp1K39ziL4KiLGzOOdwPd2Fjn+rz/KTVO8rKX4F5gEDloldFHXIkIez TFvNsq0TwU40ZvleWLfdQ63wmW9O5JIG0xbX2o+sMA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddutddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepjedvjedukedtvddvleejjeefudefgeettdegffdtleekgeehvdfffeeitedviedv necuffhomhgrihhnpehhthhtphdqfhgvthgthhdqughumhgsrdhshhdphhhtthhpthhrrg hnshhpohhrthdrrghsnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghi lhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Apr 2024 02:34:40 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id bed9a6bd (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 29 Apr 2024 06:34:21 +0000 (UTC) Date: Mon, 29 Apr 2024 08:34:38 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v3 06/13] remote-curl: fix parsing of detached SHA256 heads Message-ID: <53439067a1e94075c3f432b6c2774b1cfb11e88c.1714371422.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 Mon Apr 29 06:34: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: 13646348 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 0542D13AE2 for ; Mon, 29 Apr 2024 06:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372488; cv=none; b=rFboi50sVr189EwY2/ofLuA1RadaepHMR68BkX9M/0a8NoLp+7yeywT6uquNyRjZGfM4NQouVDGw8oBsyhQMS8kapmaEiAgXz1RZTXMLocZfasEWtNh5xR0ZFk7MyZbbIuyLslbSZey2Ej8mzo3UM7rd6G161uuJp2OQFS74be0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372488; c=relaxed/simple; bh=tSDRliLxIhUCDjWxT5ARtO7C3bgl8AHy9/WMdEuBe70=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oeZqWfhajIAPdhd52tyTztTvBv1P26t1PAEaSrjcoVZ5DQtRpLQLO0dwufm7FX8zCosoNojwT+v/356r+z+oS0TXjexma6dG58ZJJsUNKBW+71+AQ6tF81xoErq5KLLZB0zuGzGdp1OwSogAnwA/O0sUCIyoHGPvLEe9EfZy+Rg= 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=pYNDTEoY; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=elI9cLIg; arc=none smtp.client-ip=103.168.172.154 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="pYNDTEoY"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="elI9cLIg" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 2B4A911400D9; Mon, 29 Apr 2024 02:34:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 29 Apr 2024 02:34:46 -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=1714372486; x=1714458886; bh=aVJRDcm+Rf hQBJ3c+yeW4INrUnwSr8b7XQ21nJLsuEM=; b=pYNDTEoYVZt6eTPoXymvxFes22 9RuWN1F9rBLSFLTBxvV8c6gcPqwLg2xpECyv9CN6XYn5sYO0jW5ECBO1mmMI84NF 50jZNUyTFhc+iscp9JvqMEL9ZQ5H28Qh8t0GkeEH+V9wK5HkoTeenozsQnf81/jm Tve7xmTI7PeN6DZfBHYcPAZZboBrpN6T2VhNiMSun+kVPkiTfQ3gTtnE+16UB2j4 QddUi7W9QCHIlUTS8WqRBPHY9niI5Af9J0zRKTXYwAU89Ng6CSyQ3L6BNA/0Jyoq i/i3poUE543JYPbDtuz5HOVPk3JMTU7XnwJGV/YcnUSWd5paW/o5HBMBxodA== 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=1714372486; x=1714458886; bh=aVJRDcm+RfhQBJ3c+yeW4INrUnwS r8b7XQ21nJLsuEM=; b=elI9cLIgG58qWMUto9mvG/i8CAJ/mhK9xdFKrCGGe+JQ O9tazADgK1HgoVmfyIVtQqGpnynwwNz53tuX6DdEAUNkXjYVuByiQeVZLFbx+qkB PJ6LKc8B+jqaS3TapknOW6+ix2JT94ltlcwydtuYlVonUIEKTO9m+WjiZ/2bhE8Y s6+7JLeT8R8cUlvwgZs+m372P0bHwx5EMM0FQPL112nXwI+Uf9fP8iwK+FVyc7y/ NI8qU9QCplIXEtxjQ0tJ6lEeI6xhVbYxBguW8nxcbOvI3R4KMG8oX8IduIM8BzP5 riRuFznQd0cED3mq+ygpBcyaHjF18gc7s0f9hj6nSQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddutddgtdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Apr 2024 02:34:45 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 0ab7dcf0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 29 Apr 2024 06:34:26 +0000 (UTC) Date: Mon, 29 Apr 2024 08:34:43 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v3 07/13] builtin/rev-parse: allow shortening to more than 40 hex characters Message-ID: <1f749607604b80517b60b3b696b22287aca0ab54.1714371422.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 Mon Apr 29 06:34: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: 13646349 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 461661401B for ; Mon, 29 Apr 2024 06:34:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372493; cv=none; b=WYbb8JZayS9DGmD7d1I/vVjGuRtkzmrNDGWKSNfR8TAdEgmPSpploGTH8jWOnqY0eOHqznEVGhGia4kM3lpjVdZJDiU1fnVLLVUjYVx+MvfgfG8y7HtOFlL3Z6bGxdMqQdta2t4r9sjSOSey2XuXszLxdmmiZU4GMvNi5dF6JW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372493; c=relaxed/simple; bh=/U5lZtIjplVReje8Yw+V41yujThh3zKcvDWCffnxYcs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bn/OV+kF3sxIRz0+RIXONd5BXjc3Zcr6JWhrxUBvdn1g5nPW7x4VMovDiRotnE3DNa2sP2GjCmMrHyLAJDfVQ0SmifhAC57Mp4pbrg3G0QPMSLbQTjUftiR0t6U3yqUZ+MteB+2tdLt6YO8ZqEhcDr4UeiHjv+HSgZgQqyKGjHg= 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=rYSBcxdb; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=YPYQTyKg; arc=none smtp.client-ip=103.168.172.154 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="rYSBcxdb"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="YPYQTyKg" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 6358B11400DC; Mon, 29 Apr 2024 02:34:51 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 29 Apr 2024 02:34: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=1714372491; x=1714458891; bh=AfJz6Ucui1 zezMsh8KlI/jpM0IhFD+fZ9o1eOmKY8I0=; b=rYSBcxdbxsL0p/uAb9uthFb3jT YLZQ7JzBfFBLJC1bXtEOW/Qq++imMcUqA/ZV0jKZvjHWAuw5zlhJk1KQqkADp/t8 l7+QaU/2wWm0ZMs1MO6A/sRgtaVRw3iPut9/B3EPTcZIsGaA0/uY2tGLcpsnI9X0 LzNAopBn+c8hdEIZ1xfZ1/vgI0BU1bKtBH6ICWC6rbv20GrQEcvNniDITKmQ2Duk TbHGysNqw2SBhLKx0LbKtCyh3ImWM6eJ+MSWKxA5IcfObnur6VjsYlM6/ciEgOq1 aHcPsEdp/3fSArsQJFn+zLyE+KFIDSFClN6LxZfgtRl+kjdgEltvHVMpG3mw== 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=1714372491; x=1714458891; bh=AfJz6Ucui1zezMsh8KlI/jpM0IhF D+fZ9o1eOmKY8I0=; b=YPYQTyKgosgc/ZU+IfVERk5tI0E/Cy0GP4OvCfVl0IVd TOnOT1V8OaFiAugpM2PUf9qPAun818jNynsV00LDX5eX0jNQ8WzskCg7vEPT6dHE l3HEl9lCi5B0yKMLCCacvlA3aAzm788X6t0XnsXjkCPLulqM8iLDhdx9di4UpOSN lSCIDAgqcKaB9tpRVRwEn1QG1e63MXBvAc10XLv0sM1c8hOcchgfv0h5oSz7vHqz kkI5auh70q4hlUrDiANeTRC8AKPKyGwxdjDu4Xn3JlZWWftyLQIsfrmvVV1y/Rt0 9HateI/14F32HTiBn33/skSzPDer0K/D4es/iGwH9Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddutddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Apr 2024 02:34:50 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 5f51f8b9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 29 Apr 2024 06:34:30 +0000 (UTC) Date: Mon, 29 Apr 2024 08:34:47 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v3 08/13] builtin/blame: don't access potentially unitialized `the_hash_algo` Message-ID: <2d985abca1c8f99d888816965dc87caf70774a86.1714371422.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 @@ -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 Mon Apr 29 06:34: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: 13646350 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 6B756134BF for ; Mon, 29 Apr 2024 06:34:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372497; cv=none; b=S1EHL7lsjRctSDKE8TYL4fv/KeVXzUDbTGUEEiwyaVpFnwt7AQJ8reGaG2yR5BDdtl2S4Qk3X/Fr5VoGZMuvc4n94b6Ap7IznBpLEcfiE8k61hkITE0gA/vTzZ2eBS2AN/PMn1E1JxZa2CJrSgPla9e4mlOQ1smnQBHAT7jfdZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372497; c=relaxed/simple; bh=DiWouTnhsqP8DddfWFe3Ffs9WYgPVROVTySbRqtUXrM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=P1lj37lTbfFYqSHZGe7IHAN34ocv8mpXjeWcLxn6z07KmN/K2zEmEej0jwhV7AvezTdweBhOFnp/J77IibfQFagqCbbpjgcqnxmqV3DJ4lnQ+nO8zIKr7ozK0boTUMLtqWnztPP8FML/NtZms7uIWKBXZhqsQfQb3CtEWqmWV1M= 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=I8Cmm11M; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=M1VXn9rO; arc=none smtp.client-ip=103.168.172.150 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="I8Cmm11M"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="M1VXn9rO" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 9C96C138038A; Mon, 29 Apr 2024 02:34:55 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 29 Apr 2024 02:34: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=1714372495; x=1714458895; bh=P1ofyXoaHM yjdvFs1HWBS0/6OJLwX/IXpg/BO6SYGjA=; b=I8Cmm11MJY2w2XcPfrydFakPOk SLlSpBcrj9MRJ8wdJ/u2E/0iYylHLx7rhZ4dNogj07DrRL28GE6eh/EcNsX+3W3k NJv21gtcLCQ3v9kLhxh/7hTHXpip97FAlw5VQq249dEhibxixbqSM+H9qfZhU1SO maKW0pgwbBz7DmpUM3t1Ck0An4pJyMfOlSz2IrWJttXjsCgcfkYPQb2TatvNOOb4 em8PEC4+iGRhgzHcuscNHLEVSC6U0crn+FnoIOj5njOP+BKet0NkMG13YkUP0LQ9 DwVYzYbwQrdoh7PVAX3owgE3Ys8dK4ZOOs2Mf4/1y1dUPbBs0EGoCRYQAAhg== 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=1714372495; x=1714458895; bh=P1ofyXoaHMyjdvFs1HWBS0/6OJLw X/IXpg/BO6SYGjA=; b=M1VXn9rO2USuI1vrOu8cZ1tDuRtI2XpvcbgNewaWMf+z R/GujX83maxxo9mJo5fw35XW3bSZvJMCIb2H0mxMkb481XUjA7kcphxNeVnsY3br FmPQs8XAUwO/eN9cVcgqkBQMzzxILPYEU3yX7wQah9ZShsHHw1A8MF/eWPxP8CPq vyX3fa0P5BTk7qePbhE55q6FQSlxhlm/bNGRHn8yZ24QmpeXWApA31Ru/vKDN697 9FGDbEGcHV2yxg1N8FcHnVO9NPkh1BXfIhDu0ZRupUR74R8pAdZZBU8mNPUmkUEL 5ykD4MpdrUW3CJT4VOBJ5uzopbSRTTlkhH7HDnQqAQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddutddgtdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Apr 2024 02:34:54 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id eaa4bee7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 29 Apr 2024 06:34:35 +0000 (UTC) Date: Mon, 29 Apr 2024 08:34:52 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v3 09/13] 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 Mon Apr 29 06:34: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: 13646351 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 A5A88205E20 for ; Mon, 29 Apr 2024 06:35:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372503; cv=none; b=EhsJOKpnGO3sgsrgRZf7qBVhc+Fniye83+OjfKsG6Mq13tybfAClSD43WDhfbV3rbaFPXgBtJDmJVAJtsZORwbquMEjIxKE6KBLR+vJ4XIfcyEXXht8gRgDHqIr7TECL7xoIE42aG41rC1Q54cyddnZQEgmKleP8tJLzqrb+6A8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372503; c=relaxed/simple; bh=6/3q5ye10/q4hGO/MK7Q5sExjAMSk8QVkCB+pG8VJQY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Zc+XbfclP6q9R1D38DJWP9L/4TWizU3U4zo6ymIM2eoM2sWNwf4SonXBkhrOzSHlAesxPY9dKU2Br1R+JMKUrYLFAn42alfXI2oIB3Q6kWtVjZh9LEB9VzXjhr67r3iFhA7ZtPWrRsyHIDnHtVqabCx+xQ/JkG8bkVvpN0n2Yts= 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=tL4xVTme; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=eLrBF6F2; arc=none smtp.client-ip=103.168.172.150 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="tL4xVTme"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="eLrBF6F2" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id D8E411380388; Mon, 29 Apr 2024 02:35:00 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 29 Apr 2024 02:35: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=1714372500; x=1714458900; bh=ghn+T6IGcB WBTZLwJu9fsAQ+aOJ+zVZ845wD6gsMkd8=; b=tL4xVTmeLv1iqkqbzovep4SzT8 Ir2jSdcosYuJaop3fTNpApRUrl9vYDEVtrGwdo/16dv5dn7JRLFCRQJ6oH1I9ivz ZTDnI5z+l4cJCyxnGnWTy34rVdmBM9BbvcQhREgT7GzJ/Y8pdnadPh0doOsifHF4 Ao2O1tpsphiaJmqT5XZWBD0ILIDlHF4x6XyAykqOFNq0mZRiHvPZCcJ9GgvNto0h vIV8zFtF04rRz7iLQeB0Tfw/LRU5/PIqTevWS822734IXJ+ndCzofI/rLPl+JuZu qHfdJTzvniv1c0ah0xaRxewoLH3b9e88Rr3tcYBdqf+40BVNhfjjTqiQKmRQ== 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=1714372500; x=1714458900; bh=ghn+T6IGcBWBTZLwJu9fsAQ+aOJ+ zVZ845wD6gsMkd8=; b=eLrBF6F245rQNUuk7V6jad9bM50VRwQQU+KEs1PQ8TgS zwRbLZ0jQ0Ihmskyt8ZEvo/cTsom5BdTnrUpx0m7ZjinwRM8QDNeN4tR/KxHyr+c xrG9rpaGW/Snz3ge/SqXdDNa3bx4tdUxdbgcM6hlhTC2vFKI/vmFKtIX0rGxlkcK 3KCX6jpWcDM9UPjjwuLkF2+EBP7zO8wjoKgbl7U2fY9UWca3RPY/r37PDQyt80yb 729doaXob/g6G/SJXRBZCH7+1DoBLP+aCiP4d5f2xA/gMEgNEWTtMa2Dy/3OMuPC eXxNJLqgeDOSM6tndMMVMhpLY+LcBA0wQf2NABO0OQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddutddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Apr 2024 02:34:59 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id e57f624f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 29 Apr 2024 06:34:40 +0000 (UTC) Date: Mon, 29 Apr 2024 08:34:57 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v3 10/13] builtin/diff: explicitly set hash algo when there is no repo Message-ID: <7577b6b96ca2d1d7070ff92e13fccd14d2e5f86e.1714371422.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 Mon Apr 29 06:35:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13646352 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 1D0C613AE2 for ; Mon, 29 Apr 2024 06:35:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372507; cv=none; b=Fv1NDySpfzKqtLVVcIMj8uOwwhT/b+fty97/+ebOrj7F/QpC66BYuLJGc0UWwSXB4NDJ+6UaIFodU0jBx+BpKcqbkqAbHSzOahlsxxFvROnLiFYxtk5+t+97Qa8BWAs6WN6AWJHN8VbbPkFIQgQR8rEoqgzwNEQKNhKiNXRrNZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372507; c=relaxed/simple; bh=isQHdSmmrVs6v16y2VBJ+FP37sL/XlZISe81GIsMspI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eil3W9XtI3v0f8op0dxLIeLa/SuPwQ5gSaLVEzpo36F7Vw5EJCIJsBBxhDMwgwPybxZb/OB8XackxPoG44VNdskuLSVhYniKBWw/+t+Ok3RKfLZNKr63GEwcHy5JDyVyZBFRUrcwMZ6C8KgdP7todWFSXYY/HPwcHH2c2IZGgKI= 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=ctAkrWnR; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cusA75ss; arc=none smtp.client-ip=103.168.172.150 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="ctAkrWnR"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cusA75ss" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 256BF1380388; Mon, 29 Apr 2024 02:35:05 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 29 Apr 2024 02:35:05 -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=1714372505; x=1714458905; bh=kokswTQD7E Pv7bAe5D3gUUukw1sNp+ecLsFG96KQW3Q=; b=ctAkrWnRu2vCFqcA6a7I8guBRr +LpsIXTfsorGc9qzThHPZxENGlidk6OaSUzBfb5Ov9xgbp7VVMlQytZGaUE8hLCr H9pxeo78unLASUCFoZXFE4P1vfxEAgAQvSUt0s0bYzuC0fSUPLxEsQ4nfu0W8Sko fs8TRV3QWvCTIC/h9pp9Y69i1i2IAXBMPh5JR07E81uJl8KmaZcjkwC8GZp1kCSb ZyTDnp+8DDMTlWPN922cKSUGQoy3Sld4BKgXDpIAgEu8CjFxH/2l3OkgXCB8tU84 7bVCcJxOfFXK1wuZo4Z4RvFvo4SaR92Sz3vtKD81wnwdEGxKJoNabxJtkNlA== 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=1714372505; x=1714458905; bh=kokswTQD7EPv7bAe5D3gUUukw1sN p+ecLsFG96KQW3Q=; b=cusA75sskCj4PdNkle2u+JB6ldiOzY+fIg7ka62I2X+E VHWG6lbcCYK22+b9NVveEqmsLpwP3ZVJPtG7lZx7lQtC1TJmDIyMSb2sxM3/ovRX 5OCb+FCKWfAc+qQaT9IsBdGInlzLeNuZu9f/YHUPRnIzYMaq+3gY0PQI7h/D5kSc PddpeaaF8kJkGsSILupA+2g8TqF2xJLd/XicTB8cGFI2frY826Dekq9CWVlL6wr5 Z9VtvTTlTjNuVOnJeEpC+FOsBsjdFW5DP7iK+BD6EWC33LyefhLKI5kTCtb0+dJb oLGhZRU5i1wEECwKxE5LXcBFvOrNB9XYvmA/4OPnlg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddutddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Apr 2024 02:35:04 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 46807731 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 29 Apr 2024 06:34:45 +0000 (UTC) Date: Mon, 29 Apr 2024 08:35:02 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v3 11/13] builtin/shortlog: don't set up revisions without repo Message-ID: <509c79d1d33a69367726549fcf87f932f83db864.1714371422.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. 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 @@ -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 Mon Apr 29 06:35:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13646353 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 294A314A8C for ; Mon, 29 Apr 2024 06:35:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372512; cv=none; b=e5oBO50OY4U2H0kjSBSUG11luuZS2ORry/kD+F9i7AEEpdyfgKozXMoUt1z+Sgjt+QIr6gX0dNKqnWiVMcI8aNambjmlobylc+CGYH4tg9i5mBFzpNn1yTmZqsDgol0h4r8x3EPx5pCo87bfr2f11vpdNAYjQ/hJCcQ6QHbWaQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372512; c=relaxed/simple; bh=9uAiE2bLIk+BTtCZX+Nao+Htl3qry7T7srMg5POJWis=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Is9AO22dxcY36Dpwiz8ACj85698quB+/1k1ogxBjOjSWR25/7WH9wqQ3L8tR/CQ3e2aABYAx+3tvbI9dAwIdhSkOXZe5MLG/MopMxkR8x3YZWwXM8TuAIiiz9/8C60vtgdESLNGU+Tlyct9HEgbxDWIjWhw0pNZ50D2F+V2OE9E= 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=giN3Iuq7; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MeiBDxVX; arc=none smtp.client-ip=103.168.172.150 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="giN3Iuq7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MeiBDxVX" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 6C7291380389; Mon, 29 Apr 2024 02:35:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Mon, 29 Apr 2024 02:35:10 -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=1714372510; x=1714458910; bh=kFyyAw9IXX 6+d21zMDW53IWMKwEbvCURjA5cBbrf+FI=; b=giN3Iuq745L7q9YBOs6EUfW2V9 U6DbsrfFVVvQFJE0q1EQK05oHgr1aP+A+CMU1DzS/hkB74nmoYDN7QoeObViSQ2s 1ovXcHgPehEZurusjl1EIbsgIE1w7yJPx3Sx9j7XXHRKSzDeMS/l4NKvAl+G7iEo u902DWREsTrT8XKVUT1fOc6SfbX7cV0kRffANWneuCbsOMh95rj5pl659oAUPW0+ 90Dt6pNyjgwvT51Xacw4i0U9WKlAdjOCTxmNqTydzG524lxc578pV8NLiuZ35bLg uEBpsjF963VB7l2Khw2UYbq+OA9XF8DfulOvVZwePLT6pzlZbD1NLwNQS8JA== 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=1714372510; x=1714458910; bh=kFyyAw9IXX6+d21zMDW53IWMKwEb vCURjA5cBbrf+FI=; b=MeiBDxVXrH07lez1u7NcO033q0XirV4esY4AhC+Vq7BI KlC78JFT7wvhzxCnTyMwVbSnEeGug2MkPvkICb239EJRbyXzXq8OjDOB/BRNlN3L fQ/CsCTeNImECNWDOVLsSmn74OOUllhJLFmLlkXV+gSqm/RymFNsA/mQJ2KKlHG0 XspLUuwtcZlyd06ZpBKgcKseKfrKmv00zh1rEHs+QEBx7IJdhpdWLvCaHNbIg5Cp /Ye3lz9idkr47EKb9d4djZYmA3Y4FsaHGrY454cfFqNVEcv7qFAt1F7NM2vNK9yL b0WSnBYsxOjf3GBmOumeBJhkMiD/avO25g3fOAJGGA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddutddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Apr 2024 02:35:09 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 26ac040b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 29 Apr 2024 06:34:49 +0000 (UTC) Date: Mon, 29 Apr 2024 08:35:06 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v3 12/13] oss-fuzz/commit-graph: set up hash algorithm Message-ID: <660f976129ece3398465053884fbac62a6341bee.1714371422.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: 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 2992079dd9..94ecbb9242 100644 --- a/oss-fuzz/fuzz-commit-graph.c +++ b/oss-fuzz/fuzz-commit-graph.c @@ -18,6 +18,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) * 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); From patchwork Mon Apr 29 06:35:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13646354 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 A0E0114A8D for ; Mon, 29 Apr 2024 06:35:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372518; cv=none; b=qnkMD5gxj5uF9c+3hD/AG517f7LS8VdwkX6EqOZwg76PkUp3tYu3V/UCTZmudI7X41bruGilr95D/xGeu4p4IBEul9/fdJkKIhGXZBPsQh3gP9eYrtYEgeZDaySGVQ/6LM4epcv4MSheafxEjtqu87dzK16o7WE+aDf5iecBnJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714372518; c=relaxed/simple; bh=9Kcq8ym14PF+xovVHJ6p85QZ58aqIZ0PRjj5S/Xq90c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DKnzBW7KpsgCra35hdl563LkfJJadMibK3vI+4dhlh0M7wx6wdeqEty66nukiHwSuOXfm3RZBc94fh0GN+mZzx0RffO3LwHd1ogtqhg3aeHedh8stfCzPfkI72hpdAEHx9otjp9hh/IiMx6p1voLdn/skgK2gUtPz1vhORLoZB4= 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=p/xw/bxi; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=X0Kw9oiE; arc=none smtp.client-ip=103.168.172.150 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="p/xw/bxi"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="X0Kw9oiE" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id AF53B1380385; Mon, 29 Apr 2024 02:35:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 29 Apr 2024 02:35:15 -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=1714372515; x=1714458915; bh=7CKxVZY8B7 Pb6VP9IqjC0olkczPIa2rq1xIMq2/L854=; b=p/xw/bxiklapHC/7asdDtGSJOX h7BwEszbOLF5AGa/nGWhz3G47Q1JkGHIjmKls4zBmMByrPsqnkhby2TZpVf0IYqS hInsPSM/0rwSsDywL4ve2KfC7rDyYiOiKTmA7dYqjC5JysX9jQj2P1ZQALVGwPJ3 gfHmckzldH/LGx8K8tx8V6wUXaLNOlqiAjRMCe1556bpd3rpTofcNp2eNrshapmc HtWHF1bB16KX3dwT0vczhA5N6z9YOVWn2Lkxupz85Uf3SxsB9c2JisGBbEJ3fzOe OFBHfwpaq/K1DikaiNQ1/lDzgbBQm3yNALKQhZrlw9kf4xVGlYJcMrckaPBQ== 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=1714372515; x=1714458915; bh=7CKxVZY8B7Pb6VP9IqjC0olkczPI a2rq1xIMq2/L854=; b=X0Kw9oiEbnQdGkEtAebwVqOI/sWj356HOZfaY12Hw4hZ GfjWO38H2C3RgBKIDZKcd3QOGf4E0cs/liO2wVtCinDrWPO+JsWrnqCHrdZPU75L UZMe/V17036Qn5l9KkJF/0eNGbIC6zz/Y8t5RdxuB9A7mVJZDUaEUN7eWz2oh2Ge SZrJJcDeBw7qAm/pCOsVoOFFJOeFoGnqjAV9eY/wLHfwBzCh51Kn6n19l6pkzJB8 +R5QBBgsMPwBTwKqGgRRLbVo6R6mBPgkSw7dLTo8l6VFhqKnlNXtEWliRTs3MO5/ dNRWxaZzRGUdHS01jyVo2PJsHdjSq/U3pkpfED0mdQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddutddgtdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepgeenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Apr 2024 02:35:14 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id bb257c41 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 29 Apr 2024 06:34:54 +0000 (UTC) Date: Mon, 29 Apr 2024 08:35:11 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v3 13/13] repository: stop setting SHA1 as the default object hash Message-ID: <95909c2da57f6d9814561c94d75be4582195bb5f.1714371422.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 | 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,