From patchwork Fri May 17 08:18: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: 13666708 Received: from wfhigh1-smtp.messagingengine.com (wfhigh1-smtp.messagingengine.com [64.147.123.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BA1828DA4 for ; Fri, 17 May 2024 08:18:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933901; cv=none; b=WUZnl61neAiaW6MwVoxCwgTbjbLYFLehYOmXFCXP+0GGIhJZOd2l2AQAW9hpW1PTZyaUYQFRHYivNtq2gDf3UiLKQhgMMjMn+qkLQ0yJ5HW3AK3J+rvSOUUFnJAAJZJ6v1gE8QqyKc86z0BpWzUUFBs+Wk+WgkoiTa0Iz3FRvwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933901; c=relaxed/simple; bh=cd3a/e/2IvQrPxoQzoiUes2ue/5iUr8vYcDzxnDzayo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OlKWcBfI5QT9zvZnuPeFSFoTFPZ+LuTqqmeMQBLiqYD2vUJs8pIbULFMSkEPqU5LTb8HpE8V2gRe/hqDJIJrL8779KzMs9P7z6kYPt1gNJw3vHwMNLm0eQo26VQPuEOJIHXpBX6lF4CJvQ9OahNc1kFacLlc4G6/si8F3j/6wpY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=U6C1nXAG; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=RoFs2OIV; arc=none smtp.client-ip=64.147.123.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="U6C1nXAG"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RoFs2OIV" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.west.internal (Postfix) with ESMTP id 822EE1800179; Fri, 17 May 2024 04:18:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 17 May 2024 04:18:18 -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=1715933898; x=1716020298; bh=i7wtN5R4+L 2WH9hapT4WQvXFg3BZ2UravvdMW5QAYhM=; b=U6C1nXAGbVdvBxes4gwVMBTjqY 9Msps5oELFP+6qP+1h+Sj/3i3og2xSYuSBWGs91E5gnD/yPrBqhL1aqgJmA3TEr5 Z3DI6HUvKvPgE9pGt9kloFStee0D6b0IpmI3AT/cOgwJNyYptND5ep4mf+QSQ9xM Og6QhhW/50Dv+EK1Q8YMDiMpblRM/u+arsWzhIeuGGypUSaytDJx99EohbzXuMjn vqkDZlaEK5HH+3wZKRzetP7PjjaaDyNdp1Xg0evj9HUZZRbTec0LGH0EFPxSC8c6 BlrQjGcBULRLYTqmylmor21WlmLayZ1ebUlsYedWSf1bSgWsijT5AIERvt9Q== 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=1715933898; x=1716020298; bh=i7wtN5R4+L2WH9hapT4WQvXFg3BZ 2UravvdMW5QAYhM=; b=RoFs2OIVZSovaT6Qwdra1a+dv7ZULN/2ymlGfq0wt9rs LaRQscM2r1ADLgDRg+pM7yVVT1fO3D99FGiQ+XZ+8GUmVyi1yOqCLImcamnhJM64 PAHnsxyZgyTPiStBBrrNpKxsFgesyckCsI3MgS/rnD/cCEX/wbpeq1dzb21Uj5xI wj5SXl7Qfq+FkVo+z5RSD7ENtEMQK+9hxtmzZO0A32h9wwWf5PHzm4xPTpIfGx9E fJdV8KPpa/d6ju5hz2ItlqXXafcMPfSkKPKHlmIUDMZ9YK3JxIJOJa/4jUw4zCbu jrFti6ox2tdSx9qVHwtto0k7bNNEH+cPjAHNQK3Lcg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:18:17 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 2988987e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:17:50 +0000 (UTC) Date: Fri, 17 May 2024 10:18:14 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 01/16] refs: adjust names for `init` and `init_db` callbacks Message-ID: <4225a6928ab5119d8d6844c6a7a13f1975137767.1715929858.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 names of the functions that implement the `init` and `init_db` callbacks in the "files" and "packed" backends do not match the names of the callbacks, which is inconsistent. Rename them so that they match, which makes it easier to discover their respective implementations. Signed-off-by: Patrick Steinhardt --- refs/files-backend.c | 10 +++++----- refs/packed-backend.c | 16 ++++++++-------- refs/packed-backend.h | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index a098d14ea0..2c9d5e0747 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -89,9 +89,9 @@ static void clear_loose_ref_cache(struct files_ref_store *refs) * Create a new submodule ref cache and add it to the internal * set of caches. */ -static struct ref_store *files_ref_store_create(struct repository *repo, - const char *gitdir, - unsigned int flags) +static struct ref_store *files_ref_store_init(struct repository *repo, + const char *gitdir, + unsigned int flags) { struct files_ref_store *refs = xcalloc(1, sizeof(*refs)); struct ref_store *ref_store = (struct ref_store *)refs; @@ -102,7 +102,7 @@ static struct ref_store *files_ref_store_create(struct repository *repo, get_common_dir_noenv(&sb, gitdir); refs->gitcommondir = strbuf_detach(&sb, NULL); refs->packed_ref_store = - packed_ref_store_create(repo, refs->gitcommondir, flags); + packed_ref_store_init(repo, refs->gitcommondir, flags); chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir); chdir_notify_reparent("files-backend $GIT_COMMONDIR", @@ -3283,7 +3283,7 @@ static int files_init_db(struct ref_store *ref_store, struct ref_storage_be refs_be_files = { .name = "files", - .init = files_ref_store_create, + .init = files_ref_store_init, .init_db = files_init_db, .transaction_prepare = files_transaction_prepare, .transaction_finish = files_transaction_finish, diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 4e826c05ff..a3c5a75073 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -200,9 +200,9 @@ static int release_snapshot(struct snapshot *snapshot) } } -struct ref_store *packed_ref_store_create(struct repository *repo, - const char *gitdir, - unsigned int store_flags) +struct ref_store *packed_ref_store_init(struct repository *repo, + const char *gitdir, + unsigned int store_flags) { struct packed_ref_store *refs = xcalloc(1, sizeof(*refs)); struct ref_store *ref_store = (struct ref_store *)refs; @@ -1244,9 +1244,9 @@ int packed_refs_is_locked(struct ref_store *ref_store) static const char PACKED_REFS_HEADER[] = "# pack-refs with: peeled fully-peeled sorted \n"; -static int packed_init_db(struct ref_store *ref_store UNUSED, - int flags UNUSED, - struct strbuf *err UNUSED) +static int packed_ref_store_init_db(struct ref_store *ref_store UNUSED, + int flags UNUSED, + struct strbuf *err UNUSED) { /* Nothing to do. */ return 0; @@ -1706,8 +1706,8 @@ static struct ref_iterator *packed_reflog_iterator_begin(struct ref_store *ref_s struct ref_storage_be refs_be_packed = { .name = "packed", - .init = packed_ref_store_create, - .init_db = packed_init_db, + .init = packed_ref_store_init, + .init_db = packed_ref_store_init_db, .transaction_prepare = packed_transaction_prepare, .transaction_finish = packed_transaction_finish, .transaction_abort = packed_transaction_abort, diff --git a/refs/packed-backend.h b/refs/packed-backend.h index 9dd8a344c3..09437ad13b 100644 --- a/refs/packed-backend.h +++ b/refs/packed-backend.h @@ -13,9 +13,9 @@ struct ref_transaction; * even among packed refs. */ -struct ref_store *packed_ref_store_create(struct repository *repo, - const char *gitdir, - unsigned int store_flags); +struct ref_store *packed_ref_store_init(struct repository *repo, + const char *gitdir, + unsigned int store_flags); /* * Lock the packed-refs file for writing. Flags is passed to From patchwork Fri May 17 08:18: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: 13666709 Received: from wfhigh1-smtp.messagingengine.com (wfhigh1-smtp.messagingengine.com [64.147.123.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39F172BD1C for ; Fri, 17 May 2024 08:18:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933906; cv=none; b=e5qcJq2yEPEOt2GgfkRw05np6jhtDPWNHjysH0h5/akS4SQov4ywf14uFkkyIy7fSuOaAbmyFac7kkS0S8iu8XSgFz9HY992rfsUIFuV32NOYzGXbxt78+GD38Fo3krG2LtDnwH5YUpGBdgNTG/mRTprtSPDdv8qjqkiplk0uok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933906; c=relaxed/simple; bh=5w0/pkr0yOKgbWw0zI2tvvwWZ42CQ0Qmy7l8gqBoNc4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Bv+n6pqmQw6O4hD2lVZnMZN8etNMM+GVjGDpGLOqn6PmTW+Gmogd73s9h+fPaDS3WwYn7wytfmxo+rstSJITlwCfMESg+8Lj7jt7SK3pMt9M5WyC3YXiPiGCAKMbHGXfqJChorcFBf9n+EiD172gX+i6Jdv9he5E0yddblC20Ug= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=BDnK0zcL; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jQqroHwb; arc=none smtp.client-ip=64.147.123.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="BDnK0zcL"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jQqroHwb" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.west.internal (Postfix) with ESMTP id 6D6641800178; Fri, 17 May 2024 04:18:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 17 May 2024 04:18: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=1715933903; x=1716020303; bh=36wH8ZnUMq iK0+55f0rY4Das5t2yq0K1AlLX0RfWCMo=; b=BDnK0zcLMGdfex8eU8rDp2xquq wQbduGcHSyqiU/OGfXVZHaVxMDTcTgI2bHORYdCY68p8oKNLSWnlWwp1j40ygM3c njZBWXI1Y1gqCy8AWKHjgI0RJimhKGYYQkRrIjnM0DUNcG3TwIInE0JfK6X3Cth5 289Gz+fDbdDEjxSNxd2Wtx/4ETJc6/hCHWqv17PwgNtiNYZhBmZT7lyu3K0DqOgg Vfn85Bn3ub26XMblAJzTd1GciMT7Rz7wGbO/iC30O9W/cd6spcmyD4TR2Kx5yDDf QhGkMH2HAzH15SDJVKXXUredYrKUMXpFIVmavtxsvpLpzf7/cE2UkDA72saw== 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=1715933903; x=1716020303; bh=36wH8ZnUMqiK0+55f0rY4Das5t2y q0K1AlLX0RfWCMo=; b=jQqroHwboY0tH1P6ZKbR0fI4ZuEJM5vNjcuhYrS6YMJk 3KATR7JyJ5PwBbTvGFgUMkxgvSIF8StGd0lSCWNkt3+R6gZNe3xuuA1wyqH80vj+ 1c0xGLNg7V0ISRQYbqj2/Mz8f7jZn5zGgw0rBT9/GPg6XuYdOAWZ/3XxWrcp19h+ YUGp9xag2KilFpe+YzqtZRezv5OmTIAcAdUe0uWBTBdzlIkLcmLLr1N+XqnEXBYk OhlbnAt28Mmyt41kUpNZImx+Pl0uq48YetOx4ZL0le0CDzq0FWeb3P3QUxKFTOL+ W995RA5NkwFZ1sDGa8Q8bD9axxJnZenkU6GKwcUd+g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:18:22 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id d9a6f5be (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:17:55 +0000 (UTC) Date: Fri, 17 May 2024 10:18:19 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 02/16] refs: rename `init_db` callback to avoid confusion Message-ID: <050fb24e5834fab6e42ed7deda1e9380701db118.1715929858.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: Reference backends have two callbacks `init` and `init_db`. The similarity of these two callbacks has repeatedly confused me whenever I was looking at them, where I always had to look up which of them does what. Rename the `init_db` callback to `create_on_disk`, which should hopefully be clearer. Signed-off-by: Patrick Steinhardt --- builtin/worktree.c | 2 +- refs.c | 4 ++-- refs.h | 4 ++-- refs/debug.c | 8 ++++---- refs/files-backend.c | 12 ++++++------ refs/packed-backend.c | 8 ++++---- refs/refs-internal.h | 8 ++++---- refs/reftable-backend.c | 10 +++++----- setup.c | 2 +- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/builtin/worktree.c b/builtin/worktree.c index 108cfa156a..49d9632aa8 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -509,7 +509,7 @@ static int add_worktree(const char *path, const char *refname, } wt_refs = get_worktree_ref_store(wt); - ret = refs_init_db(wt_refs, REFS_INIT_DB_IS_WORKTREE, &sb); + ret = ref_store_create_on_disk(wt_refs, REF_STORE_CREATE_ON_DISK_IS_WORKTREE, &sb); if (ret) goto done; diff --git a/refs.c b/refs.c index a26c50a401..ebc6de81e9 100644 --- a/refs.c +++ b/refs.c @@ -1938,9 +1938,9 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs, } /* backend functions */ -int refs_init_db(struct ref_store *refs, int flags, struct strbuf *err) +int ref_store_create_on_disk(struct ref_store *refs, int flags, struct strbuf *err) { - return refs->be->init_db(refs, flags, err); + return refs->be->create_on_disk(refs, flags, err); } int resolve_gitlink_ref(const char *submodule, const char *refname, diff --git a/refs.h b/refs.h index d02dd79ca6..421ff9fdb7 100644 --- a/refs.h +++ b/refs.h @@ -114,9 +114,9 @@ int should_autocreate_reflog(const char *refname); int is_branch(const char *refname); -#define REFS_INIT_DB_IS_WORKTREE (1 << 0) +#define REF_STORE_CREATE_ON_DISK_IS_WORKTREE (1 << 0) -int refs_init_db(struct ref_store *refs, int flags, struct strbuf *err); +int ref_store_create_on_disk(struct ref_store *refs, int flags, struct strbuf *err); /* * Return the peeled value of the oid currently being iterated via diff --git a/refs/debug.c b/refs/debug.c index c7531b17f0..4cc4910974 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -33,11 +33,11 @@ struct ref_store *maybe_debug_wrap_ref_store(const char *gitdir, struct ref_stor return (struct ref_store *)res; } -static int debug_init_db(struct ref_store *refs, int flags, struct strbuf *err) +static int debug_create_on_disk(struct ref_store *refs, int flags, struct strbuf *err) { struct debug_ref_store *drefs = (struct debug_ref_store *)refs; - int res = drefs->refs->be->init_db(drefs->refs, flags, err); - trace_printf_key(&trace_refs, "init_db: %d\n", res); + int res = drefs->refs->be->create_on_disk(drefs->refs, flags, err); + trace_printf_key(&trace_refs, "create_on_disk: %d\n", res); return res; } @@ -427,7 +427,7 @@ static int debug_reflog_expire(struct ref_store *ref_store, const char *refname, struct ref_storage_be refs_be_debug = { .name = "debug", .init = NULL, - .init_db = debug_init_db, + .create_on_disk = debug_create_on_disk, /* * None of these should be NULL. If the "files" backend (in diff --git a/refs/files-backend.c b/refs/files-backend.c index 2c9d5e0747..f9f15d1f76 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3236,12 +3236,12 @@ static int files_reflog_expire(struct ref_store *ref_store, return -1; } -static int files_init_db(struct ref_store *ref_store, - int flags, - struct strbuf *err UNUSED) +static int files_ref_store_create_on_disk(struct ref_store *ref_store, + int flags, + struct strbuf *err UNUSED) { struct files_ref_store *refs = - files_downcast(ref_store, REF_STORE_WRITE, "init_db"); + files_downcast(ref_store, REF_STORE_WRITE, "create"); struct strbuf sb = STRBUF_INIT; /* @@ -3264,7 +3264,7 @@ static int files_init_db(struct ref_store *ref_store, * There is no need to create directories for common refs when creating * a worktree ref store. */ - if (!(flags & REFS_INIT_DB_IS_WORKTREE)) { + if (!(flags & REF_STORE_CREATE_ON_DISK_IS_WORKTREE)) { /* * Create .git/refs/{heads,tags} */ @@ -3284,7 +3284,7 @@ static int files_init_db(struct ref_store *ref_store, struct ref_storage_be refs_be_files = { .name = "files", .init = files_ref_store_init, - .init_db = files_init_db, + .create_on_disk = files_ref_store_create_on_disk, .transaction_prepare = files_transaction_prepare, .transaction_finish = files_transaction_finish, .transaction_abort = files_transaction_abort, diff --git a/refs/packed-backend.c b/refs/packed-backend.c index a3c5a75073..b94183034e 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1244,9 +1244,9 @@ int packed_refs_is_locked(struct ref_store *ref_store) static const char PACKED_REFS_HEADER[] = "# pack-refs with: peeled fully-peeled sorted \n"; -static int packed_ref_store_init_db(struct ref_store *ref_store UNUSED, - int flags UNUSED, - struct strbuf *err UNUSED) +static int packed_ref_store_create_on_disk(struct ref_store *ref_store UNUSED, + int flags UNUSED, + struct strbuf *err UNUSED) { /* Nothing to do. */ return 0; @@ -1707,7 +1707,7 @@ static struct ref_iterator *packed_reflog_iterator_begin(struct ref_store *ref_s struct ref_storage_be refs_be_packed = { .name = "packed", .init = packed_ref_store_init, - .init_db = packed_ref_store_init_db, + .create_on_disk = packed_ref_store_create_on_disk, .transaction_prepare = packed_transaction_prepare, .transaction_finish = packed_transaction_finish, .transaction_abort = packed_transaction_abort, diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 56641aa57a..c3d5f0a6cd 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -530,9 +530,9 @@ typedef struct ref_store *ref_store_init_fn(struct repository *repo, const char *gitdir, unsigned int flags); -typedef int ref_init_db_fn(struct ref_store *refs, - int flags, - struct strbuf *err); +typedef int ref_store_create_on_disk_fn(struct ref_store *refs, + int flags, + struct strbuf *err); typedef int ref_transaction_prepare_fn(struct ref_store *refs, struct ref_transaction *transaction, @@ -668,7 +668,7 @@ typedef int read_symbolic_ref_fn(struct ref_store *ref_store, const char *refnam struct ref_storage_be { const char *name; ref_store_init_fn *init; - ref_init_db_fn *init_db; + ref_store_create_on_disk_fn *create_on_disk; ref_transaction_prepare_fn *transaction_prepare; ref_transaction_finish_fn *transaction_finish; diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 010ef811b6..8583a0cdba 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -293,12 +293,12 @@ static struct ref_store *reftable_be_init(struct repository *repo, return &refs->base; } -static int reftable_be_init_db(struct ref_store *ref_store, - int flags UNUSED, - struct strbuf *err UNUSED) +static int reftable_be_create_on_disk(struct ref_store *ref_store, + int flags UNUSED, + struct strbuf *err UNUSED) { struct reftable_ref_store *refs = - reftable_be_downcast(ref_store, REF_STORE_WRITE, "init_db"); + reftable_be_downcast(ref_store, REF_STORE_WRITE, "create"); struct strbuf sb = STRBUF_INIT; strbuf_addf(&sb, "%s/reftable", refs->base.gitdir); @@ -2248,7 +2248,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store, struct ref_storage_be refs_be_reftable = { .name = "reftable", .init = reftable_be_init, - .init_db = reftable_be_init_db, + .create_on_disk = reftable_be_create_on_disk, .transaction_prepare = reftable_be_transaction_prepare, .transaction_finish = reftable_be_transaction_finish, .transaction_abort = reftable_be_transaction_abort, diff --git a/setup.c b/setup.c index c7d3375645..fec6bfd5fa 100644 --- a/setup.c +++ b/setup.c @@ -2049,7 +2049,7 @@ void create_reference_database(unsigned int ref_storage_format, int reinit = is_reinit(); repo_set_ref_storage_format(the_repository, ref_storage_format); - if (refs_init_db(get_main_ref_store(the_repository), 0, &err)) + if (ref_store_create_on_disk(get_main_ref_store(the_repository), 0, &err)) die("failed to set up refs db: %s", err.buf); /* From patchwork Fri May 17 08:18:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13666710 Received: from wfhigh1-smtp.messagingengine.com (wfhigh1-smtp.messagingengine.com [64.147.123.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2951D2C84F for ; Fri, 17 May 2024 08:18:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933911; cv=none; b=JJpLwi3ertWMAtyIna4dVOA9RslwlaswLYSaY4cAVMwcJe0IaH/K1EPahbfJYA7spK8FfSAR02ewMgM5UmZ8RjDnxj6yuQu+v/tIJ9ONpY1rMrWDExiqvycuSFZHZ8mXkHlyf7LSMbmQiyHvcxhn9L8ZGf0sgvNLr5BObAs8Wbk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933911; c=relaxed/simple; bh=RtPTLJCIVWZtes3eionGmcAAfVUM2XEHosvS4hhvj9k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OHuHtq3VkGxyy7vZ0YpaH/HJoCscwItDIgLeqpWeykCfCGVsRCfT3EZADPFxa8HiSyJo1SVI19aHtEICz+y1RLVh4YGUul9PR8zRI+sI5RjuTrXGFYOGe8Q/TAzeypXoCb4mwgmlC2rlCgvT6vbadSmWb0BT8wskpdqOzhJ7pIs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=owzS2xem; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bJ8+nY/Y; arc=none smtp.client-ip=64.147.123.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="owzS2xem"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bJ8+nY/Y" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.west.internal (Postfix) with ESMTP id 5E3111800178; Fri, 17 May 2024 04:18:29 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Fri, 17 May 2024 04:18:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715933908; x=1716020308; bh=sX2dim/a+y 0HOVdN4fZsXDC7reBXDxl30hFATI6Ei+k=; b=owzS2xemZymX3++kmGUVmx9VnR AK8H3wFn01SjZHwSIsp1+XMiDHD+HBh24JFJKqsI5x7bLCd8U0YCMAsUJQMFpJn4 H5ZKAQSSp6rynryhz1WgpgyXf4waMnxCIh6uLp/gmpHvyykopkT1BWDn0ZO/Lq/c dyLn8Mqd0h9Nqhmf5ttym9Gx7Qelz/SK2DyCmJ9PlmnSlofUhe+hK2rAIW4D2A0P 4Yt0/tvNn7nR0mAl/a/P/LHTfHVoCDHSr6HBhS2lvkNzIEUkyZFr7lxUOjQoqngj pqDXsJcm85/frhS2qoND9DEhVBGpfPBAKaOtiyIiZNaQcZWj13SGK+DmllJw== 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=1715933908; x=1716020308; bh=sX2dim/a+y0HOVdN4fZsXDC7reBX Dxl30hFATI6Ei+k=; b=bJ8+nY/YBvVpCssyzA9uMwdw5kNVc6q1455uZz6gkc2V YivTmpUuQ8+3LLVHTUEnGkVLdTEpbNI/rSK65Qrregx1l3O1y0VHc9zp8pF6bYpx dy4jrOolt0Ua1D/k92oDuSMiHy+EZWCcTNImxFh74gCOvTNpQCX+2XGn3pL2dL4E n9G7K7/0og+ppynDgLuPGxHbrESG3duHJfGnZfT0AiV9d0f/2Cc9DG8YEY4VXSEP cemKcHXE0wgR6gbVSBF5UX19fL3eG5Zqvq35Femip0/hSXmrDzHAkmwPA6UwrMZ1 6cNPi7R7FSpRq+6OGN2kBNQF4OZK3hSMBI46zxq+6w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:18:26 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 9fbe0f9b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:17:59 +0000 (UTC) Date: Fri, 17 May 2024 10:18:24 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 03/16] refs: implement releasing ref storages Message-ID: <4beecb09445f050eecaff079d7cc873ddce62706.1715929858.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: Ref storages are typically only initialized once for `the_repository` and then never released. Until now we got away with that without causing memory leaks because `the_repository` stays reachable, and because the ref backend is reachable via `the_repository` its memory basically never leaks. This is about to change though because of the upcoming migration logic, which will create a secondary ref storage. In that case, we will either have to release the old or new ref storage to avoid leaks. Implement a new `release` callback and expose it via a new `ref_storage_release()` function. Signed-off-by: Patrick Steinhardt --- refs.c | 6 ++++++ refs.h | 5 +++++ refs/debug.c | 8 ++++++++ refs/files-backend.c | 10 ++++++++++ refs/packed-backend.c | 11 +++++++++++ refs/refs-internal.h | 5 +++++ refs/reftable-backend.c | 23 +++++++++++++++++++++++ 7 files changed, 68 insertions(+) diff --git a/refs.c b/refs.c index ebc6de81e9..0f4d327c47 100644 --- a/refs.c +++ b/refs.c @@ -2041,6 +2041,12 @@ static struct ref_store *ref_store_init(struct repository *repo, return refs; } +void ref_store_release(struct ref_store *ref_store) +{ + ref_store->be->release(ref_store); + free(ref_store->gitdir); +} + struct ref_store *get_main_ref_store(struct repository *r) { if (r->refs_private) diff --git a/refs.h b/refs.h index 421ff9fdb7..b11c250e8a 100644 --- a/refs.h +++ b/refs.h @@ -118,6 +118,11 @@ int is_branch(const char *refname); int ref_store_create_on_disk(struct ref_store *refs, int flags, struct strbuf *err); +/* + * Release all memory and resources associated with the ref store. + */ +void ref_store_release(struct ref_store *ref_store); + /* * Return the peeled value of the oid currently being iterated via * for_each_ref(), etc. This is equivalent to calling: diff --git a/refs/debug.c b/refs/debug.c index 4cc4910974..3a063077ba 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -33,6 +33,13 @@ struct ref_store *maybe_debug_wrap_ref_store(const char *gitdir, struct ref_stor return (struct ref_store *)res; } +static void debug_release(struct ref_store *refs) +{ + struct debug_ref_store *drefs = (struct debug_ref_store *)refs; + drefs->refs->be->release(drefs->refs); + trace_printf_key(&trace_refs, "release\n"); +} + static int debug_create_on_disk(struct ref_store *refs, int flags, struct strbuf *err) { struct debug_ref_store *drefs = (struct debug_ref_store *)refs; @@ -427,6 +434,7 @@ static int debug_reflog_expire(struct ref_store *ref_store, const char *refname, struct ref_storage_be refs_be_debug = { .name = "debug", .init = NULL, + .release = debug_release, .create_on_disk = debug_create_on_disk, /* diff --git a/refs/files-backend.c b/refs/files-backend.c index f9f15d1f76..62acd2721d 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -149,6 +149,14 @@ static struct files_ref_store *files_downcast(struct ref_store *ref_store, return refs; } +static void files_ref_store_release(struct ref_store *ref_store) +{ + struct files_ref_store *refs = files_downcast(ref_store, 0, "release"); + free_ref_cache(refs->loose); + free(refs->gitcommondir); + ref_store_release(refs->packed_ref_store); +} + static void files_reflog_path(struct files_ref_store *refs, struct strbuf *sb, const char *refname) @@ -3284,7 +3292,9 @@ static int files_ref_store_create_on_disk(struct ref_store *ref_store, struct ref_storage_be refs_be_files = { .name = "files", .init = files_ref_store_init, + .release = files_ref_store_release, .create_on_disk = files_ref_store_create_on_disk, + .transaction_prepare = files_transaction_prepare, .transaction_finish = files_transaction_finish, .transaction_abort = files_transaction_abort, diff --git a/refs/packed-backend.c b/refs/packed-backend.c index b94183034e..9c98e6295f 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -252,6 +252,15 @@ static void clear_snapshot(struct packed_ref_store *refs) } } +static void packed_ref_store_release(struct ref_store *ref_store) +{ + struct packed_ref_store *refs = packed_downcast(ref_store, 0, "release"); + clear_snapshot(refs); + rollback_lock_file(&refs->lock); + delete_tempfile(&refs->tempfile); + free(refs->path); +} + static NORETURN void die_unterminated_line(const char *path, const char *p, size_t len) { @@ -1707,7 +1716,9 @@ static struct ref_iterator *packed_reflog_iterator_begin(struct ref_store *ref_s struct ref_storage_be refs_be_packed = { .name = "packed", .init = packed_ref_store_init, + .release = packed_ref_store_release, .create_on_disk = packed_ref_store_create_on_disk, + .transaction_prepare = packed_transaction_prepare, .transaction_finish = packed_transaction_finish, .transaction_abort = packed_transaction_abort, diff --git a/refs/refs-internal.h b/refs/refs-internal.h index c3d5f0a6cd..8624477e19 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -529,6 +529,10 @@ struct ref_store; typedef struct ref_store *ref_store_init_fn(struct repository *repo, const char *gitdir, unsigned int flags); +/* + * Release all memory and resources associated with the ref store. + */ +typedef void ref_store_release_fn(struct ref_store *refs); typedef int ref_store_create_on_disk_fn(struct ref_store *refs, int flags, @@ -668,6 +672,7 @@ typedef int read_symbolic_ref_fn(struct ref_store *ref_store, const char *refnam struct ref_storage_be { const char *name; ref_store_init_fn *init; + ref_store_release_fn *release; ref_store_create_on_disk_fn *create_on_disk; ref_transaction_prepare_fn *transaction_prepare; diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 8583a0cdba..7b73f73f59 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -293,6 +293,27 @@ static struct ref_store *reftable_be_init(struct repository *repo, return &refs->base; } +static void reftable_be_release(struct ref_store *ref_store) +{ + struct reftable_ref_store *refs = reftable_be_downcast(ref_store, 0, "release"); + struct strmap_entry *entry; + struct hashmap_iter iter; + + if (refs->main_stack) { + reftable_stack_destroy(refs->main_stack); + refs->main_stack = NULL; + } + + if (refs->worktree_stack) { + reftable_stack_destroy(refs->worktree_stack); + refs->worktree_stack = NULL; + } + + strmap_for_each_entry(&refs->worktree_stacks, &iter, entry) + reftable_stack_destroy(entry->value); + strmap_clear(&refs->worktree_stacks, 0); +} + static int reftable_be_create_on_disk(struct ref_store *ref_store, int flags UNUSED, struct strbuf *err UNUSED) @@ -2248,7 +2269,9 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store, struct ref_storage_be refs_be_reftable = { .name = "reftable", .init = reftable_be_init, + .release = reftable_be_release, .create_on_disk = reftable_be_create_on_disk, + .transaction_prepare = reftable_be_transaction_prepare, .transaction_finish = reftable_be_transaction_finish, .transaction_abort = reftable_be_transaction_abort, From patchwork Fri May 17 08:18: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: 13666711 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 406C62D044 for ; Fri, 17 May 2024 08:18:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933914; cv=none; b=oalsunKu5JnrJnYe5Upg6e2DCfiLBxAylHj982/3qJTXjlSd2VDrxuUwKHgCuofTM2t8GJRj+ZEk5pAwCKa7NDwG+g6+IR4qRgT9vEHvZqcrHfoNBduqSRXehEocr4Ktszu2qH3sjVh1HfNSmyX1isAFWr5S3jE9UixhfkqvB+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933914; c=relaxed/simple; bh=PnegIze7+EVfUYQRnqi1Gv7y3Pd+Hmr8mtQgtADAm9A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SxBAUsmey0z8zKT8JKC58WKL6YOaFy9Azb/0Ne6bM3uOP944bepC5tzewTSd8Az3dHUW1eUl6Ol7cyV7mMseKRCtQ76C+qdLczkZy9ZWUGXmyFrMOHf1SlKe1dRv1hQ24C4mwsoXg/ep42TuWTdJhVMH7PcEH6+DPf3wCATvBvQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=DlQmIqUT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Bg6YRaOL; arc=none smtp.client-ip=64.147.123.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="DlQmIqUT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Bg6YRaOL" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id 5CA971C00092; Fri, 17 May 2024 04:18:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 17 May 2024 04:18: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=1715933912; x=1716020312; bh=Af34vpjTvR 2fhCrGeicJzUbgANvzPftkFk2PMQEntdQ=; b=DlQmIqUTHUU2w6XBR93XD6kJak yR3hu6VsFXdbMYlKBeaxHuNvc6npBaglpL3ToEM/YbczJXnLnI4cbm7kioHESjdc 5bwGfu1zDmGgZni8uGWCilPdFd4H1e+OIkp40fdOXw7wrm1cbjsaG2wY0G3nGLca yOadp66AbE1v6hdURr29UAmE7KeEtUf0P3u+hme1znrzyZNZiAP3wn7/reEXNbdT 3DoN4KwYW3gc1j+Drwo26EtcyGDdt+iv0I4vUYxhPdZfde+7IO1NwfvF4Vbr14ef slXvdzk1SBoq3JmHZy+76WuvJ/3ybfAU6c27nmK5wMD1n5PP47tyQ1F08/pQ== 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=1715933912; x=1716020312; bh=Af34vpjTvR2fhCrGeicJzUbgANvz PftkFk2PMQEntdQ=; b=Bg6YRaOLQOrbje7X/vOGZJYuYszpBLB25DY7SWLkHFOO K3Dw3IUhc43bs1hwuMCF7gAmVmJ2we7pm4fg8OZfk3X4jeG46Ww1FYo3IU4KLXmK L3/V9X4irFnCCPUIU02v6wZLfzJZTEFDWpKVjiUFSBJRcGGD2EK1Vi2rexo8LWFJ eOarh1Zpdpjmvyw/Lq8yv2oBc+NOg9A2kPvP/srEkTPt47usbRC0v3QYTXmT4KgP 1Q9sJeAVgEP4Z2SnAwSm/Nh1T1skV/udPIT2hUvo8pKCQiq/1GDzw+xBLL+gH89h m/bR+JBK6366TJJ2gRNc2MU5XlpKE+yltQSwOrHvsA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:18:30 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id c10b93cc (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:18:04 +0000 (UTC) Date: Fri, 17 May 2024 10:18:28 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 04/16] refs: track ref stores via strmap Message-ID: <9ca54a12e892a188ba54922c8cbb0e8ceffab0f4.1715929858.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 refs code has two global maps that track the submodule and worktree ref stores. Even though both of these maps track values by strings, we still use a `struct hashmap` instead of a `struct strmap`. This has the benefit of saving us an allocation because we can combine key and value in a single struct. But it does introduce significant complexity that is completely unneeded. Refactor the code to use `struct strmap`s instead to reduce complexity. It's unlikely that this will have any real-world impact on performance given that most repositories likely won't have all that many ref stores. Furthermore, this refactoring allows us to de-globalize those maps and move them into `struct repository` in a subsequent commit more easily. Signed-off-by: Patrick Steinhardt --- refs.c | 71 ++++++++++++---------------------------------------------- 1 file changed, 14 insertions(+), 57 deletions(-) diff --git a/refs.c b/refs.c index 0f4d327c47..01e8453930 100644 --- a/refs.c +++ b/refs.c @@ -6,7 +6,7 @@ #include "advice.h" #include "config.h" #include "environment.h" -#include "hashmap.h" +#include "strmap.h" #include "gettext.h" #include "hex.h" #include "lockfile.h" @@ -1960,66 +1960,27 @@ int resolve_gitlink_ref(const char *submodule, const char *refname, return 0; } -struct ref_store_hash_entry -{ - struct hashmap_entry ent; - - struct ref_store *refs; - - /* NUL-terminated identifier of the ref store: */ - char name[FLEX_ARRAY]; -}; +/* A strmap of ref_stores, stored by submodule name: */ +static struct strmap submodule_ref_stores; -static int ref_store_hash_cmp(const void *cmp_data UNUSED, - const struct hashmap_entry *eptr, - const struct hashmap_entry *entry_or_key, - const void *keydata) -{ - const struct ref_store_hash_entry *e1, *e2; - const char *name; - - e1 = container_of(eptr, const struct ref_store_hash_entry, ent); - e2 = container_of(entry_or_key, const struct ref_store_hash_entry, ent); - name = keydata ? keydata : e2->name; - - return strcmp(e1->name, name); -} - -static struct ref_store_hash_entry *alloc_ref_store_hash_entry( - const char *name, struct ref_store *refs) -{ - struct ref_store_hash_entry *entry; - - FLEX_ALLOC_STR(entry, name, name); - hashmap_entry_init(&entry->ent, strhash(name)); - entry->refs = refs; - return entry; -} - -/* A hashmap of ref_stores, stored by submodule name: */ -static struct hashmap submodule_ref_stores; - -/* A hashmap of ref_stores, stored by worktree id: */ -static struct hashmap worktree_ref_stores; +/* A strmap of ref_stores, stored by worktree id: */ +static struct strmap worktree_ref_stores; /* * Look up a ref store by name. If that ref_store hasn't been * registered yet, return NULL. */ -static struct ref_store *lookup_ref_store_map(struct hashmap *map, +static struct ref_store *lookup_ref_store_map(struct strmap *map, const char *name) { - struct ref_store_hash_entry *entry; - unsigned int hash; + struct strmap_entry *entry; - if (!map->tablesize) + if (!map->map.tablesize) /* It's initialized on demand in register_ref_store(). */ return NULL; - hash = strhash(name); - entry = hashmap_get_entry_from_hash(map, hash, name, - struct ref_store_hash_entry, ent); - return entry ? entry->refs : NULL; + entry = strmap_get_entry(map, name); + return entry ? entry->value : NULL; } /* @@ -2064,18 +2025,14 @@ struct ref_store *get_main_ref_store(struct repository *r) * Associate a ref store with a name. It is a fatal error to call this * function twice for the same name. */ -static void register_ref_store_map(struct hashmap *map, +static void register_ref_store_map(struct strmap *map, const char *type, struct ref_store *refs, const char *name) { - struct ref_store_hash_entry *entry; - - if (!map->tablesize) - hashmap_init(map, ref_store_hash_cmp, NULL, 0); - - entry = alloc_ref_store_hash_entry(name, refs); - if (hashmap_put(map, &entry->ent)) + if (!map->map.tablesize) + strmap_init(map); + if (strmap_put(map, name, refs)) BUG("%s ref_store '%s' initialized twice", type, name); } From patchwork Fri May 17 08:18:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13666712 Received: from wfhigh1-smtp.messagingengine.com (wfhigh1-smtp.messagingengine.com [64.147.123.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F3282E652 for ; Fri, 17 May 2024 08:18:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933920; cv=none; b=kaAOaMqi5479jJfDSchFOB/tfcGYGlMVaNbmFTX+NaRh6K5iAPyROFxPvq3XfrOZuwEmqGycQrrXAxI/00wGeTTtdEVdsDWhRljooquRxw+JG/g0FrP8KyYvUxGy1gDKAhtepbnL/qdj5t7EiYj+GMZvt5u1i0Ruav81JU9Crvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933920; c=relaxed/simple; bh=yBl6rn+8NhXBo+p5CbvJixqs7wpevVq0lVTnqojL6L0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UmuIuRI+lK2rvV69nbwPBeHiuTRiXhRkXojJpO4E0Xxbwpb5RATDEr/mt8dFSc0iFRcJZJaCRN9m8LSsfpsnXwBJ+jfB4igeBleZMjnejsjuFZqX2QI88gk0voo4n6MjP/qpeDBDvjln11G8T4FXcTC51sc3/vVBcPcmrFPAmBI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=XvItfleZ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Rh/I4GXr; arc=none smtp.client-ip=64.147.123.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="XvItfleZ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Rh/I4GXr" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id 4CF451800173; Fri, 17 May 2024 04:18:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 17 May 2024 04:18:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715933917; x=1716020317; bh=BbWc4aFKKU mq0OvDhfwO6wG9ew20J1qpN6FkkIBlTf8=; b=XvItfleZfv+SPY3BqQL00q/MRb QbNh8Sq6dl/9F7DpE1F/dblEGkRwycvX8SLoW/zejkOhrgIvsUc350COaBS8Wcsx vcUtGVcgTyHFRrGQR5Ha2g/louQgrr7JZc6Eu5S5ozMvZbyqYfwC3IXouiOqj7r+ Nnj2p2L9donQ9c40Cfr3ZCrqpBH3gLzLgw66Z08GOBWdexv+WaWirJH/gDqhwrK0 rwOKPJG3POmtNc8/8fTHFojOSw4/VHJkDO+hwrCn3zHk1Ji+HTuAEc8YKvLECbHE iu/ueULPMm+Q1RNSTov5ySsOinT1A2tBqYb9iKm/brBdGp214ZT3sm/TYt6g== 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=1715933917; x=1716020317; bh=BbWc4aFKKUmq0OvDhfwO6wG9ew20 J1qpN6FkkIBlTf8=; b=Rh/I4GXrafI+ygZPJAlcjO8TLaKwQcCYWQbvmCw5VujG jFPKY0pkuJ5DP3LAN38i5ygvVg80xn0MVJPFhc4DFyIZpxBhN3o3gE0PPvI7e0Ll uH+29LHWU1G/B2GK/8dAuhhMCGIUbakyo5SwzRfRQpkLfc4uqagzZWDfSkujZeP1 Fg+nQC3mdib2sL0FqCQpTAl1TDlVFoMvBzmQCOA8ycnBi7OGcjie+IysIY4MV9ND DIXn2byl4+CbLbOOAT4x+iiGD/wtrqODHy6TUvT7lIxfBKubAM3LC0EJ7uT87Lil Fnyp9qirIc4PNmzAi1/l3Ph9vtJ6BEA58A8T+KmUbQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:18:36 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 0fcb5c59 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:18:09 +0000 (UTC) Date: Fri, 17 May 2024 10:18:34 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 05/16] refs: pass repo when retrieving submodule ref store 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: Looking up submodule ref stores has two deficiencies: - The initialized subrepo will be attributed to `the_repository`. - The submodule ref store will be tracked in a global map. This makes it impossible to have submodule ref stores for a repository other than `the_repository`. Modify the function to accept the parent repository as parameter and move the global map into `struct repository`. Like this it becomes possible to look up submodule ref stores for arbitrary repositories. Note that this also adds a new reference to `the_repository` in `resolve_gitlink_ref()`, which is part of the refs interfaces. This will get adjusted in the next patch. Signed-off-by: Patrick Steinhardt --- builtin/submodule--helper.c | 6 ++++-- refs.c | 22 +++++++--------------- refs.h | 3 ++- refs/refs-internal.h | 2 +- repository.c | 8 ++++++++ repository.h | 8 ++++++++ submodule.c | 3 ++- t/helper/test-ref-store.c | 2 +- 8 files changed, 33 insertions(+), 21 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index e604cb5ddb..5076a33500 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -679,7 +679,8 @@ static void status_submodule(const char *path, const struct object_id *ce_oid, displaypath); } else if (!(flags & OPT_CACHED)) { struct object_id oid; - struct ref_store *refs = get_submodule_ref_store(path); + struct ref_store *refs = repo_get_submodule_ref_store(the_repository, + path); if (!refs) { print_status(flags, '-', path, ce_oid, displaypath); @@ -903,7 +904,8 @@ static void generate_submodule_summary(struct summary_cb *info, if (!info->cached && oideq(&p->oid_dst, null_oid())) { if (S_ISGITLINK(p->mod_dst)) { - struct ref_store *refs = get_submodule_ref_store(p->sm_path); + struct ref_store *refs = repo_get_submodule_ref_store(the_repository, + p->sm_path); if (refs) refs_head_ref(refs, handle_submodule_head_ref, &p->oid_dst); diff --git a/refs.c b/refs.c index 01e8453930..1d660d5ace 100644 --- a/refs.c +++ b/refs.c @@ -1949,8 +1949,7 @@ int resolve_gitlink_ref(const char *submodule, const char *refname, struct ref_store *refs; int flags; - refs = get_submodule_ref_store(submodule); - + refs = repo_get_submodule_ref_store(the_repository, submodule); if (!refs) return -1; @@ -1960,9 +1959,6 @@ int resolve_gitlink_ref(const char *submodule, const char *refname, return 0; } -/* A strmap of ref_stores, stored by submodule name: */ -static struct strmap submodule_ref_stores; - /* A strmap of ref_stores, stored by worktree id: */ static struct strmap worktree_ref_stores; @@ -2036,7 +2032,8 @@ static void register_ref_store_map(struct strmap *map, BUG("%s ref_store '%s' initialized twice", type, name); } -struct ref_store *get_submodule_ref_store(const char *submodule) +struct ref_store *repo_get_submodule_ref_store(struct repository *repo, + const char *submodule) { struct strbuf submodule_sb = STRBUF_INIT; struct ref_store *refs; @@ -2057,7 +2054,7 @@ struct ref_store *get_submodule_ref_store(const char *submodule) /* We need to strip off one or more trailing slashes */ submodule = to_free = xmemdupz(submodule, len); - refs = lookup_ref_store_map(&submodule_ref_stores, submodule); + refs = lookup_ref_store_map(&repo->submodule_ref_stores, submodule); if (refs) goto done; @@ -2069,20 +2066,15 @@ struct ref_store *get_submodule_ref_store(const char *submodule) goto done; subrepo = xmalloc(sizeof(*subrepo)); - /* - * NEEDSWORK: Make get_submodule_ref_store() work with arbitrary - * superprojects other than the_repository. This probably should be - * done by making it take a struct repository * parameter instead of a - * submodule path. - */ - if (repo_submodule_init(subrepo, the_repository, submodule, + + if (repo_submodule_init(subrepo, repo, submodule, null_oid())) { free(subrepo); goto done; } refs = ref_store_init(subrepo, submodule_sb.buf, REF_STORE_READ | REF_STORE_ODB); - register_ref_store_map(&submodule_ref_stores, "submodule", + register_ref_store_map(&repo->submodule_ref_stores, "submodule", refs, submodule); done: diff --git a/refs.h b/refs.h index b11c250e8a..346a81e9e3 100644 --- a/refs.h +++ b/refs.h @@ -954,7 +954,8 @@ struct ref_store *get_main_ref_store(struct repository *r); * For backwards compatibility, submodule=="" is treated the same as * submodule==NULL. */ -struct ref_store *get_submodule_ref_store(const char *submodule); +struct ref_store *repo_get_submodule_ref_store(struct repository *repo, + const char *submodule); struct ref_store *get_worktree_ref_store(const struct worktree *wt); /* diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 8624477e19..178a355eb0 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -705,7 +705,7 @@ extern struct ref_storage_be refs_be_packed; /* * A representation of the reference store for the main repository or * a submodule. The ref_store instances for submodules are kept in a - * hash map; see get_submodule_ref_store() for more info. + * hash map; see repo_get_submodule_ref_store() for more info. */ struct ref_store { /* The backend describing this ref_store's storage scheme: */ diff --git a/repository.c b/repository.c index c50849fd83..bb9b9e2b52 100644 --- a/repository.c +++ b/repository.c @@ -14,6 +14,7 @@ #include "sparse-index.h" #include "trace2.h" #include "promisor-remote.h" +#include "refs.h" /* The main repository */ static struct repository the_repo; @@ -289,6 +290,9 @@ static void repo_clear_path_cache(struct repo_path_cache *cache) void repo_clear(struct repository *repo) { + struct hashmap_iter iter; + struct strmap_entry *e; + FREE_AND_NULL(repo->gitdir); FREE_AND_NULL(repo->commondir); FREE_AND_NULL(repo->graft_file); @@ -329,6 +333,10 @@ void repo_clear(struct repository *repo) FREE_AND_NULL(repo->remote_state); } + strmap_for_each_entry(&repo->submodule_ref_stores, &iter, e) + ref_store_release(e->value); + strmap_clear(&repo->submodule_ref_stores, 1); + repo_clear_path_cache(&repo->cached_paths); } diff --git a/repository.h b/repository.h index 41ed22543a..0389df0461 100644 --- a/repository.h +++ b/repository.h @@ -1,6 +1,8 @@ #ifndef REPOSITORY_H #define REPOSITORY_H +#include "strmap.h" + struct config_set; struct fsmonitor_settings; struct git_hash_algo; @@ -108,6 +110,12 @@ struct repository { */ struct ref_store *refs_private; + /* + * A strmap of ref_stores, stored by submodule name, accessible via + * `repo_get_submodule_ref_store()`. + */ + struct strmap submodule_ref_stores; + /* * Contains path to often used file names. */ diff --git a/submodule.c b/submodule.c index f6313cd99f..759cf1e1cd 100644 --- a/submodule.c +++ b/submodule.c @@ -99,7 +99,8 @@ int is_staging_gitmodules_ok(struct index_state *istate) static int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) { - return refs_for_each_remote_ref(get_submodule_ref_store(submodule), + return refs_for_each_remote_ref(repo_get_submodule_ref_store(the_repository, + submodule), fn, cb_data); } diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index 82bbf6e2e6..a5a7609811 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -82,7 +82,7 @@ static const char **get_store(const char **argv, struct ref_store **refs) add_to_alternates_memory(sb.buf); strbuf_release(&sb); - *refs = get_submodule_ref_store(gitdir); + *refs = repo_get_submodule_ref_store(the_repository, gitdir); } else if (skip_prefix(argv[0], "worktree:", &gitdir)) { struct worktree **p, **worktrees = get_worktrees(); From patchwork Fri May 17 08:18:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13666713 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3327436137 for ; Fri, 17 May 2024 08:18:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933925; cv=none; b=JNZ8ghdY8HFeBu9WTQ/vnpwJxGnyqmkTkp7ctU1Zt7nutY9/5Xd4W/6iKzG5XI+RbSOq+Cjnq+NT1FOTmVAe0CH9gqV/WZmLA49QHRrkwy4r1t0FOopT+n7COAlWMwAqbqREgpSxHvdyHtoo2ApQxnrUt0ZtSocIkrJp1Z207c4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933925; c=relaxed/simple; bh=EW13sedVTtNPQrj94I72CCYclpGNi4MtFz1XYoFg91M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=H+snHUCw8/C7Mcjn6+M+hs3aqlDOtJ/1x0srnIKiHFqVBYEuPclhOh6M3Q+VtX3c5p94635fSsmnfMCNKjqd7FDJfmIc0lpm5/V8/xYjyoe67EUtQSrrwd6pgqQwTUArjItl6F5nd0XrvTHRoBWce1IlsYVX/d+l1hhAVxZHFzc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=rsxLzYJc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=j6FbB5wp; arc=none smtp.client-ip=64.147.123.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="rsxLzYJc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="j6FbB5wp" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 41F481C000BB; Fri, 17 May 2024 04:18:43 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 17 May 2024 04:18:43 -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=1715933922; x=1716020322; bh=I1mM2lEjVH DbT9Evr6S2sAY2W8wnbqH0i8raCvyoyWw=; b=rsxLzYJcEmYrS9tPQzEys3/E7s MzkUp28BML4SdKpPckXH76HaNmaNP9xIAeM7fXdAbQjaYsz6wNv0Evbap+Qzlg1F HXfL5FeCu5lb41ufx6KI3q28IvqMGIJHNjaDPPX2R/HRFM8bmcLBVT5AeSS0I36c fyq5j5E5nPPcG6Ct22heWFvJRfXs0V5geAA/6yZ4EsjLxMw2PqOM8hjsot8xSzAH X8ivGoYrv6edhOupudsDqyxIToFAB1VdfN6vJkj+2oEVR4NDnFvd8xg1Nzr4WDQb nPEdnnvuMtu/9h2SjN5aN8GW9dQqjQk3KaoKrPHjJr65xW1okKEE364Vpz3w== 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=1715933922; x=1716020322; bh=I1mM2lEjVHDbT9Evr6S2sAY2W8wn bqH0i8raCvyoyWw=; b=j6FbB5wpAS8IwMQpE09Hixj4M+UCkDfxMEEomOWcZFCa vKXzFppPrA7pazNsay4+bcO7IVSbMrcvviSVxpyAvFaEdjdWfhzH5LkzMQvoUNKp vm4w1MoXgKs+euZ0a3vZYWnxdtQT0ojzAxq2cnQFIpsGlY0OU+WRm2qqTJtiyH7E YRYbiDMnqk1jY53KZ/FaNuFuuqhLxezyj3mEwnmagVuM2pQKFHjdyNQcyCHNPQCw t/hL5GQq+NuzrXqzuWHDWt+f5r4iltJsVNuaT0UWWpI1FZ5UJVAxU2rUB6gFcy1Q 94lEqwtysYyAYCCLbHxSwD/WemKBab7E8aIJI01fjg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:18:41 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 29cd82d8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:18:14 +0000 (UTC) Date: Fri, 17 May 2024 10:18:39 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 06/16] refs: refactor `resolve_gitlink_ref()` to accept a 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: In `resolve_gitlink_ref()` we implicitly rely on `the_repository` to look up the submodule ref store. Now that we can look up submodule ref stores for arbitrary repositories we can improve this function to instead accept a repository as parameter for which we want to resolve the gitlink. Do so and adjust callers accordingly. Signed-off-by: Patrick Steinhardt --- attr.c | 3 ++- builtin/submodule--helper.c | 8 +++++--- builtin/update-index.c | 5 +++-- combine-diff.c | 3 ++- diff-lib.c | 3 ++- dir.c | 3 ++- object-file.c | 2 +- read-cache.c | 5 +++-- refs.c | 7 ++++--- refs.h | 5 +++-- unpack-trees.c | 3 ++- 11 files changed, 29 insertions(+), 18 deletions(-) diff --git a/attr.c b/attr.c index 33473bdce0..6c6eb05333 100644 --- a/attr.c +++ b/attr.c @@ -1288,7 +1288,8 @@ static const char *builtin_object_mode_attr(struct index_state *istate, const ch if (pos >= 0) { if (S_ISGITLINK(istate->cache[pos]->ce_mode)) mode = istate->cache[pos]->ce_mode; - } else if (resolve_gitlink_ref(path, "HEAD", &oid) == 0) { + } else if (repo_resolve_gitlink_ref(the_repository, path, + "HEAD", &oid) == 0) { mode = S_IFGITLINK; } } diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 5076a33500..897f19868e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2600,7 +2600,8 @@ static int update_submodule(struct update_data *update_data) if (update_data->just_cloned) oidcpy(&update_data->suboid, null_oid()); - else if (resolve_gitlink_ref(update_data->sm_path, "HEAD", &update_data->suboid)) + else if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path, + "HEAD", &update_data->suboid)) return die_message(_("Unable to find current revision in submodule path '%s'"), update_data->displaypath); @@ -2627,7 +2628,8 @@ static int update_submodule(struct update_data *update_data) update_data->sm_path); } - if (resolve_gitlink_ref(update_data->sm_path, remote_ref, &update_data->oid)) + if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path, + remote_ref, &update_data->oid)) return die_message(_("Unable to find %s revision in submodule path '%s'"), remote_ref, update_data->sm_path); @@ -3357,7 +3359,7 @@ static void die_on_repo_without_commits(const char *path) strbuf_addstr(&sb, path); if (is_nonbare_repository_dir(&sb)) { struct object_id oid; - if (resolve_gitlink_ref(path, "HEAD", &oid) < 0) + if (repo_resolve_gitlink_ref(the_repository, path, "HEAD", &oid) < 0) die(_("'%s' does not have a commit checked out"), path); } strbuf_release(&sb); diff --git a/builtin/update-index.c b/builtin/update-index.c index 20aa1c4c68..d343416ae2 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -349,7 +349,8 @@ static int process_directory(const char *path, int len, struct stat *st) if (S_ISGITLINK(ce->ce_mode)) { /* Do nothing to the index if there is no HEAD! */ - if (resolve_gitlink_ref(path, "HEAD", &oid) < 0) + if (repo_resolve_gitlink_ref(the_repository, path, + "HEAD", &oid) < 0) return 0; return add_one_path(ce, path, len, st); @@ -375,7 +376,7 @@ static int process_directory(const char *path, int len, struct stat *st) } /* No match - should we add it as a gitlink? */ - if (!resolve_gitlink_ref(path, "HEAD", &oid)) + if (!repo_resolve_gitlink_ref(the_repository, path, "HEAD", &oid)) return add_one_path(NULL, path, len, st); /* Error out. */ diff --git a/combine-diff.c b/combine-diff.c index d6d6fa1689..4960d904ac 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -1066,7 +1066,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, elem->mode = canon_mode(st.st_mode); } else if (S_ISDIR(st.st_mode)) { struct object_id oid; - if (resolve_gitlink_ref(elem->path, "HEAD", &oid) < 0) + if (repo_resolve_gitlink_ref(the_repository, elem->path, + "HEAD", &oid) < 0) result = grab_blob(opt->repo, &elem->oid, elem->mode, &result_size, NULL, NULL); diff --git a/diff-lib.c b/diff-lib.c index 12b1541478..5a5a50c5a1 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -66,7 +66,8 @@ static int check_removed(const struct cache_entry *ce, struct stat *st) * a directory --- the blob was removed! */ if (!S_ISGITLINK(ce->ce_mode) && - resolve_gitlink_ref(ce->name, "HEAD", &sub)) + repo_resolve_gitlink_ref(the_repository, ce->name, + "HEAD", &sub)) return 1; } return 0; diff --git a/dir.c b/dir.c index 2d83f3311a..f6066cc01d 100644 --- a/dir.c +++ b/dir.c @@ -3318,7 +3318,8 @@ static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up) struct object_id submodule_head; if ((flag & REMOVE_DIR_KEEP_NESTED_GIT) && - !resolve_gitlink_ref(path->buf, "HEAD", &submodule_head)) { + !repo_resolve_gitlink_ref(the_repository, path->buf, + "HEAD", &submodule_head)) { /* Do not descend and nuke a nested git work tree. */ if (kept_up) *kept_up = 1; diff --git a/object-file.c b/object-file.c index 610b1f465c..a40300ce4a 100644 --- a/object-file.c +++ b/object-file.c @@ -2669,7 +2669,7 @@ int index_path(struct index_state *istate, struct object_id *oid, strbuf_release(&sb); break; case S_IFDIR: - return resolve_gitlink_ref(path, "HEAD", oid); + return repo_resolve_gitlink_ref(the_repository, path, "HEAD", oid); default: return error(_("%s: unsupported file type"), path); } diff --git a/read-cache.c b/read-cache.c index a6db25a16d..447109aa76 100644 --- a/read-cache.c +++ b/read-cache.c @@ -271,7 +271,8 @@ static int ce_compare_gitlink(const struct cache_entry *ce) * * If so, we consider it always to match. */ - if (resolve_gitlink_ref(ce->name, "HEAD", &oid) < 0) + if (repo_resolve_gitlink_ref(the_repository, ce->name, + "HEAD", &oid) < 0) return 0; return !oideq(&oid, &ce->oid); } @@ -711,7 +712,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, namelen = strlen(path); if (S_ISDIR(st_mode)) { - if (resolve_gitlink_ref(path, "HEAD", &oid) < 0) + if (repo_resolve_gitlink_ref(the_repository, path, "HEAD", &oid) < 0) return error(_("'%s' does not have a commit checked out"), path); while (namelen && path[namelen-1] == '/') namelen--; diff --git a/refs.c b/refs.c index 1d660d5ace..7703b7781c 100644 --- a/refs.c +++ b/refs.c @@ -1943,13 +1943,14 @@ int ref_store_create_on_disk(struct ref_store *refs, int flags, struct strbuf *e return refs->be->create_on_disk(refs, flags, err); } -int resolve_gitlink_ref(const char *submodule, const char *refname, - struct object_id *oid) +int repo_resolve_gitlink_ref(struct repository *r, + const char *submodule, const char *refname, + struct object_id *oid) { struct ref_store *refs; int flags; - refs = repo_get_submodule_ref_store(the_repository, submodule); + refs = repo_get_submodule_ref_store(r, submodule); if (!refs) return -1; diff --git a/refs.h b/refs.h index 346a81e9e3..90a7e2dde3 100644 --- a/refs.h +++ b/refs.h @@ -141,8 +141,9 @@ int peel_iterated_oid(const struct object_id *base, struct object_id *peeled); * successful, return 0 and set oid to the name of the object; * otherwise, return a non-zero value. */ -int resolve_gitlink_ref(const char *submodule, const char *refname, - struct object_id *oid); +int repo_resolve_gitlink_ref(struct repository *r, + const char *submodule, const char *refname, + struct object_id *oid); /* * Return true iff abbrev_name is a possible abbreviation for diff --git a/unpack-trees.c b/unpack-trees.c index c2b20b80d5..304ea2ed86 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -2318,7 +2318,8 @@ static int verify_clean_subdirectory(const struct cache_entry *ce, if (S_ISGITLINK(ce->ce_mode)) { struct object_id oid; - int sub_head = resolve_gitlink_ref(ce->name, "HEAD", &oid); + int sub_head = repo_resolve_gitlink_ref(the_repository, ce->name, + "HEAD", &oid); /* * If we are not going to update the submodule, then * we don't care. From patchwork Fri May 17 08:18:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13666714 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C9B4224EA for ; Fri, 17 May 2024 08:18:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933930; cv=none; b=t5GizyrhGm/dm0OGWaoVWINOpfPfynYSoBz/AdNMg5MJE89kJ4Ugpg1PtNxYuGI6G0iIr3+5vVxERS4dfwXqwX8Q8c/N1FntbpFJxPHlkJDC9OLBkxzQpCcVagDtG7RSc8Jdtpbl3082z3QsFofNwbkjOp3c53aT6qyhPqkn6OM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933930; c=relaxed/simple; bh=v7TyzD+cC6z4P993xZgNx5dVRQ7iqtkPEFB4wP6FE1s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=giyY0lsIdItGjVN6cYkBTaZoeKDGaSqWrwp8Uk8SIbBBBRTnqhvDe9z2QdAdGWvgzea21RwtRYylOs+5HeX8/k/x6SfoDiYr/2ZjufE5c7tuZOOWi4slqPaHq6Irrl8UU6qX5TbCAtH9ZsHk8EwrhPVTRsqAgyrf5oYEhsBZoRo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=VeFZB87Y; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PQDk0fz8; arc=none smtp.client-ip=64.147.123.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="VeFZB87Y"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PQDk0fz8" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.west.internal (Postfix) with ESMTP id 3996C1C000BD; Fri, 17 May 2024 04:18:48 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Fri, 17 May 2024 04:18:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715933927; x=1716020327; bh=hPdlKqhlJi EU/6hG+PgkICY95T4pKZJYzrhmctHRoo8=; b=VeFZB87YvvqduaHCsnth1VE9C9 rMm7FMgB6/cT+vdFMMZx+8/Yn46w2ffyYpr+xJgdtsuL3M/fL5DliIo2Got10qid CE2R5tW77Sjc5prMo7xF6tyH49at2l9LTr0H8BxO/gLVoZz4YeXNiAoCmjB81jBL IRGQk/r2rtst/d50plZP2acioUGDuSTdWFQMvK4F7U4Eb/7g38QSsDDsmSSGVQ98 wyMnxtYLPHef3sETpBt1R9kUufzK0HeWnbxf5fbWZrAS7huqh8wuU23mECCsmKnc aH8OW7nTQPcz/ZIM1auSbyEcl0gGdC0ak2uQOIJHM/QMMUWr/CIbeGc2DBUA== 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=1715933927; x=1716020327; bh=hPdlKqhlJiEU/6hG+PgkICY95T4p KZJYzrhmctHRoo8=; b=PQDk0fz8pCEM0EuNAeSivkK7uAg5r0/T7zNotfQd+8ux XtF3QWF11v6K9FAZWycq9/gta0PK4bKSBG21jhy8xLVnLyyWdNHsd8ReifGTR94h mTawFwcDmx0tIgC6JAfbsoPSH9Skpk2+sRUoy0P4kRpgFTbFSebnj+KNTw0V7CGY 0qs/QwPfBGwGt2rdjNz86wdcxbxR8KDnVYdizGT+YlAC4Wo81GyoiLYTb/PiXb+K JnerOx4/SB8UPtTw399unbHeFOqNDaqQnIBTtrJpXA9Cd84EVYtZj/opIhnOnHGw 4FzjYAF4u4ezdtz2P8ja9da8omrRDPVm4CPPm84n1Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:18:46 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id b9db5046 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:18:19 +0000 (UTC) Date: Fri, 17 May 2024 10:18:44 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 07/16] refs: retrieve worktree ref stores via associated repository Message-ID: <977f3a8510c96b8f278852ef240e19c759a53d2c.1715929858.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: Similar as with the preceding commit, the worktree ref stores are always looked up via `the_repository`. Also, again, those ref stores are stored in a global map. Refactor the code so that worktrees have a pointer to their repository. Like this, we can move the global map into `struct repository` and stop using `the_repository`. With this change, we can now in theory look up worktree ref stores for repositories other than `the_repository`. In practice, the worktree code will need further changes to look up arbitrary worktrees. Signed-off-by: Patrick Steinhardt --- refs.c | 27 ++++++++++++++------------- repository.c | 4 ++++ repository.h | 6 ++++++ worktree.c | 2 ++ worktree.h | 2 ++ 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/refs.c b/refs.c index 7703b7781c..70e712fcef 100644 --- a/refs.c +++ b/refs.c @@ -1960,9 +1960,6 @@ int repo_resolve_gitlink_ref(struct repository *r, return 0; } -/* A strmap of ref_stores, stored by worktree id: */ -static struct strmap worktree_ref_stores; - /* * Look up a ref store by name. If that ref_store hasn't been * registered yet, return NULL. @@ -2091,25 +2088,29 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt) const char *id; if (wt->is_current) - return get_main_ref_store(the_repository); + return get_main_ref_store(wt->repo); id = wt->id ? wt->id : "/"; - refs = lookup_ref_store_map(&worktree_ref_stores, id); + refs = lookup_ref_store_map(&wt->repo->worktree_ref_stores, id); if (refs) return refs; - if (wt->id) - refs = ref_store_init(the_repository, - git_common_path("worktrees/%s", wt->id), + if (wt->id) { + struct strbuf common_path = STRBUF_INIT; + strbuf_git_common_path(&common_path, wt->repo, + "worktrees/%s", wt->id); + refs = ref_store_init(wt->repo, common_path.buf, REF_STORE_ALL_CAPS); - else - refs = ref_store_init(the_repository, - get_git_common_dir(), + strbuf_release(&common_path); + } else { + refs = ref_store_init(wt->repo, wt->repo->commondir, REF_STORE_ALL_CAPS); + } if (refs) - register_ref_store_map(&worktree_ref_stores, "worktree", - refs, id); + register_ref_store_map(&wt->repo->worktree_ref_stores, + "worktree", refs, id); + return refs; } diff --git a/repository.c b/repository.c index bb9b9e2b52..d29b0304fb 100644 --- a/repository.c +++ b/repository.c @@ -337,6 +337,10 @@ void repo_clear(struct repository *repo) ref_store_release(e->value); strmap_clear(&repo->submodule_ref_stores, 1); + strmap_for_each_entry(&repo->worktree_ref_stores, &iter, e) + ref_store_release(e->value); + strmap_clear(&repo->worktree_ref_stores, 1); + repo_clear_path_cache(&repo->cached_paths); } diff --git a/repository.h b/repository.h index 0389df0461..4bd8969005 100644 --- a/repository.h +++ b/repository.h @@ -116,6 +116,12 @@ struct repository { */ struct strmap submodule_ref_stores; + /* + * A strmap of ref_stores, stored by worktree id, accessible via + * `get_worktree_ref_store()`. + */ + struct strmap worktree_ref_stores; + /* * Contains path to often used file names. */ diff --git a/worktree.c b/worktree.c index cf5eea8c93..12eadacc61 100644 --- a/worktree.c +++ b/worktree.c @@ -65,6 +65,7 @@ static struct worktree *get_main_worktree(int skip_reading_head) strbuf_strip_suffix(&worktree_path, "/.git"); CALLOC_ARRAY(worktree, 1); + worktree->repo = the_repository; worktree->path = strbuf_detach(&worktree_path, NULL); /* * NEEDSWORK: If this function is called from a secondary worktree and @@ -98,6 +99,7 @@ struct worktree *get_linked_worktree(const char *id, strbuf_strip_suffix(&worktree_path, "/.git"); CALLOC_ARRAY(worktree, 1); + worktree->repo = the_repository; worktree->path = strbuf_detach(&worktree_path, NULL); worktree->id = xstrdup(id); if (!skip_reading_head) diff --git a/worktree.h b/worktree.h index f14784a2ff..7cc6d90e66 100644 --- a/worktree.h +++ b/worktree.h @@ -6,6 +6,8 @@ struct strbuf; struct worktree { + /* The repository this worktree belongs to. */ + struct repository *repo; char *path; char *id; char *head_ref; /* NULL if HEAD is broken or detached */ From patchwork Fri May 17 08:18:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13666715 Received: from wfhigh1-smtp.messagingengine.com (wfhigh1-smtp.messagingengine.com [64.147.123.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2225724215 for ; Fri, 17 May 2024 08:18:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933935; cv=none; b=l1letTI8nCiOCIGk+/pjuobzHKPmoFffSU1ufseNTF66eYhWT0cLnmvX87n3NJad7ITvq8Amc/9ki3UDJVqzsBVH3hGCDymYIh1n2YoSRjEUB5tdvwypXx4E90AhyjCQA6NRSviyoZ41LTAGfUdQEKBXGWV6K79bpdyA4RzL3ZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933935; c=relaxed/simple; bh=4YXQoQM9Y9hw1XSnOJme6sAwnBfbkEb07yzfXWD1qa4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jYNRy9Xh4EEbfy+ehcMS1Bebl1/E8mC+jcNmsbThdRtIj7FcMNAYnWg20D/wkzR+Da28K20FpBLyyLxgq11qqi1KWR2iUp0ErfRSuMDuDG4ERMBZOAf9g16c+Nm1XYHi6iSpzDsnDBgDgEuUdpwX+bvMV7onZ5mJHgaRm4vF1cE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=p9IBuum2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=dY2W8tH1; arc=none smtp.client-ip=64.147.123.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="p9IBuum2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="dY2W8tH1" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id 2D14E1800178; Fri, 17 May 2024 04:18:53 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 17 May 2024 04:18:53 -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=1715933932; x=1716020332; bh=CK6uec6NSq CU8ZuRMyAcNGm6d1LXPxgWyVt6KQubaHo=; b=p9IBuum2LHgyeSCrVjXCfGvFNr M5eEltWKlqnLyHljunee5F81+KdbSLsY0T92CALshB8OsgHcezIaLRsXS/hfcpqm 2rqiwXOooaSMhcDREWgiId3Hs+WCRIRvBXfsnwwKoPsPYXQC5R+73LIk3iDyzjsk w9EeB3DmMxerasq2qXUTrVlv8krfYHuPjRpDPaMutx4H+y2hEHaS81Iji12BhDvV jFLeAbqUhd2VzkVHmvXjgfvxJQj5VCrz81NHNrsBjp7/DB8N9iUPSA9I575x0vvX 0EGP+FtVJISNH82lWOQXY7inrSy6cm45b+k0IESZ/A1UJUnOTLFb0ixWNrGw== 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=1715933932; x=1716020332; bh=CK6uec6NSqCU8ZuRMyAcNGm6d1LX PxgWyVt6KQubaHo=; b=dY2W8tH1VOdTDex2l5ZSe5+kfTdqGMsi6PTbw3c9rPuT kwzu3pFpYFs/nt8WyQgKTHwtoL6+rxlzOta17jem30nLIJTRHXZwimdvFVIm3bjd dBy0pgmqvsb8F1wf5PtwXlApEA8wCH+soSFILZERJkok9e2wHpp3Cq0Wl0xQ2Yqo vJUbDcpof+ybU+cvQOZOQpylTz/gWxdwSIaXDjmmHeuo4X3It20GnKwhF+z+lT3W OifvnUfA+33ipnGoXjT5tdE8GH+2p3pZ/Kgj+TjhnX4IeL8w84dJGklQ64kfJCK3 4HWlEPiy0psuJIwRkUFXjO2f2tKNtiRqo8vkc1AIzw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:18:51 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 7e409ba4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:18:24 +0000 (UTC) Date: Fri, 17 May 2024 10:18:49 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 08/16] refs: convert iteration over replace refs to accept ref store Message-ID: <5306122d5806cf563cb6908480b78fcb12ba06c1.1715929858.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 function `for_each_replace_ref()` is a bit of an oddball across the refs interfaces as it accepts a pointer to the repository instead of a pointer to the ref store. The only reason for us to accept a repository is so that we can eventually pass it back to the callback function that the caller has provided. This is somewhat arbitrary though, as callers that need the repository can instead make it accessible via the callback payload. Refactor the function to instead accept the ref store and adjust callers accordingly. This allows us to get rid of some of the boilerplate that we had to carry to pass along the repository and brings us in line with the other functions that iterate through refs. Signed-off-by: Patrick Steinhardt --- builtin/replace.c | 13 ++++++---- refs.c | 58 ++++++-------------------------------------- refs.h | 17 ++----------- refs/iterator.c | 6 ++--- refs/refs-internal.h | 5 ++-- replace-object.c | 10 +++++--- 6 files changed, 28 insertions(+), 81 deletions(-) diff --git a/builtin/replace.c b/builtin/replace.c index bc2a948c80..b09c78b77d 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -43,11 +43,12 @@ enum replace_format { }; struct show_data { + struct repository *repo; const char *pattern; enum replace_format format; }; -static int show_reference(struct repository *r, const char *refname, +static int show_reference(const char *refname, const struct object_id *oid, int flag UNUSED, void *cb_data) { @@ -62,11 +63,11 @@ static int show_reference(struct repository *r, const char *refname, struct object_id object; enum object_type obj_type, repl_type; - if (repo_get_oid(r, refname, &object)) + if (repo_get_oid(data->repo, refname, &object)) return error(_("failed to resolve '%s' as a valid ref"), refname); - obj_type = oid_object_info(r, &object, NULL); - repl_type = oid_object_info(r, oid, NULL); + obj_type = oid_object_info(data->repo, &object, NULL); + repl_type = oid_object_info(data->repo, oid, NULL); printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type), oid_to_hex(oid), type_name(repl_type)); @@ -80,6 +81,7 @@ static int list_replace_refs(const char *pattern, const char *format) { struct show_data data; + data.repo = the_repository; if (!pattern) pattern = "*"; data.pattern = pattern; @@ -99,7 +101,8 @@ static int list_replace_refs(const char *pattern, const char *format) "valid formats are 'short', 'medium' and 'long'"), format); - for_each_replace_ref(the_repository, show_reference, (void *)&data); + refs_for_each_replace_ref(get_main_ref_store(the_repository), + show_reference, (void *)&data); return 0; } diff --git a/refs.c b/refs.c index 70e712fcef..d705add3b8 100644 --- a/refs.c +++ b/refs.c @@ -1576,53 +1576,12 @@ struct ref_iterator *refs_ref_iterator_begin( return iter; } -/* - * Call fn for each reference in the specified submodule for which the - * refname begins with prefix. If trim is non-zero, then trim that - * many characters off the beginning of each refname before passing - * the refname to fn. flags can be DO_FOR_EACH_INCLUDE_BROKEN to - * include broken references in the iteration. If fn ever returns a - * non-zero value, stop the iteration and return that value; - * otherwise, return 0. - */ -static int do_for_each_repo_ref(struct repository *r, const char *prefix, - each_repo_ref_fn fn, int trim, int flags, - void *cb_data) -{ - struct ref_iterator *iter; - struct ref_store *refs = get_main_ref_store(r); - - if (!refs) - return 0; - - iter = refs_ref_iterator_begin(refs, prefix, NULL, trim, flags); - - return do_for_each_repo_ref_iterator(r, iter, fn, cb_data); -} - -struct do_for_each_ref_help { - each_ref_fn *fn; - void *cb_data; -}; - -static int do_for_each_ref_helper(struct repository *r UNUSED, - const char *refname, - const struct object_id *oid, - int flags, - void *cb_data) -{ - struct do_for_each_ref_help *hp = cb_data; - - return hp->fn(refname, oid, flags, hp->cb_data); -} - static int do_for_each_ref(struct ref_store *refs, const char *prefix, const char **exclude_patterns, each_ref_fn fn, int trim, enum do_for_each_ref_flags flags, void *cb_data) { struct ref_iterator *iter; - struct do_for_each_ref_help hp = { fn, cb_data }; if (!refs) return 0; @@ -1630,8 +1589,7 @@ static int do_for_each_ref(struct ref_store *refs, const char *prefix, iter = refs_ref_iterator_begin(refs, prefix, exclude_patterns, trim, flags); - return do_for_each_repo_ref_iterator(the_repository, iter, - do_for_each_ref_helper, &hp); + return do_for_each_ref_iterator(iter, fn, cb_data); } int refs_for_each_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) @@ -1652,12 +1610,12 @@ int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix, return do_for_each_ref(refs, prefix, exclude_patterns, fn, 0, 0, cb_data); } -int for_each_replace_ref(struct repository *r, each_repo_ref_fn fn, void *cb_data) +int refs_for_each_replace_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) { const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref; - return do_for_each_repo_ref(r, git_replace_ref_base, fn, - strlen(git_replace_ref_base), - DO_FOR_EACH_INCLUDE_BROKEN, cb_data); + return do_for_each_ref(refs, git_replace_ref_base, NULL, fn, + strlen(git_replace_ref_base), + DO_FOR_EACH_INCLUDE_BROKEN, cb_data); } int refs_for_each_namespaced_ref(struct ref_store *refs, @@ -2425,8 +2383,7 @@ struct do_for_each_reflog_help { void *cb_data; }; -static int do_for_each_reflog_helper(struct repository *r UNUSED, - const char *refname, +static int do_for_each_reflog_helper(const char *refname, const struct object_id *oid UNUSED, int flags, void *cb_data) @@ -2442,8 +2399,7 @@ int refs_for_each_reflog(struct ref_store *refs, each_reflog_fn fn, void *cb_dat iter = refs->be->reflog_iterator_begin(refs); - return do_for_each_repo_ref_iterator(the_repository, iter, - do_for_each_reflog_helper, &hp); + return do_for_each_ref_iterator(iter, do_for_each_reflog_helper, &hp); } int refs_for_each_reflog_ent_reverse(struct ref_store *refs, diff --git a/refs.h b/refs.h index 90a7e2dde3..fa1f19464e 100644 --- a/refs.h +++ b/refs.h @@ -298,16 +298,6 @@ struct ref_transaction; typedef int each_ref_fn(const char *refname, const struct object_id *oid, int flags, void *cb_data); -/* - * The same as each_ref_fn, but also with a repository argument that - * contains the repository associated with the callback. - */ -typedef int each_repo_ref_fn(struct repository *r, - const char *refname, - const struct object_id *oid, - int flags, - void *cb_data); - /* * The following functions invoke the specified callback function for * each reference indicated. If the function ever returns a nonzero @@ -329,6 +319,8 @@ int refs_for_each_branch_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data); int refs_for_each_remote_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data); +int refs_for_each_replace_ref(struct ref_store *refs, + each_ref_fn fn, void *cb_data); /* * references matching any pattern in "exclude_patterns" are omitted from the @@ -353,11 +345,6 @@ int refs_for_each_fullref_in_prefixes(struct ref_store *refs, const char **exclude_patterns, each_ref_fn fn, void *cb_data); -/** - * iterate refs from the respective area. - */ -int for_each_replace_ref(struct repository *r, each_repo_ref_fn fn, void *cb_data); - /* iterates all refs that match the specified glob pattern. */ int refs_for_each_glob_ref(struct ref_store *refs, each_ref_fn fn, const char *pattern, void *cb_data); diff --git a/refs/iterator.c b/refs/iterator.c index 9db8b056d5..d355ebf0d5 100644 --- a/refs/iterator.c +++ b/refs/iterator.c @@ -440,15 +440,15 @@ struct ref_iterator *prefix_ref_iterator_begin(struct ref_iterator *iter0, struct ref_iterator *current_ref_iter = NULL; -int do_for_each_repo_ref_iterator(struct repository *r, struct ref_iterator *iter, - each_repo_ref_fn fn, void *cb_data) +int do_for_each_ref_iterator(struct ref_iterator *iter, + each_ref_fn fn, void *cb_data) { int retval = 0, ok; struct ref_iterator *old_ref_iter = current_ref_iter; current_ref_iter = iter; while ((ok = ref_iterator_advance(iter)) == ITER_OK) { - retval = fn(r, iter->refname, iter->oid, iter->flags, cb_data); + retval = fn(iter->refname, iter->oid, iter->flags, cb_data); if (retval) { /* * If ref_iterator_abort() returns ITER_ERROR, diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 178a355eb0..07e24c8481 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -503,9 +503,8 @@ extern struct ref_iterator *current_ref_iter; * adapter between the callback style of reference iteration and the * iterator style. */ -int do_for_each_repo_ref_iterator(struct repository *r, - struct ref_iterator *iter, - each_repo_ref_fn fn, void *cb_data); +int do_for_each_ref_iterator(struct ref_iterator *iter, + each_ref_fn fn, void *cb_data); struct ref_store; diff --git a/replace-object.c b/replace-object.c index 523215589d..73f5acbcd9 100644 --- a/replace-object.c +++ b/replace-object.c @@ -8,12 +8,13 @@ #include "repository.h" #include "commit.h" -static int register_replace_ref(struct repository *r, - const char *refname, +static int register_replace_ref(const char *refname, const struct object_id *oid, int flag UNUSED, - void *cb_data UNUSED) + void *cb_data) { + struct repository *r = cb_data; + /* Get sha1 from refname */ const char *slash = strrchr(refname, '/'); const char *hash = slash ? slash + 1 : refname; @@ -50,7 +51,8 @@ void prepare_replace_object(struct repository *r) xmalloc(sizeof(*r->objects->replace_map)); oidmap_init(r->objects->replace_map, 0); - for_each_replace_ref(r, register_replace_ref, NULL); + refs_for_each_replace_ref(get_main_ref_store(r), + register_replace_ref, r); r->objects->replace_map_initialized = 1; pthread_mutex_unlock(&r->objects->replace_mutex); From patchwork Fri May 17 08:18:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13666716 Received: from wfhigh1-smtp.messagingengine.com (wfhigh1-smtp.messagingengine.com [64.147.123.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAF94288A4 for ; Fri, 17 May 2024 08:18:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933940; cv=none; b=bgYKFSDZ06bHlJmK3ajyc6m09X8/Fya65xYtdWhiC55Nma5AmlLgQN+107Q5LAiZP+wo8hBdLkOhBNaPro5DI2i71dHGqcNkf/EYE9YkQQgsyWTDbwlKxDGrFGmZYeRTibkZHNIIgxGL0m+Y0+2B8oIwNKoGjUiNFkpZsXSKoa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933940; c=relaxed/simple; bh=vIgdI9GCHAfs87nVt4MpL0cfEOwm+VRU0KKsTyIQsgM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pprAL497W1NTVAq3m++3Dgo9h7O9urgFuKdoi1iMOs/vAYRFbUco5i6lKkj44BS5BKl5YhNcYdgYdTZhDta8+bG1E0gjKOOoMVHhs5NyeLbLFqmk2JFnZhTxcnCpGqvRArEHL85jE/uKwq7o68bADuXlRoAw7esWHLJNTvlGUI4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=sWYiFa3K; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MKhuMlAk; arc=none smtp.client-ip=64.147.123.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="sWYiFa3K"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MKhuMlAk" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.west.internal (Postfix) with ESMTP id 1C9661800178; Fri, 17 May 2024 04:18:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 17 May 2024 04:18:58 -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=1715933937; x=1716020337; bh=V/2MKTzUMc WtuDJ9Es0BrDO2SiaUQCLsv2RMkAVk2Nw=; b=sWYiFa3KhpD5xZjX4sgEQ/kw4C 3Pf7RNFd4Fd/axdX0QBEL5pClXPay5xMYQ3HwgRdJG/5pxkDin9Wnm+gPUCd6tR4 2+yizTP0sY37GjaLClzMUJM0aXldFdPnYIxG9SxW2ploxYHW50ok8UbJTQ6Caasu D/gKuFgqJGh8RffCh3kDMFVVouFNkRUUEMM0D43fIlJYSy9MJultN3eHZf4oSC+V 2ZML3UGJNMcp/D6V851XVwgu+kX5gMCm+06xU3xjyuVEmj89aB3KTZF7ooJbNT1w 1mnq2ktBwuBf4jYGHCIpezCnqTK7o5fWNYy9yJswOo1x5MGaaNY0FU+otqhA== 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=1715933937; x=1716020337; bh=V/2MKTzUMcWtuDJ9Es0BrDO2SiaU QCLsv2RMkAVk2Nw=; b=MKhuMlAkheYnLueOhneTIs1dzvlKi1ydgJ7LdfwTIgWB sQvXfqm6fRC3WZ/zEQgFKTx1B8LJHxm2anEVp2RiJb3JX9fxsbLCDNs4TRVO3OMK 1UqH4wezWzqtM+3WfP4LhHKNm4ZutI5VgM5YWky8pkZM9OkoTa1YVtvfikxktMcv nfHwfQd6J9W7/w7rUEJrlzUewPb/dRIUAOeVSPOibE3UOqm2xfKxYu4Oo/4h7G5b oJc+5fumH04iAUAnZiegjsmeFzjkl/Jw4nGjBEhlXVvRIGDMmlzFY46rRE2IrKu0 7kBjLVRFwU9/7TGZDT8ht5nTboxRHx82iXMIDlR3JQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:18:56 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 677fb25c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:18:29 +0000 (UTC) Date: Fri, 17 May 2024 10:18:53 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 09/16] refs: pass ref store when detecting dangling symrefs Message-ID: <423d7b3fb65067fe381b6654e74f28da83e470bc.1715929858.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: Both `warn_dangling_symref()` and `warn_dangling_symrefs()` derive the ref store via `the_repository`. Adapt them to instead take in the ref store as a parameter. While at it, rename the functions to have a `ref_` prefix to align them with other functions that take a ref store. Signed-off-by: Patrick Steinhardt --- builtin/fetch.c | 3 ++- builtin/remote.c | 3 ++- refs.c | 40 ++++++++++++++++++++-------------------- refs.h | 7 ++++--- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 3829d66b40..3df1c0c052 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1412,7 +1412,8 @@ static int prune_refs(struct display_state *display_state, _("(none)"), ref->name, &ref->new_oid, &ref->old_oid, summary_width); - warn_dangling_symref(stderr, dangling_msg, ref->name); + refs_warn_dangling_symref(get_main_ref_store(the_repository), + stderr, dangling_msg, ref->name); } } diff --git a/builtin/remote.c b/builtin/remote.c index ff70d6835a..c0b513cc95 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1477,7 +1477,8 @@ static int prune_remote(const char *remote, int dry_run) abbrev_ref(refname, "refs/remotes/")); } - warn_dangling_symrefs(stdout, dangling_msg, &refs_to_prune); + refs_warn_dangling_symrefs(get_main_ref_store(the_repository), + stdout, dangling_msg, &refs_to_prune); string_list_clear(&refs_to_prune, 0); free_remote_ref_states(&states); diff --git a/refs.c b/refs.c index d705add3b8..48323dd28d 100644 --- a/refs.c +++ b/refs.c @@ -447,6 +447,7 @@ enum peel_status peel_object(const struct object_id *name, struct object_id *oid } struct warn_if_dangling_data { + struct ref_store *refs; FILE *fp; const char *refname; const struct string_list *refnames; @@ -463,8 +464,7 @@ static int warn_if_dangling_symref(const char *refname, if (!(flags & REF_ISSYMREF)) return 0; - resolves_to = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - refname, 0, NULL, NULL); + resolves_to = refs_resolve_ref_unsafe(d->refs, refname, 0, NULL, NULL); if (!resolves_to || (d->refname ? strcmp(resolves_to, d->refname) @@ -477,28 +477,28 @@ static int warn_if_dangling_symref(const char *refname, return 0; } -void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname) +void refs_warn_dangling_symref(struct ref_store *refs, FILE *fp, + const char *msg_fmt, const char *refname) { - struct warn_if_dangling_data data; - - data.fp = fp; - data.refname = refname; - data.refnames = NULL; - data.msg_fmt = msg_fmt; - refs_for_each_rawref(get_main_ref_store(the_repository), - warn_if_dangling_symref, &data); + struct warn_if_dangling_data data = { + .refs = refs, + .fp = fp, + .refname = refname, + .msg_fmt = msg_fmt, + }; + refs_for_each_rawref(refs, warn_if_dangling_symref, &data); } -void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_list *refnames) +void refs_warn_dangling_symrefs(struct ref_store *refs, FILE *fp, + const char *msg_fmt, const struct string_list *refnames) { - struct warn_if_dangling_data data; - - data.fp = fp; - data.refname = NULL; - data.refnames = refnames; - data.msg_fmt = msg_fmt; - refs_for_each_rawref(get_main_ref_store(the_repository), - warn_if_dangling_symref, &data); + struct warn_if_dangling_data data = { + .refs = refs, + .fp = fp, + .refnames = refnames, + .msg_fmt = msg_fmt, + }; + refs_for_each_rawref(refs, warn_if_dangling_symref, &data); } int refs_for_each_tag_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) diff --git a/refs.h b/refs.h index fa1f19464e..56d9714293 100644 --- a/refs.h +++ b/refs.h @@ -388,9 +388,10 @@ static inline const char *has_glob_specials(const char *pattern) return strpbrk(pattern, "?*["); } -void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname); -void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, - const struct string_list *refnames); +void refs_warn_dangling_symref(struct ref_store *refs, FILE *fp, + const char *msg_fmt, const char *refname); +void refs_warn_dangling_symrefs(struct ref_store *refs, FILE *fp, + const char *msg_fmt, const struct string_list *refnames); /* * Flags for controlling behaviour of pack_refs() From patchwork Fri May 17 08:18:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13666717 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C862729437 for ; Fri, 17 May 2024 08:19:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933945; cv=none; b=kJm8wji93lGXMNlYLIqcXvYiWc+YlNEX7la4LuPhF7Up4JctU5eMvxQJ98YqGlTSIFtZHvt4+Kc81avkb3XON3PL/vQNUTQ1PKWMuwsDwKNdf7v9xQIJkZB6BvdhmzRf0ShX8A09A6FSiVt7gcPQmcgkLQoM2CDatB69p8fR4Jk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933945; c=relaxed/simple; bh=UcgA1plcJi5FmBk5C1wi22taKka3Vdo8vph8ZPC3pTA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lU2xqiBv4Cczzb8HK/uoqxJQ25I7StdFwtiktBFW8o4Oj8Dr4s6spfixLW85lPUYoxul8m+b6GK4wjXuDe4NT6eEnAi2udI29NQdhLMAD+yUdMvQX45+WWwcHFDk4eNRCsfEU0wh5BuMKH9zURweL/kAS5WgTLDKo6bZluBKzkg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=ItvjLG4p; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=RVBLVuAp; arc=none smtp.client-ip=64.147.123.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="ItvjLG4p"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RVBLVuAp" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.west.internal (Postfix) with ESMTP id 111761C000BB; Fri, 17 May 2024 04:19:03 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 17 May 2024 04:19:03 -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=1715933942; x=1716020342; bh=PPJC9hhIn3 /yni5DFUMKrBXyOxnz3eFLOoR4yNmpyz8=; b=ItvjLG4pYiEnlQhGdg+80LChYl va0n+eyMa8oGFWol+ANGDaD4J0PEy48Ssmcn74aGLXl/FPPxq95//KhK9IU1IqDF YFYvVaik1O5ve4MNKPdLXCXtgv0GLMXrKFWT8Pcds0hkwm3YBDHC1xtDKGAhNU2m uF6/yNtOQkA2COB3Ht6QzZknTyNjYwS9/CLjeg8T45ZWaqOB2IewBWDRq0YnElDu BYqcxYwSDMyp8cdd97Dz8Gbst8Zoc9S1uBU/YAKkLuOScHD1VooI1DAxo/Kewe41 cz6hwrmdEFXSZjowTehjTIaTObBL7WBovgT2qVU1rXbEpGT87GOXwhr3WR+w== 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=1715933942; x=1716020342; bh=PPJC9hhIn3/yni5DFUMKrBXyOxnz 3eFLOoR4yNmpyz8=; b=RVBLVuApfi4YTFRC7IiLlWdhqW9E7OVhds9CbTHd8P0e AeBvSbRH4M+CDFF5x0xpjh9p3PeBPFqFlDWXPDA8WbdjQyTQHIu00u6TFGY/7O+E jAJDaGBc1tNkJRlLu8rqw09zzTWnGoo1f+xQ1DVZx1XiYS6aWa1kPv0YaOpN5Sqe 0tu08MhpBK738c1fzS2XkbC8BMp20Xaw84SLQLT1hI20tf4PsUnOapy3tkvyK6/6 rrl8r0tz3FDO9KkoapBO+yKgL18TV6aAk8bAUW3ylmeN9ficwUo24AGGehrOGFuW 5pAOlWSiVgzzR97SbkkyknjGd9Zjc2oFTTgyMfBXUg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:19:01 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 7ec647e0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:18:34 +0000 (UTC) Date: Fri, 17 May 2024 10:18:59 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 10/16] refs: move object peeling into "object.c" Message-ID: <3c6f814158bd9f6ab78362181614f3e2112e4a19.1715929858.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: Peeling an object has nothing to do with refs, but we still have the code in "refs.c". Move it over into "object.c", which is a more natural place to put it. Ideally, we'd also move `peel_iterated_oid()` over into "object.c". But this function is tied to the refs interfaces because it uses a global ref iterator variable to optimize peeling when the iterator already has the peeled object ID readily available. Signed-off-by: Patrick Steinhardt --- object.c | 21 +++++++++++++++++++++ object.h | 34 ++++++++++++++++++++++++++++++++++ refs.c | 22 ---------------------- refs/refs-internal.h | 34 ---------------------------------- 4 files changed, 55 insertions(+), 56 deletions(-) diff --git a/object.c b/object.c index 51e384828e..995041926a 100644 --- a/object.c +++ b/object.c @@ -207,6 +207,27 @@ struct object *lookup_object_by_type(struct repository *r, } } +enum peel_status peel_object(const struct object_id *name, struct object_id *oid) +{ + struct object *o = lookup_unknown_object(the_repository, name); + + if (o->type == OBJ_NONE) { + int type = oid_object_info(the_repository, name, NULL); + if (type < 0 || !object_as_type(o, type, 0)) + return PEEL_INVALID; + } + + if (o->type != OBJ_TAG) + return PEEL_NON_TAG; + + o = deref_tag_noverify(o); + if (!o) + return PEEL_INVALID; + + oidcpy(oid, &o->oid); + return PEEL_PEELED; +} + struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p) { struct object *obj; diff --git a/object.h b/object.h index 9293e703cc..31ccd1bb10 100644 --- a/object.h +++ b/object.h @@ -256,6 +256,40 @@ struct object *lookup_unknown_object(struct repository *r, const struct object_i struct object *lookup_object_by_type(struct repository *r, const struct object_id *oid, enum object_type type); +enum peel_status { + /* object was peeled successfully: */ + PEEL_PEELED = 0, + + /* + * object cannot be peeled because the named object (or an + * object referred to by a tag in the peel chain), does not + * exist. + */ + PEEL_INVALID = -1, + + /* object cannot be peeled because it is not a tag: */ + PEEL_NON_TAG = -2, + + /* ref_entry contains no peeled value because it is a symref: */ + PEEL_IS_SYMREF = -3, + + /* + * ref_entry cannot be peeled because it is broken (i.e., the + * symbolic reference cannot even be resolved to an object + * name): + */ + PEEL_BROKEN = -4 +}; + +/* + * Peel the named object; i.e., if the object is a tag, resolve the + * tag recursively until a non-tag is found. If successful, store the + * result to oid and return PEEL_PEELED. If the object is not a tag + * or is not valid, return PEEL_NON_TAG or PEEL_INVALID, respectively, + * and leave oid unchanged. + */ +enum peel_status peel_object(const struct object_id *name, struct object_id *oid); + struct object_list *object_list_insert(struct object *item, struct object_list **list_p); diff --git a/refs.c b/refs.c index 48323dd28d..d1b530679f 100644 --- a/refs.c +++ b/refs.c @@ -19,7 +19,6 @@ #include "object-store-ll.h" #include "object.h" #include "path.h" -#include "tag.h" #include "submodule.h" #include "worktree.h" #include "strvec.h" @@ -425,27 +424,6 @@ static int for_each_filter_refs(const char *refname, return filter->fn(refname, oid, flags, filter->cb_data); } -enum peel_status peel_object(const struct object_id *name, struct object_id *oid) -{ - struct object *o = lookup_unknown_object(the_repository, name); - - if (o->type == OBJ_NONE) { - int type = oid_object_info(the_repository, name, NULL); - if (type < 0 || !object_as_type(o, type, 0)) - return PEEL_INVALID; - } - - if (o->type != OBJ_TAG) - return PEEL_NON_TAG; - - o = deref_tag_noverify(o); - if (!o) - return PEEL_INVALID; - - oidcpy(oid, &o->oid); - return PEEL_PEELED; -} - struct warn_if_dangling_data { struct ref_store *refs; FILE *fp; diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 07e24c8481..8d85589081 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -69,40 +69,6 @@ int ref_resolves_to_object(const char *refname, const struct object_id *oid, unsigned int flags); -enum peel_status { - /* object was peeled successfully: */ - PEEL_PEELED = 0, - - /* - * object cannot be peeled because the named object (or an - * object referred to by a tag in the peel chain), does not - * exist. - */ - PEEL_INVALID = -1, - - /* object cannot be peeled because it is not a tag: */ - PEEL_NON_TAG = -2, - - /* ref_entry contains no peeled value because it is a symref: */ - PEEL_IS_SYMREF = -3, - - /* - * ref_entry cannot be peeled because it is broken (i.e., the - * symbolic reference cannot even be resolved to an object - * name): - */ - PEEL_BROKEN = -4 -}; - -/* - * Peel the named object; i.e., if the object is a tag, resolve the - * tag recursively until a non-tag is found. If successful, store the - * result to oid and return PEEL_PEELED. If the object is not a tag - * or is not valid, return PEEL_NON_TAG or PEEL_INVALID, respectively, - * and leave oid unchanged. - */ -enum peel_status peel_object(const struct object_id *name, struct object_id *oid); - /** * Information needed for a single ref update. Set new_oid to the new * value or to null_oid to delete the ref. To check the old value From patchwork Fri May 17 08:19:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13666718 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3D261AAA5 for ; Fri, 17 May 2024 08:19:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933950; cv=none; b=CnM3IOh5qAeZM+xhcuGoa4ZYyUv473XEqXk8o4U1hmJuPmKWh07OiYRBLtfbqKSnk0N4c7e4PN3AJgQO3mJy+uETGasB3/hWDu1NVppEKQ8MZEFsSOwIFHEMw/HXpXG2RIJ7v77BUDOLcye8wtYOI4HPnoynzOy5GhC4yBjqi78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933950; c=relaxed/simple; bh=2wwuHSs2rpICHQxzIZXYyAJPe2kRf1eb0tuOYtApbls=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IGLuKOGFHolbsrQebpQ3fGYPsP0cB+P49/P07H1oUoLZ6rO0KBZkFCo0pgE8PY9D/bzcJQdplpHedPjUu9+4Vd5yf8U5i7koqqg4qfSOO6Gd2qUiL2XjtcJodKP/Z+SOPAfdfXL5UI8c7+Ix22C4hOK/SV2mJq9LU4LgAagWjaY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=NQW4quFt; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=NgBDu7et; arc=none smtp.client-ip=64.147.123.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="NQW4quFt"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NgBDu7et" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 099511C00092; Fri, 17 May 2024 04:19:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 17 May 2024 04:19:08 -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=1715933947; x=1716020347; bh=Uy1XoKP+/c dhIJZMoIBhK50aUuQkiO2B1AjUidPCPlE=; b=NQW4quFt6smYdetvyw/o1z8D37 nHr86baFbmbl289A7DgP64A5iDNiOtXIAKgMQ0F//EuGNBKBMsKif28vzpf2oKVy P+ud07tFHEtBoxNu6xo1yimO0ZeQMOF9mk8FX5GRBxpBgaY7I4ev+E849QeEn09c IRkmCs3ISCcDaIsb40knquCBw29qn+7epOcLIN2RQ3QwfZ44wAFg7CGyU6HXE2qG yEMPs1WhWqI/HCNC6ENE7PciVDdZ/q/BQYWNDFdmCqKnANBlNnXk/WkGJ67Uv34B ha+EVuAioAgYKdSUfZDbtAQD33Cz3ETmBLOdUGFIhDHwjPBVtKx5Pv+WTu0w== 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=1715933947; x=1716020347; bh=Uy1XoKP+/cdhIJZMoIBhK50aUuQk iO2B1AjUidPCPlE=; b=NgBDu7etQ5/tfxzSFFYrBSgticUvOdtkGr+vUpHOYJtn Ze0B8+z1YsPpAFrrCdhX+x0VHVw/cWKi2VdguUSJeE00tOn1asrzmSDr887by78E HNHxwoEZyzzOnZ89T00/VFueMjPvJT4h4P09m8Bog6AB2zp4RAGY8SdNfVL6CiRD hDrQ/pGBuz6sSC5T/fhR1VTc8a92aOLhXEkG2GscNPBzdmsejCzcgZ5K03JIxSBE RDSEL792EJhTS6AJ1C/XZuVNCu3qyFpKbkVPrx/y62DvCku6ymN5rLzi/PKlNvJp nLCB0z7ptnqaH6WUOXOli5FtcN+eVkSqLSPBMX/m0A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepheejffdufeekjeehkeefgfeuvddtheetgfeigfevleeggfehkefhvdejfedvkedu necuffhomhgrihhnpehvrghlvddrthgrrhhgvghtnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:19:06 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 81308310 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:18:39 +0000 (UTC) Date: Fri, 17 May 2024 10:19:04 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 11/16] refs: pass repo when peeling objects Message-ID: <272cd49357b33e4df9a53fd76ee1011b840570fb.1715929858.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: Both `peel_object()` and `peel_iterated_oid()` implicitly rely on `the_repository` to look up objects. Despite the fact that we want to get rid of `the_repository`, it also leads to some restrictions in our ref iterators when trying to retrieve the peeled value for a repository other than `the_repository`. Refactor these functions such that both take a repository as argument and remove the now-unnecessary restrictions. Signed-off-by: Patrick Steinhardt --- builtin/describe.c | 2 +- builtin/gc.c | 2 +- builtin/pack-objects.c | 6 +++--- builtin/repack.c | 2 +- builtin/show-ref.c | 2 +- commit-graph.c | 2 +- ls-refs.c | 2 +- midx-write.c | 2 +- object.c | 10 ++++++---- object.h | 3 ++- ref-filter.c | 2 +- refs.c | 4 ++-- refs.h | 5 +++-- refs/packed-backend.c | 8 +++----- refs/ref-cache.c | 5 +---- refs/reftable-backend.c | 6 ++++-- t/helper/test-reach.c | 2 +- tag.c | 4 ++-- tag.h | 2 +- upload-pack.c | 2 +- 20 files changed, 37 insertions(+), 36 deletions(-) diff --git a/builtin/describe.c b/builtin/describe.c index 82aca00c80..e5287eddf2 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -200,7 +200,7 @@ static int get_name(const char *path, const struct object_id *oid, } /* Is it annotated? */ - if (!peel_iterated_oid(oid, &peeled)) { + if (!peel_iterated_oid(the_repository, oid, &peeled)) { is_annotated = !oideq(oid, &peeled); } else { oidcpy(&peeled, oid); diff --git a/builtin/gc.c b/builtin/gc.c index 054fca7835..72bac2554f 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -846,7 +846,7 @@ static int dfs_on_ref(const char *refname UNUSED, struct commit_list *stack = NULL; struct commit *commit; - if (!peel_iterated_oid(oid, &peeled)) + if (!peel_iterated_oid(the_repository, oid, &peeled)) oid = &peeled; if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT) return 0; diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index cd2396896d..62ddf41f84 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -779,7 +779,7 @@ static int mark_tagged(const char *path UNUSED, const struct object_id *oid, if (entry) entry->tagged = 1; - if (!peel_iterated_oid(oid, &peeled)) { + if (!peel_iterated_oid(the_repository, oid, &peeled)) { entry = packlist_find(&to_pack, &peeled); if (entry) entry->tagged = 1; @@ -3125,7 +3125,7 @@ static int add_ref_tag(const char *tag UNUSED, const struct object_id *oid, { struct object_id peeled; - if (!peel_iterated_oid(oid, &peeled) && obj_is_packed(&peeled)) + if (!peel_iterated_oid(the_repository, oid, &peeled) && obj_is_packed(&peeled)) add_tag_chain(oid); return 0; } @@ -4074,7 +4074,7 @@ static int mark_bitmap_preferred_tip(const char *refname, struct object_id peeled; struct object *object; - if (!peel_iterated_oid(oid, &peeled)) + if (!peel_iterated_oid(the_repository, oid, &peeled)) oid = &peeled; object = parse_object_or_die(oid, refname); diff --git a/builtin/repack.c b/builtin/repack.c index 43491a4cbf..58ad82dd97 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -673,7 +673,7 @@ static int midx_snapshot_ref_one(const char *refname UNUSED, struct midx_snapshot_ref_data *data = _data; struct object_id peeled; - if (!peel_iterated_oid(oid, &peeled)) + if (!peel_iterated_oid(the_repository, oid, &peeled)) oid = &peeled; if (oidset_insert(&data->seen, oid)) diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 151ef35134..3114bdc391 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -50,7 +50,7 @@ static void show_one(const struct show_one_options *opts, if (!opts->deref_tags) return; - if (!peel_iterated_oid(oid, &peeled)) { + if (!peel_iterated_oid(the_repository, oid, &peeled)) { hex = repo_find_unique_abbrev(the_repository, &peeled, opts->abbrev); printf("%s %s^{}\n", hex, refname); } diff --git a/commit-graph.c b/commit-graph.c index c4c156ff52..e5dd3553df 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1821,7 +1821,7 @@ static int add_ref_to_set(const char *refname UNUSED, struct object_id peeled; struct refs_cb_data *data = (struct refs_cb_data *)cb_data; - if (!peel_iterated_oid(oid, &peeled)) + if (!peel_iterated_oid(the_repository, oid, &peeled)) oid = &peeled; if (oid_object_info(the_repository, oid, NULL) == OBJ_COMMIT) oidset_insert(data->commits, oid); diff --git a/ls-refs.c b/ls-refs.c index 8e3ffff811..398afe4ce3 100644 --- a/ls-refs.c +++ b/ls-refs.c @@ -110,7 +110,7 @@ static int send_ref(const char *refname, const struct object_id *oid, if (data->peel && oid) { struct object_id peeled; - if (!peel_iterated_oid(oid, &peeled)) + if (!peel_iterated_oid(the_repository, oid, &peeled)) strbuf_addf(&data->buf, " peeled:%s", oid_to_hex(&peeled)); } diff --git a/midx-write.c b/midx-write.c index 9d096d5a28..86173abdb9 100644 --- a/midx-write.c +++ b/midx-write.c @@ -664,7 +664,7 @@ static int add_ref_to_pending(const char *refname, return 0; } - if (!peel_iterated_oid(oid, &peeled)) + if (!peel_iterated_oid(the_repository, oid, &peeled)) oid = &peeled; object = parse_object_or_die(oid, refname); diff --git a/object.c b/object.c index 995041926a..93b5d97fdb 100644 --- a/object.c +++ b/object.c @@ -207,12 +207,14 @@ struct object *lookup_object_by_type(struct repository *r, } } -enum peel_status peel_object(const struct object_id *name, struct object_id *oid) +enum peel_status peel_object(struct repository *r, + const struct object_id *name, + struct object_id *oid) { - struct object *o = lookup_unknown_object(the_repository, name); + struct object *o = lookup_unknown_object(r, name); if (o->type == OBJ_NONE) { - int type = oid_object_info(the_repository, name, NULL); + int type = oid_object_info(r, name, NULL); if (type < 0 || !object_as_type(o, type, 0)) return PEEL_INVALID; } @@ -220,7 +222,7 @@ enum peel_status peel_object(const struct object_id *name, struct object_id *oid if (o->type != OBJ_TAG) return PEEL_NON_TAG; - o = deref_tag_noverify(o); + o = deref_tag_noverify(r, o); if (!o) return PEEL_INVALID; diff --git a/object.h b/object.h index 31ccd1bb10..83fcc035e9 100644 --- a/object.h +++ b/object.h @@ -288,7 +288,8 @@ enum peel_status { * or is not valid, return PEEL_NON_TAG or PEEL_INVALID, respectively, * and leave oid unchanged. */ -enum peel_status peel_object(const struct object_id *name, struct object_id *oid); +enum peel_status peel_object(struct repository *r, + const struct object_id *name, struct object_id *oid); struct object_list *object_list_insert(struct object *item, struct object_list **list_p); diff --git a/ref-filter.c b/ref-filter.c index 31cc096644..79e7d3910d 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -2520,7 +2520,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) * If it is a tag object, see if we use the peeled value. If we do, * grab the peeled OID. */ - if (need_tagged && peel_iterated_oid(&obj->oid, &oi_deref.oid)) + if (need_tagged && peel_iterated_oid(the_repository, &obj->oid, &oi_deref.oid)) die("bad tag"); return get_object(ref, 1, &obj, &oi_deref, err); diff --git a/refs.c b/refs.c index d1b530679f..5f1819b33e 100644 --- a/refs.c +++ b/refs.c @@ -2064,14 +2064,14 @@ int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts) return refs->be->pack_refs(refs, opts); } -int peel_iterated_oid(const struct object_id *base, struct object_id *peeled) +int peel_iterated_oid(struct repository *r, const struct object_id *base, struct object_id *peeled) { if (current_ref_iter && (current_ref_iter->oid == base || oideq(current_ref_iter->oid, base))) return ref_iterator_peel(current_ref_iter, peeled); - return peel_object(base, peeled) ? -1 : 0; + return peel_object(r, base, peeled) ? -1 : 0; } int refs_create_symref(struct ref_store *refs, diff --git a/refs.h b/refs.h index 56d9714293..e043b6cfa3 100644 --- a/refs.h +++ b/refs.h @@ -127,13 +127,14 @@ void ref_store_release(struct ref_store *ref_store); * Return the peeled value of the oid currently being iterated via * for_each_ref(), etc. This is equivalent to calling: * - * peel_object(oid, &peeled); + * peel_object(r, oid, &peeled); * * with the "oid" value given to the each_ref_fn callback, except * that some ref storage may be able to answer the query without * actually loading the object in memory. */ -int peel_iterated_oid(const struct object_id *base, struct object_id *peeled); +int peel_iterated_oid(struct repository *r, + const struct object_id *base, struct object_id *peeled); /** * Resolve refname in the nested "gitlink" repository in the specified diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 9c98e6295f..dfdd718eb9 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -953,16 +953,13 @@ static int packed_ref_iterator_peel(struct ref_iterator *ref_iterator, struct packed_ref_iterator *iter = (struct packed_ref_iterator *)ref_iterator; - if (iter->repo != the_repository) - BUG("peeling for non-the_repository is not supported"); - if ((iter->base.flags & REF_KNOWS_PEELED)) { oidcpy(peeled, &iter->peeled); return is_null_oid(&iter->peeled) ? -1 : 0; } else if ((iter->base.flags & (REF_ISBROKEN | REF_ISSYMREF))) { return -1; } else { - return peel_object(&iter->oid, peeled) ? -1 : 0; + return peel_object(iter->repo, &iter->oid, peeled) ? -1 : 0; } } @@ -1421,7 +1418,8 @@ static int write_with_updates(struct packed_ref_store *refs, i++; } else { struct object_id peeled; - int peel_error = peel_object(&update->new_oid, + int peel_error = peel_object(refs->base.repo, + &update->new_oid, &peeled); if (write_packed_entry(out, update->refname, diff --git a/refs/ref-cache.c b/refs/ref-cache.c index 9f9797209a..b6c53fc8ed 100644 --- a/refs/ref-cache.c +++ b/refs/ref-cache.c @@ -441,10 +441,7 @@ static int cache_ref_iterator_peel(struct ref_iterator *ref_iterator, { struct cache_ref_iterator *iter = (struct cache_ref_iterator *)ref_iterator; - - if (iter->repo != the_repository) - BUG("peeling for non-the_repository is not supported"); - return peel_object(ref_iterator->oid, peeled) ? -1 : 0; + return peel_object(iter->repo, ref_iterator->oid, peeled) ? -1 : 0; } static int cache_ref_iterator_abort(struct ref_iterator *ref_iterator) diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 7b73f73f59..850466da4b 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -1144,7 +1144,7 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data ref.refname = (char *)u->refname; ref.update_index = ts; - peel_error = peel_object(&u->new_oid, &peeled); + peel_error = peel_object(arg->refs->base.repo, &u->new_oid, &peeled); if (!peel_error) { ref.value_type = REFTABLE_REF_VAL2; memcpy(ref.value.val2.target_value, peeled.hash, GIT_MAX_RAWSZ); @@ -2045,6 +2045,7 @@ static int reftable_be_delete_reflog(struct ref_store *ref_store, } struct reflog_expiry_arg { + struct reftable_ref_store *refs; struct reftable_stack *stack; struct reftable_log_record *records; struct object_id update_oid; @@ -2073,7 +2074,7 @@ static int write_reflog_expiry_table(struct reftable_writer *writer, void *cb_da ref.refname = (char *)arg->refname; ref.update_index = ts; - if (!peel_object(&arg->update_oid, &peeled)) { + if (!peel_object(arg->refs->base.repo, &arg->update_oid, &peeled)) { ref.value_type = REFTABLE_REF_VAL2; memcpy(ref.value.val2.target_value, peeled.hash, GIT_MAX_RAWSZ); memcpy(ref.value.val2.value, arg->update_oid.hash, GIT_MAX_RAWSZ); @@ -2235,6 +2236,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store, reftable_ref_record_val1(&ref_record)) oidread(&arg.update_oid, last_hash); + arg.refs = refs; arg.records = rewritten; arg.len = logs_nr; arg.stack = stack, diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c index 1e3b431e3e..1ba226f1f9 100644 --- a/t/helper/test-reach.c +++ b/t/helper/test-reach.c @@ -62,7 +62,7 @@ int cmd__reach(int ac, const char **av) die("failed to resolve %s", buf.buf + 2); orig = parse_object(r, &oid); - peeled = deref_tag_noverify(orig); + peeled = deref_tag_noverify(the_repository, orig); if (!peeled) die("failed to load commit for input %s resulting in oid %s\n", diff --git a/tag.c b/tag.c index fc3834db46..52bbe50819 100644 --- a/tag.c +++ b/tag.c @@ -91,10 +91,10 @@ struct object *deref_tag(struct repository *r, struct object *o, const char *war return o; } -struct object *deref_tag_noverify(struct object *o) +struct object *deref_tag_noverify(struct repository *r, struct object *o) { while (o && o->type == OBJ_TAG) { - o = parse_object(the_repository, &o->oid); + o = parse_object(r, &o->oid); if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged) o = ((struct tag *)o)->tagged; else diff --git a/tag.h b/tag.h index 3ce8e72192..c49d7c19ad 100644 --- a/tag.h +++ b/tag.h @@ -16,7 +16,7 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u int parse_tag(struct tag *item); void release_tag_memory(struct tag *t); struct object *deref_tag(struct repository *r, struct object *, const char *, int); -struct object *deref_tag_noverify(struct object *); +struct object *deref_tag_noverify(struct repository *r, struct object *); int gpg_verify_tag(const struct object_id *oid, const char *name_to_report, unsigned flags); struct object_id *get_tagged_oid(struct tag *tag); diff --git a/upload-pack.c b/upload-pack.c index 8fbd138515..bbfb04c8bd 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -1269,7 +1269,7 @@ static void write_v0_ref(struct upload_pack_data *data, packet_fwrite_fmt(stdout, "%s %s\n", oid_to_hex(oid), refname_nons); } capabilities = NULL; - if (!peel_iterated_oid(oid, &peeled)) + if (!peel_iterated_oid(the_repository, oid, &peeled)) packet_fwrite_fmt(stdout, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons); return; } From patchwork Fri May 17 08:19:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13666719 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC3292C68C for ; Fri, 17 May 2024 08:19:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933955; cv=none; b=PvlrFf9ctwaijDKnk1rFxaQa5L9x7ZzzC6PpW24XZ3GzbYW5ukB55hi0k5geTw7DJNk/vEfvu/PfQf35vqydc+q5ql1mMEZIcAmT4lJqUBJU2s1+zs9Aem76xERlC6hsRaMEFfy2IXTwOH/Q4vTn244n/UG39CQDiutwsHp3m8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933955; c=relaxed/simple; bh=wFM988INED51iI5iNFjo8rXZeguyl1hQwIv8tJs0Jlo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MMa+UrrY+6doLmLGc9aiT8J+rhynPgTWWWhNLSPuhdMzw1duM3hXtIqO9Po0onXOj+THiRbtC+incTIdYF+EACrTV2zhn1veCrx4dSnmDQbtkcadRTb1oMwYVjZrHHydoymFmAWGcy73QMT483r5OjgwiYZFxnMc0sgMIR9YDh0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=V2d1L6A6; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PKiwossO; arc=none smtp.client-ip=64.147.123.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="V2d1L6A6"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PKiwossO" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.west.internal (Postfix) with ESMTP id 0F55E1C000BB; Fri, 17 May 2024 04:19:12 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Fri, 17 May 2024 04:19:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715933952; x=1716020352; bh=Q2rVk68H1T 7Z5cSIgXmfcHgNue9v4ZRkKZ1N3nSjx8M=; b=V2d1L6A6FQk3pVS3BxnITR5FmM eu6VPtYjMtlr2XaKIxS3IrmMfhGWuJfDrh/poINufMCbtPDEp0giszGJsq2uDci4 M3KmKVb48ds3nXxM6UptqdTM8B8h1QyF5eRs1EFPnOSUD88n9TuN7G5BrrsW04MH P0ENRc+lbi7DFw+KiEi/OACp3nHnUEI2Ao9xeeQqykNG2Oeux9l/PK3sAoZl1L8t BYQtUastWS0QGNgh79HZpWI8Vu76VdO7JcDvfDp8uDNL9+5lTWJh01HVnBkRU32R oU5dlGIpz4+9Altp72FnOL2p28QtPB40Si5J9FzhNZgOpTbYmO53yv9/vZ3Q== 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=1715933952; x=1716020352; bh=Q2rVk68H1T7Z5cSIgXmfcHgNue9v 4ZRkKZ1N3nSjx8M=; b=PKiwossOGrU21NQssNezsniRwjP0970yUs4BiG8VrW9f KUEf+Irt4I8QoUYisO31/+YkI7DJ9/SNzZxGCoVzpBfpfWQv56ligGpto2BJ2eDk LkBvaYu9MDqnRQy+X0M8RloibFEz9V5xXv8DLy2vgH8Yws+HmpecapuEx7O9o0Ux 69NgpQpY1mBGXWNUfdHN66u9pw8yBcFRbt7pvs4qqgRg+cC3RlK2X2GhjEVr5iqc eU2d6YpL5ov+mY48xMk4xu4iZDNvlNSYvDG5AklbXehTG2vpb8WcigIAKxEh3BP1 S8bdSxmD7oXwcpHXrAYoyEMh8EQZ3mbAmaURlGeRAA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:19:11 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 3f2af3f0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:18:44 +0000 (UTC) Date: Fri, 17 May 2024 10:19:09 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 12/16] refs: drop `git_default_branch_name()` Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `git_default_branch_name()` function is a thin wrapper around `repo_default_branch_name()` with two differences: - We implicitly rely on `the_repository`. - We cache the default branch name. None of the callsites of `git_default_branch_name()` are hot code paths though, so the caching of the branch name is not really required. Refactor the callsites to use `repo_default_branch_name()` instead and drop `git_default_branch_name()`, thus getting rid of one more case where we rely on `the_repository`. Signed-off-by: Patrick Steinhardt --- builtin/clone.c | 5 ++++- builtin/var.c | 2 +- refs.c | 10 ---------- refs.h | 4 +--- remote.c | 12 ++++++++---- setup.c | 5 ++++- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index 554b29768c..bd3e8302ed 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -1468,6 +1468,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) } else if (remote_head) { our_head_points_at = NULL; } else { + char *to_free = NULL; const char *branch; if (!mapped_refs) { @@ -1480,7 +1481,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) "refs/heads/", &branch)) { unborn_head = xstrdup(transport_ls_refs_options.unborn_head_target); } else { - branch = git_default_branch_name(0); + branch = to_free = repo_default_branch_name(the_repository, 0); unborn_head = xstrfmt("refs/heads/%s", branch); } @@ -1496,6 +1497,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix) * a match. */ our_head_points_at = find_remote_branch(mapped_refs, branch); + + free(to_free); } write_refspec_config(src_ref_prefix, our_head_points_at, diff --git a/builtin/var.c b/builtin/var.c index cf5567208a..5dc384810c 100644 --- a/builtin/var.c +++ b/builtin/var.c @@ -46,7 +46,7 @@ static char *pager(int ident_flag UNUSED) static char *default_branch(int ident_flag UNUSED) { - return xstrdup_or_null(git_default_branch_name(1)); + return repo_default_branch_name(the_repository, 1); } static char *shell_path(int ident_flag UNUSED) diff --git a/refs.c b/refs.c index 5f1819b33e..83cd965a26 100644 --- a/refs.c +++ b/refs.c @@ -664,16 +664,6 @@ char *repo_default_branch_name(struct repository *r, int quiet) return ret; } -const char *git_default_branch_name(int quiet) -{ - static char *ret; - - if (!ret) - ret = repo_default_branch_name(the_repository, quiet); - - return ret; -} - /* * *string and *len will only be substituted, and *string returned (for * later free()ing) if the string passed in is a magic short-hand form diff --git a/refs.h b/refs.h index e043b6cfa3..e906dbb44a 100644 --- a/refs.h +++ b/refs.h @@ -169,10 +169,8 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **ref); /* * Retrieves the default branch name for newly-initialized repositories. * - * The return value of `repo_default_branch_name()` is an allocated string. The - * return value of `git_default_branch_name()` is a singleton. + * The return value is an allocated string. */ -const char *git_default_branch_name(int quiet); char *repo_default_branch_name(struct repository *r, int quiet); /* diff --git a/remote.c b/remote.c index ec8c158e60..85c390b199 100644 --- a/remote.c +++ b/remote.c @@ -305,7 +305,7 @@ static void read_remotes_file(struct remote_state *remote_state, static void read_branches_file(struct remote_state *remote_state, struct remote *remote) { - char *frag; + char *frag, *to_free = NULL; struct strbuf buf = STRBUF_INIT; FILE *f = fopen_or_warn(git_path("branches/%s", remote->name), "r"); @@ -333,7 +333,7 @@ static void read_branches_file(struct remote_state *remote_state, if (frag) *(frag++) = '\0'; else - frag = (char *)git_default_branch_name(0); + frag = to_free = repo_default_branch_name(the_repository, 0); add_url_alias(remote_state, remote, strbuf_detach(&buf, NULL)); refspec_appendf(&remote->fetch, "refs/heads/%s:refs/heads/%s", @@ -345,6 +345,8 @@ static void read_branches_file(struct remote_state *remote_state, */ refspec_appendf(&remote->push, "HEAD:refs/heads/%s", frag); remote->fetch_tags = 1; /* always auto-follow */ + + free(to_free); } static int handle_config(const char *key, const char *value, @@ -2388,11 +2390,13 @@ struct ref *guess_remote_head(const struct ref *head, /* If a remote branch exists with the default branch name, let's use it. */ if (!all) { - char *ref = xstrfmt("refs/heads/%s", - git_default_branch_name(0)); + char *default_branch = repo_default_branch_name(the_repository, 0); + char *ref = xstrfmt("refs/heads/%s", default_branch); r = find_ref_by_name(refs, ref); free(ref); + free(default_branch); + if (r && oideq(&r->old_oid, &head->old_oid)) return copy_ref(r); diff --git a/setup.c b/setup.c index fec6bfd5fa..481b57d523 100644 --- a/setup.c +++ b/setup.c @@ -2046,6 +2046,7 @@ void create_reference_database(unsigned int ref_storage_format, const char *initial_branch, int quiet) { struct strbuf err = STRBUF_INIT; + char *to_free = NULL; int reinit = is_reinit(); repo_set_ref_storage_format(the_repository, ref_storage_format); @@ -2060,7 +2061,8 @@ void create_reference_database(unsigned int ref_storage_format, char *ref; if (!initial_branch) - initial_branch = git_default_branch_name(quiet); + initial_branch = to_free = + repo_default_branch_name(the_repository, quiet); ref = xstrfmt("refs/heads/%s", initial_branch); if (check_refname_format(ref, 0) < 0) @@ -2077,6 +2079,7 @@ void create_reference_database(unsigned int ref_storage_format, initial_branch); strbuf_release(&err); + free(to_free); } static int create_default_files(const char *template_path, From patchwork Fri May 17 08:19: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: 13666720 Received: from wfhigh1-smtp.messagingengine.com (wfhigh1-smtp.messagingengine.com [64.147.123.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C25442CCD0 for ; Fri, 17 May 2024 08:19:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933960; cv=none; b=GHDSXKh43HlA7NA4Expv6pNQA0492Qhx2N9w2c+ea0jx/0En8RBFYOmWW8wRbCuRraYnQT9CQoDL6YCe+kfyPG61JK8oHW4XIFXx7274stairHCtb1imu64i5oJyTuG0XHu6SrruscHHgC5B4GmT2yRoNx9cb8NuEQNFMiqMFfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933960; c=relaxed/simple; bh=QW+MN7/lI/Qz9BnK3HFMp8mH7MtrgiPNjvjqkK4wASE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UY7LbpOH6aes9MngOjyGZtZZyzNeUl9n+1GJ1pdwnnzBoiyOux/3jNym6uiFfXpkUtwct/1k8midZFpr6HuWeROuRPwokvVOxDtUY/E4ZnfaBXf7SXswkJwwwEjMHpvg1ITb0E2Sw4RewH4Rmlvb2FMya2yTHHrJwxj8EdSTxmU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=hq0WsgSB; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ZyO45hvR; arc=none smtp.client-ip=64.147.123.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="hq0WsgSB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZyO45hvR" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id EE87B1800179; Fri, 17 May 2024 04:19:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 17 May 2024 04:19:18 -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=1715933957; x=1716020357; bh=0g/qpNRPOV 0A2HwwYHRA4haGO8oOblx0WRcfXjN1s50=; b=hq0WsgSBRELO7V3HvN8WiIl60o ILMLv5YiiQ9+oApCsA8h/Oj46R0PhVm/hhPDjDYTF8kd1zasdX8COvzLjRnqtBb1 MnCfcTfvogiw93ylimh1AuCS/J0DaBhuF9AMiBoLNBpmDIm2+OpELBkcI9p38tJw kDEw6k/KWcfMqVn/PqHNiMsLE/+8DACdvwHzcxkpBzTJ3OD/Sr+YhQnfw5vFs4bH zRDsoXkTGsSx6SL5Xyg8DSPJSoWeCO0z6HGaCoeKcEzV/fswgzWOnwOOPzmvZUD7 2JitK7UXMGQrETsBBADBtxwSFKYyivDosx+PVnyW9JWuxhbtzyaRiaG8oJMA== 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=1715933957; x=1716020357; bh=0g/qpNRPOV0A2HwwYHRA4haGO8oO blx0WRcfXjN1s50=; b=ZyO45hvRaz8sUFKJxDCUl1zd2jfkjpA5CmV8lMQ/i9tm zRP1xuJsDUhI/IvMH4JkZR6Dr/IX4NHLm5IQEYo6NISfm8XJKwJgKB0k6gEO7xst DRB9E2f1AkOHjsbZekE/kP/b1idYZDYEfcSQjM0upCbcukyUlN9BnU3Hr3au0wIh 8xHV9Cxw2hyoaCa+w1Uh6prllNURRRrDZ4D8LO9X0nXwAOw2dH8hpghd2StngX+D c6RwJLhNjaHEoVvwHw7ocW32K52z4PlfxZ5RcDcFJ/407js03RBlxDfK5nJ1EE57 WjxPIolE+/FG3q8FrMW8FW2XBp0G55Yr33OGvGf6oQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:19:16 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 06c21804 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:18:49 +0000 (UTC) Date: Fri, 17 May 2024 10:19:14 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 13/16] refs: remove `dwim_log()` 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: Remove `dwim_log()` in favor of `repo_dwim_log()` so that we can get rid of one more dependency on `the_repository`. Signed-off-by: Patrick Steinhardt --- builtin/reflog.c | 2 +- reflog-walk.c | 4 ++-- reflog.c | 2 +- refs.c | 5 ----- refs.h | 1 - 5 files changed, 4 insertions(+), 10 deletions(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index b4650cea16..0d2ff95c6e 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -378,7 +378,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) char *ref; struct expire_reflog_policy_cb cb = { .cmd = cmd }; - if (!dwim_log(argv[i], strlen(argv[i]), NULL, &ref)) { + if (!repo_dwim_log(the_repository, argv[i], strlen(argv[i]), NULL, &ref)) { status |= error(_("%s points nowhere!"), argv[i]); continue; } diff --git a/reflog-walk.c b/reflog-walk.c index f11b97e889..5f09552c5c 100644 --- a/reflog-walk.c +++ b/reflog-walk.c @@ -191,8 +191,8 @@ int add_reflog_for_walk(struct reflog_walk_info *info, reflogs = read_complete_reflog(branch); if (!reflogs || reflogs->nr == 0) { char *b; - int ret = dwim_log(branch, strlen(branch), - NULL, &b); + int ret = repo_dwim_log(the_repository, branch, strlen(branch), + NULL, &b); if (ret > 1) free(b); else if (ret == 1) { diff --git a/reflog.c b/reflog.c index 8861c2d606..3c80950186 100644 --- a/reflog.c +++ b/reflog.c @@ -409,7 +409,7 @@ int reflog_delete(const char *rev, enum expire_reflog_flags flags, int verbose) if (!spec) return error(_("not a reflog: %s"), rev); - if (!dwim_log(rev, spec - rev, NULL, &ref)) { + if (!repo_dwim_log(the_repository, rev, spec - rev, NULL, &ref)) { status |= error(_("no reflog for '%s'"), rev); goto cleanup; } diff --git a/refs.c b/refs.c index 83cd965a26..43c5fef734 100644 --- a/refs.c +++ b/refs.c @@ -775,11 +775,6 @@ int repo_dwim_log(struct repository *r, const char *str, int len, return logs_found; } -int dwim_log(const char *str, int len, struct object_id *oid, char **log) -{ - return repo_dwim_log(the_repository, str, len, oid, log); -} - int is_per_worktree_ref(const char *refname) { return starts_with(refname, "refs/worktree/") || diff --git a/refs.h b/refs.h index e906dbb44a..82022d300c 100644 --- a/refs.h +++ b/refs.h @@ -164,7 +164,6 @@ int expand_ref(struct repository *r, const char *str, int len, struct object_id int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref, int nonfatal_dangling_mark); int repo_dwim_log(struct repository *r, const char *str, int len, struct object_id *oid, char **ref); -int dwim_log(const char *str, int len, struct object_id *oid, char **ref); /* * Retrieves the default branch name for newly-initialized repositories. From patchwork Fri May 17 08:19: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: 13666721 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6C992E62C for ; Fri, 17 May 2024 08:19:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933965; cv=none; b=SOvp6gzhk7A0BvxhKTfQeDG7nT78Kj7w6abUhgR1683Yrnp7rOexaaKPd5EdQMhuvSCU7Mcf8kMM2Sga1Z9XLQHRIxMdl5ULPX3TXyfPQ8xnPHx8HsQUSRzDf+6x9bF3ViVMm4WYBErBQnjyw6aonIuM9bIKh7sPJbhKLNX81UQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933965; c=relaxed/simple; bh=K2c/6rNIPhFfnR6j/MfIUUtxHQMCT8vRRzDPuAHq5ac=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HyazQHOmCp8SabRo287Wo60C7aB8afLuGEhLaqTTfuHKwhR5Vh765vrN7hRjzmmyM1kH69cj7phZSYk+4GKrh+jVJU+CLduKgH+sate7auh6qnYBPkLuzCkDr8v37UKQ3qFYPNkvUlFI04FJQnOR+F3QjhfKIHZRcEtWExMbPnM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=ESs7jXDE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KnrLzxIP; arc=none smtp.client-ip=64.147.123.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="ESs7jXDE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KnrLzxIP" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id DD75F1C000CD; Fri, 17 May 2024 04:19:22 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 17 May 2024 04:19: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=1715933962; x=1716020362; bh=3x9HGTG7Ko li/1M7B6L3Es+kgO/eSGGRhNhLT3yWrys=; b=ESs7jXDEKa7qZfF6aOy4APTBrF eYk+MSDNzIQhATXwkfIS/XUaVGr9u8cLo6wBFNuW5HlsjEaxk/ztU3FhQMTMhBv6 6Nj87+pB0KmaurmD5QwR7JYqL0M13zhiULk3MCtamxxTa9jdPRC0h49zd0Aza60u 62+Hdo3/ZE0TTSo9gmBifucC2vGkifNfJeCJZ7EMd2FAv6rwMaTw6GJTrBHaCNFX 22Iymddw7QNfu3hYCIc9bS6TFwrw4+ZgTSAg73Cvi1+21tg4nlacVVJ1QjrQmKGb 2iEPO7YdnQGywbF4XgHT5KrT8q1ewfAPaNt2//pQchAtSuAz7MDRbXvtfS+A== 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=1715933962; x=1716020362; bh=3x9HGTG7Koli/1M7B6L3Es+kgO/e SGGRhNhLT3yWrys=; b=KnrLzxIPrZfdN1a5cEwGVzI4fbyKnNASd2R+kHn0P7fn hDtUVGtrItBvzDqPLOv/NixYkbuDHQ1YwLLkJ9CG0sF7bZXjUxnSOGZg1zj9ulOE ELnn7CVM+YLx4SllXm32e50AXQnwlTwtWFwSLS2zQ/TlWyv5ggceO1kzzuZSUh7I +eSeqw/7fSsLTDUHeiXAOxvTW8XF4ZoG0ANfQ97cDQPuLzDd7ug8cg08+adNVaxR WUmrEDQ8nRE7Rfp2BUWUe8pSbQwGuFzgqnhrBgcnJtYiglI9mPOXT1H33qoY/z4q /X8NXhyEHGBXY84QbeSCco4MzZFdKBll+B2vhSB1Ew== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:19:21 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 1a58a555 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:18:54 +0000 (UTC) Date: Fri, 17 May 2024 10:19:19 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 14/16] refs/files: use correct 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: There are several places in the "files" backend where we use `the_repository` instead of the repository associated with the ref store itself. Adapt those to use the correct repository. Signed-off-by: Patrick Steinhardt --- refs/files-backend.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 62acd2721d..235c8580d1 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1237,7 +1237,8 @@ static void prune_refs(struct files_ref_store *refs, struct ref_to_prune **refs_ /* * Return true if the specified reference should be packed. */ -static int should_pack_ref(const char *refname, +static int should_pack_ref(struct files_ref_store *refs, + const char *refname, const struct object_id *oid, unsigned int ref_flags, struct pack_refs_opts *opts) { @@ -1253,7 +1254,7 @@ static int should_pack_ref(const char *refname, return 0; /* Do not pack broken refs: */ - if (!ref_resolves_to_object(refname, the_repository, oid, ref_flags)) + if (!ref_resolves_to_object(refname, refs->base.repo, oid, ref_flags)) return 0; if (ref_excluded(opts->exclusions, refname)) @@ -1285,14 +1286,14 @@ static int files_pack_refs(struct ref_store *ref_store, packed_refs_lock(refs->packed_ref_store, LOCK_DIE_ON_ERROR, &err); iter = cache_ref_iterator_begin(get_loose_ref_cache(refs, 0), NULL, - the_repository, 0); + refs->base.repo, 0); while ((ok = ref_iterator_advance(iter)) == ITER_OK) { /* * If the loose reference can be packed, add an entry * in the packed ref cache. If the reference should be * pruned, also add it to refs_to_prune. */ - if (!should_pack_ref(iter->refname, iter->oid, iter->flags, opts)) + if (!should_pack_ref(refs, iter->refname, iter->oid, iter->flags, opts)) continue; /* @@ -1389,7 +1390,8 @@ static int rename_tmp_log(struct files_ref_store *refs, const char *newrefname) return ret; } -static int write_ref_to_lockfile(struct ref_lock *lock, +static int write_ref_to_lockfile(struct files_ref_store *refs, + struct ref_lock *lock, const struct object_id *oid, int skip_oid_verification, struct strbuf *err); static int commit_ref_update(struct files_ref_store *refs, @@ -1537,7 +1539,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store, } oidcpy(&lock->old_oid, &orig_oid); - if (write_ref_to_lockfile(lock, &orig_oid, 0, &err) || + if (write_ref_to_lockfile(refs, lock, &orig_oid, 0, &err) || commit_ref_update(refs, lock, &orig_oid, logmsg, &err)) { error("unable to write current sha1 into %s: %s", newrefname, err.buf); strbuf_release(&err); @@ -1557,7 +1559,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store, flag = log_all_ref_updates; log_all_ref_updates = LOG_REFS_NONE; - if (write_ref_to_lockfile(lock, &orig_oid, 0, &err) || + if (write_ref_to_lockfile(refs, lock, &orig_oid, 0, &err) || commit_ref_update(refs, lock, &orig_oid, NULL, &err)) { error("unable to write current sha1 into %s: %s", oldrefname, err.buf); strbuf_release(&err); @@ -1791,7 +1793,8 @@ static int files_log_ref_write(struct files_ref_store *refs, * Write oid into the open lockfile, then close the lockfile. On * errors, rollback the lockfile, fill in *err and return -1. */ -static int write_ref_to_lockfile(struct ref_lock *lock, +static int write_ref_to_lockfile(struct files_ref_store *refs, + struct ref_lock *lock, const struct object_id *oid, int skip_oid_verification, struct strbuf *err) { @@ -1800,7 +1803,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock, int fd; if (!skip_oid_verification) { - o = parse_object(the_repository, oid); + o = parse_object(refs->base.repo, oid); if (!o) { strbuf_addf( err, @@ -2571,7 +2574,7 @@ static int lock_ref_for_update(struct files_ref_store *refs, * value, so we don't need to write it. */ } else if (write_ref_to_lockfile( - lock, &update->new_oid, + refs, lock, &update->new_oid, update->flags & REF_SKIP_OID_VERIFICATION, err)) { char *write_err = strbuf_detach(err, NULL); From patchwork Fri May 17 08:19:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13666722 Received: from wfhigh1-smtp.messagingengine.com (wfhigh1-smtp.messagingengine.com [64.147.123.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AABDA2F853 for ; Fri, 17 May 2024 08:19:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933971; cv=none; b=cZxrQqS/sb0EH5/T8pHBDjMgcNzdrUDrmRfiPzB8kCZbnHLxCI9Ake3VrZaNoTC9eOqHGEyJb+YCpymsQmGJfFCBS17HR+DydA4Z/F6khwFFEUFKaoHRQ+yVwkEiA1xKX4vyjMeOvzu5vGdPhvs9RLGWmMK9LU1rQB1QAYRCxpw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933971; c=relaxed/simple; bh=L5URsni2ZQTUt4m6WFC0tWzkh43nIZjczGFw6lrQrjo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=B+LMxP1ibwB/W4gq+9tB5DWHz9MdzP41f1Jo9cPb8VCojMmqmQLBwX61ABNkis10FHN0YMJrwd2dhS42c+C63tFWM3OmTXMmqrSSS3n7y5Kwkl7xDf1waUQP5iUt0KvtfyOnDbuG0QWkPj8lE3dYq03j77LkZtZMKqPc2QIw5j4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=Y4pVzWdO; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=I0XJiEBf; arc=none smtp.client-ip=64.147.123.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="Y4pVzWdO"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="I0XJiEBf" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.west.internal (Postfix) with ESMTP id D351E180017A; Fri, 17 May 2024 04:19:28 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 17 May 2024 04:19:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715933968; x=1716020368; bh=IAdzOo6+r3 RZV2GnAlQ+hlyw7zawHgTgPk/F/+8jiQY=; b=Y4pVzWdO16452I9Az9ba3OcuYB cFc2N0Mil+PykhbI2fc1duPkAZPBnEJaOiYn9E3IBHOLmIBs312Y46Oa5ub6o7fx 8tHuYPiY+HHKbXauues8KkAFdmPSJEdOqFsoWKKkx0uahdMV886j+KfmVmO5tyd0 9uticuL5ow1PuiJT4WlrzJl0B/V//G5o3whNbGumhcUEafLeEh0mnvJUAjPEMwib c18iLpcI0ihK3O8zUPXo8WLhXJJpU4efwHbZfpQm6W3FcTZSf/DUqRtBKl4PSYkM RpKMOSyik5NEcW9guHX5OYbHCwXdr5qweL6TPrUWyNub6qS0O96v2z9RKlQQ== 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=1715933968; x=1716020368; bh=IAdzOo6+r3RZV2GnAlQ+hlyw7zaw HgTgPk/F/+8jiQY=; b=I0XJiEBfjipK+WbPiVhdsRO20jgiurwC3BEKSLglA6hy GxaIwikOjh64y9NFjeN9LOXAvUyTOR3tVc7OWbNqbuDIT5uKDmONtWlg9KAXjYkA 3J6FPk/WqN1+hILRlMbtLwttvGTydtcU7d0mX3I8+mIrixL4rtEQm7EobxIYK3dn CpvG85okURoJugzAKPf3HyDVyXtFPHCXvF4QdVv0VGP9bCOu9OWiu2ul6SFON+8y 9ALfJU7TeQf7qxZlItvGp9LedA7T1VDkLzv7S4k9KaD4HpiTbZ07TFVJGq77VVBP 6gGNnakzzBi0ZrfS0nrKQ5BQNWs+lIH6JErSW/Gmmw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:19:27 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 1546f4ec (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:19:00 +0000 (UTC) Date: Fri, 17 May 2024 10:19:24 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 15/16] refs/files: remove references to `the_hash_algo` Message-ID: <20c2bb4cbbb8eb1604c9a6a650b36cb05cd1dbf0.1715929858.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: Remove references to `the_hash_algo` in favor of the hash algo specified by the repository associated with the files ref store. Signed-off-by: Patrick Steinhardt --- refs/files-backend.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 235c8580d1..735a5acefe 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1822,7 +1822,7 @@ static int write_ref_to_lockfile(struct files_ref_store *refs, } } fd = get_lock_file_fd(&lock->lk); - if (write_in_full(fd, oid_to_hex(oid), the_hash_algo->hexsz) < 0 || + if (write_in_full(fd, oid_to_hex(oid), refs->base.repo->hash_algo->hexsz) < 0 || write_in_full(fd, &term, 1) < 0 || fsync_component(FSYNC_COMPONENT_REFERENCE, get_lock_file_fd(&lock->lk)) < 0 || close_ref_gently(lock) < 0) { @@ -3223,7 +3223,7 @@ static int files_reflog_expire(struct ref_store *ref_store, rollback_lock_file(&reflog_lock); } else if (update && (write_in_full(get_lock_file_fd(&lock->lk), - oid_to_hex(&cb.last_kept_oid), the_hash_algo->hexsz) < 0 || + oid_to_hex(&cb.last_kept_oid), refs->base.repo->hash_algo->hexsz) < 0 || write_str_in_full(get_lock_file_fd(&lock->lk), "\n") < 0 || close_ref_gently(lock) < 0)) { status |= error("couldn't write %s", From patchwork Fri May 17 08:19:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13666723 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D1C8364AA for ; Fri, 17 May 2024 08:19:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933976; cv=none; b=YunBY2fRnVUZh5IIClwREFY4zyUWN6E684sC96ebJTbGMdhlPgSvTokBC1gL9vvBDI/CLti7dY7yF9Y+opSeqCL5VEsSPOo55nqQIHrsSUf9jNxhFqBuQpSze0nD9LeCvCIU7akc8PLKmKGsbEmUNyBXIPsGdR3RV8VpCY8OEx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715933976; c=relaxed/simple; bh=sQgH96BBEWRMw0xcKtr7NM99pSQCrObsbRf7lJDuqiE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=C5lGN76MfS/6Clly8vPZd49rDp6JrkUKgO23j12VximydzHt7i6nixr28lakHHenUvbcwRy0BmoONB9Ds2wpc6Gyz//W04NnH/zlrVxUZyqoCEac++bJzInEAE7oX2kHNh2X+9qbkX8OITb7IQAPzqdGjZyW0mPXOxHK+1ANXxw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject 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=ZXlnqdR7; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ICp7i/Mv; arc=none smtp.client-ip=64.147.123.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="ZXlnqdR7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ICp7i/Mv" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id BD0751C00131; Fri, 17 May 2024 04:19:33 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 17 May 2024 04:19:34 -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=1715933973; x=1716020373; bh=EEfZmMakaP p4LmtmSpKTotHeZpRiDtp7DU+YAikU82Q=; b=ZXlnqdR7K7kuvOIQ6o1WfdhoiD d/6u2g9GdQqRh6nQrVfL7/qq9IKaNZb6cmwx+xOlm7rN2xcu1dUbsUL8+VyrRJTS R/4ti1mLLtz6CPWGuJswc2GyzWxW0MMXpOX0Dl1FTSKKtLfTsZAnCAzQOdDvuWT1 uyjq3t7CLXSOSkhszrCSdRbJGZgE6bvPY9f5CzW4PBRs7ZbPFOaZG0ZEFaMAQ5+o +3eLzX7k2BYVgPCCW4Oc8Ivxm3Y3Uipe396OwAieEAlmLXSOcoTUtOqMrEJQkZ2a 4U+f3hwU2q177PFMyZYq5pLORO3Zrb65qDRn8Hf41nIdnGYBCjypbNu///yA== 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=1715933973; x=1716020373; bh=EEfZmMakaPp4LmtmSpKTotHeZpRi Dtp7DU+YAikU82Q=; b=ICp7i/MvEcq6zFx2Z4y5UynUYJiAvlD/8NG5GnuQTiXF qOdzR7yi/UreQcOdq8CEL2WO6tDJMEUAhTq3m/uh3BRhhWHL4QsQNKQK7YidvivU uIDy1SuWWo4W0VfWwLYRfOKr9ojCRWDSFTuL/NUBnrBUa3ZeRvVZ1LmKdATD8cLi A7LXIcgHeqJtFWsEmXdd2X+iR0KSmDO0OfV+V/QW4Y27hkB1RvL1NptFff82VjZi Gx9A8zBn6PV5hfuIIopgRGuMPsikaOouzbsLLX1V1HshBuzvahh77j04hKi5LMBa TQ3iZRqCXWz9sUUfHCxG1ZWb3iyZfugLgwyQ6kWkOg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehfedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 May 2024 04:19:32 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id d60cc6bd (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 17 May 2024 08:19:05 +0000 (UTC) Date: Fri, 17 May 2024 10:19:29 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano Subject: [PATCH v2 16/16] refs/packed: remove references to `the_hash_algo` Message-ID: <5ebe81d8c3410f88e5f6be6383fc301a48fb9eed.1715929858.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: Remove references to `the_hash_algo` in favor of the hash algo specified by the repository associated with the packed ref store. Signed-off-by: Patrick Steinhardt --- refs/packed-backend.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/refs/packed-backend.c b/refs/packed-backend.c index dfdd718eb9..78e26bcf41 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -200,6 +200,11 @@ static int release_snapshot(struct snapshot *snapshot) } } +static size_t snapshot_hexsz(const struct snapshot *snapshot) +{ + return snapshot->refs->base.repo->hash_algo->hexsz; +} + struct ref_store *packed_ref_store_init(struct repository *repo, const char *gitdir, unsigned int store_flags) @@ -289,11 +294,13 @@ struct snapshot_record { size_t len; }; -static int cmp_packed_ref_records(const void *v1, const void *v2) +static int cmp_packed_ref_records(const void *v1, const void *v2, + void *cb_data) { + const struct snapshot *snapshot = cb_data; const struct snapshot_record *e1 = v1, *e2 = v2; - const char *r1 = e1->start + the_hash_algo->hexsz + 1; - const char *r2 = e2->start + the_hash_algo->hexsz + 1; + const char *r1 = e1->start + snapshot_hexsz(snapshot) + 1; + const char *r2 = e2->start + snapshot_hexsz(snapshot) + 1; while (1) { if (*r1 == '\n') @@ -314,9 +321,9 @@ static int cmp_packed_ref_records(const void *v1, const void *v2) * refname. */ static int cmp_record_to_refname(const char *rec, const char *refname, - int start) + int start, const struct snapshot *snapshot) { - const char *r1 = rec + the_hash_algo->hexsz + 1; + const char *r1 = rec + snapshot_hexsz(snapshot) + 1; const char *r2 = refname; while (1) { @@ -363,7 +370,7 @@ static void sort_snapshot(struct snapshot *snapshot) if (!eol) /* The safety check should prevent this. */ BUG("unterminated line found in packed-refs"); - if (eol - pos < the_hash_algo->hexsz + 2) + if (eol - pos < snapshot_hexsz(snapshot) + 2) die_invalid_line(snapshot->refs->path, pos, eof - pos); eol++; @@ -389,7 +396,7 @@ static void sort_snapshot(struct snapshot *snapshot) if (sorted && nr > 1 && cmp_packed_ref_records(&records[nr - 2], - &records[nr - 1]) >= 0) + &records[nr - 1], snapshot) >= 0) sorted = 0; pos = eol; @@ -399,7 +406,7 @@ static void sort_snapshot(struct snapshot *snapshot) goto cleanup; /* We need to sort the memory. First we sort the records array: */ - QSORT(records, nr, cmp_packed_ref_records); + QSORT_S(records, nr, cmp_packed_ref_records, snapshot); /* * Allocate a new chunk of memory, and copy the old memory to @@ -475,7 +482,8 @@ static void verify_buffer_safe(struct snapshot *snapshot) return; last_line = find_start_of_record(start, eof - 1); - if (*(eof - 1) != '\n' || eof - last_line < the_hash_algo->hexsz + 2) + if (*(eof - 1) != '\n' || + eof - last_line < snapshot_hexsz(snapshot) + 2) die_invalid_line(snapshot->refs->path, last_line, eof - last_line); } @@ -570,7 +578,7 @@ static const char *find_reference_location_1(struct snapshot *snapshot, mid = lo + (hi - lo) / 2; rec = find_start_of_record(lo, mid); - cmp = cmp_record_to_refname(rec, refname, start); + cmp = cmp_record_to_refname(rec, refname, start, snapshot); if (cmp < 0) { lo = find_end_of_record(mid, hi); } else if (cmp > 0) { @@ -867,7 +875,7 @@ static int next_record(struct packed_ref_iterator *iter) iter->base.flags = REF_ISPACKED; p = iter->pos; - if (iter->eof - p < the_hash_algo->hexsz + 2 || + if (iter->eof - p < snapshot_hexsz(iter->snapshot) + 2 || parse_oid_hex(p, &iter->oid, &p) || !isspace(*p++)) die_invalid_line(iter->snapshot->refs->path, @@ -897,7 +905,7 @@ static int next_record(struct packed_ref_iterator *iter) if (iter->pos < iter->eof && *iter->pos == '^') { p = iter->pos + 1; - if (iter->eof - p < the_hash_algo->hexsz + 1 || + if (iter->eof - p < snapshot_hexsz(iter->snapshot) + 1 || parse_oid_hex(p, &iter->peeled, &p) || *p++ != '\n') die_invalid_line(iter->snapshot->refs->path,