From patchwork Thu May 16 08:04:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13665804 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 484B380BE3 for ; Thu, 16 May 2024 08:04:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846667; cv=none; b=OHZvdD2xjHnMnUD/nDR0dqw6m0p04U0xoFYQfiE9Wc97HTb9KWgLX+hMT/a++be2EDSalSPrCg7B3bspxrs9a5d6+kD9LWvElK7hZ18zUXOtcuFymCz0ekZL6yskJjlT8tOQcLva+yLyb7UcZHnAcSl619/e3NML9iW5MaE+gPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846667; c=relaxed/simple; bh=orKg9vqr5WgZQGUWAyqAPIJuT35xbSidB8TxcIefYxU=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mSa/IPMwBTIS5oPLH18THU8ShxjxeKdqvPmKx/dM+OYxOqgrUbRV5Zt5E0HGG/7snW6sjlMNZVYKxaFf72lfohZTEd80gUQ1JEJefa+c7TpEiO3CYZzneTIPoPG3Rluq8aUAYnhVL+g8VABoFNYAstuJc7EKyrA07JhBo9KLaqg= 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=i8n6KBw+; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=B4zfqmIz; arc=none smtp.client-ip=103.168.172.147 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="i8n6KBw+"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="B4zfqmIz" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 577B41380E54 for ; Thu, 16 May 2024 04:04:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 16 May 2024 04:04:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846664; x=1715933064; bh=tl16NLF/8J W6tXuBuqRq++KihhiGh68iNUgfO94ECIA=; b=i8n6KBw+5w+lHuazfaNwkxAH6k PN6gV3V+kt2Tq1d4pJLlF+X7Q126eNjjQsQ+xwO4HEi2gWdadrOeUTtZAxfRRpnG bW6pctB1D2ZxLc0PvQ6RO4A5nGIpNOoKJauW4wpDMLCWcVO0qrcl85cW6mw+O516 dQ6rHht7QMNTVgGjz/vIS97/atJ18DK7Dp1cyLfhJl7AgqNesMJpcQUG4UMc+kX4 UPHaWdJhPNvJEBtognSOnqnkg7+DyoEzHOvFYPf5ylV4Mlfmc5hDMYSUfN7YhRKb o7FNCrvG1VOoJ/MIzFihmT6gIGdRdlt52RxuYs13CYGk4ouJikKYu3O+IXZA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846664; x=1715933064; bh=tl16NLF/8JW6tXuBuqRq++KihhiG h68iNUgfO94ECIA=; b=B4zfqmIzBSlyJi8/5TNBVsAWcVi+6Wi/3QPgP0yg6vd6 bvaPDllsJAhG6ihEsCTtHf9ceHO1bu1dkTnkvNTEXHLJZ3eQtsBOR1k8duQ/3jxR Suv6i2KzpG1WcJFHjlS8XRpNIwGDtFneGVN/u28SDd2ptPsxPyFwgB69f7mquWIh 4fkv7cpKoazinC/hoRxR1RDm9ggSEl+YshNbZdbiI54KtOECGNcC/SL+S2ofn6xD o9IpKkZV8CZN8PGhGY6C5IhE7fJ1xX8RtUoXHPpMF0n7DznCK1q6//w+Vp98t3LY 9NoBru+GKcQ/FgLJxRhJTWGWdjRnt20nh/7Z5uiBqQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:04:23 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 31e2a06c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:03:51 +0000 (UTC) Date: Thu, 16 May 2024 10:04:13 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 01/16] refs: adjust names for `init` and `init_db` callbacks Message-ID: <360d03474635e36a80a3b720bf0f86ac272c618e.1715836916.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 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 Thu May 16 08:04:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13665805 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 49EBB80C03 for ; Thu, 16 May 2024 08:04:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846668; cv=none; b=HRDjZizYPkukbEcOkd10yDbbUBNd3MAii2Jl2aDqiWlkSLiy3GClJ40qCf12KbINEpVRHSgJtGN2bL3Spow/V15AZePLP9v8DO1+riVEZET0jBfsZ8Z1fhEYg+niH/Aln9nLxRyw9VfoUmgMjER+GMp3zj5GPOISvia0Uluo9no= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846668; c=relaxed/simple; bh=GWv+nOXvyUyF95YszbTV6myFSEN2RYFkJKJJF6f1i2M=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fVepCoto5raEIkipVd/EUi4G7se4IJNmU+ZLRvvSzwwFQJlA73VKb1s1b6C1xr7LIytZBBqWq2gjz/eMDkLWTj+jrpJMBBDKj0a7a2TG+3dxKr3WsiZwyL222qIxcFjidOxm8sO+8P0cN5UJmn45oMe51yExJIEAx+Tyt5Vws6M= 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=GwB7wsNN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bl8VFuDv; arc=none smtp.client-ip=103.168.172.153 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="GwB7wsNN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bl8VFuDv" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 4803611400C2 for ; Thu, 16 May 2024 04:04:25 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Thu, 16 May 2024 04:04:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846665; x=1715933065; bh=juApgQzabH 5CnpaEIyPEWZ8HYzy2a/hU3BgL7o9TsrM=; b=GwB7wsNNmfaq0G/0yT+6eX+s07 fQbxc8DtT8eeoErUtnLrHoaPv8B3dqeszxvMdT3KLhNUeeHMckzwmj87XxMByDW5 fV27kN+g4CZdP9aEoD8Z98YLFk0QGndtE39W7GDewNz1releSgwmB9atDYjDXzHa jrD+a2Jo0joDDj/qdCmVy+VV7k/I/CJ41Ihxa4/x26U1RzX6geGwSIoGfPqhAnzV 1RiHNUzzUU1sAdr4qs1BjqUTAA6NdC0sl+sWzA2HQb6d8kNT1sVoUFMER2vVbETG PcHAbpZyx60ErVMUJZiF8wc+phzqwpo4ZngzZhcgP8mokAGT0h2Wki72wJDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846665; x=1715933065; bh=juApgQzabH5CnpaEIyPEWZ8HYzy2 a/hU3BgL7o9TsrM=; b=bl8VFuDvxwNsWnyi5GslpGQAOm0SxOJ4G+UR31ts8Equ ktcTvynH7s6nDmGJOH4nhqxlp98jHcygDtbgENQHL2KbAU0Y4crDjbwrxNK7ZaH0 ztT4zk655w9BXHC8GwZfHQJJIyksXOeZqE1JnoyE8ziEwiToi8v/TIQyiafUxf3Z ODTF9J0IxEvs1kRG5jGI7oPaEffwHbIYi6WG6/pu7GwIvEeddXcM0m8kDV3eVzKU Fx7Yg/2SwUZkRC8svrtChXWDOmXj4E5eR1BtWvIqdEhVINZPehtH8mN/yvsHwSCo eYoOFBH+F8Yo5LGNzyvUbONToeRuWHzQBmv1CLRUdg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:04:24 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 8e795fa7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:03:56 +0000 (UTC) Date: Thu, 16 May 2024 10:04:18 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 02/16] refs: rename `init_db` callback to avoid confusion Message-ID: <3cc2b4e5501ebe1464a6d75b7aea9f2ad6030c4a.1715836916.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 tripped myself whenever I was looking at those, where I always had to look up which of them does what. Rename the `init_db` callback to `create`, 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..cce083d409 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(wt_refs, REF_STORE_CREATE_IS_WORKTREE, &sb); if (ret) goto done; diff --git a/refs.c b/refs.c index a26c50a401..ad7987efab 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(struct ref_store *refs, int flags, struct strbuf *err) { - return refs->be->init_db(refs, flags, err); + return refs->be->create(refs, flags, err); } int resolve_gitlink_ref(const char *submodule, const char *refname, diff --git a/refs.h b/refs.h index d02dd79ca6..e9804e4c22 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_IS_WORKTREE (1 << 0) -int refs_init_db(struct ref_store *refs, int flags, struct strbuf *err); +int ref_store_create(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..58fb4557ed 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(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(drefs->refs, flags, err); + trace_printf_key(&trace_refs, "create: %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 = debug_create, /* * 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..f766d18d5a 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(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_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 = files_ref_store_create, .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..716513efed 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(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 = packed_ref_store_create, .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..eb42212764 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_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_fn *create; 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..a4bb71cd76 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(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 = reftable_be_create, .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..4a738f4c90 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(get_main_ref_store(the_repository), 0, &err)) die("failed to set up refs db: %s", err.buf); /* From patchwork Thu May 16 08:04:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13665806 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 1ADEF137C22 for ; Thu, 16 May 2024 08:04:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846669; cv=none; b=hjY/wfkJtw55xwAK4bA2PGrbD2yX5bfafJtwFs4eSro/0tWilE8sixN34NdeB02BHgkjxDLMmhkbdsi5EF76PSX+3gDzWl0LB2S6/aRbCvxRnnUHh4uBBjo0uYTi6EGaIyExaFzNS+RgteaZYGog9iaUcbLbRNtYvHAXYindOTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846669; c=relaxed/simple; bh=TqqSIqXyF/Y9JAq9HHjC2U5yKIL3QXqzt5Ea8YAaVkU=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=l7syrjPbjiBGYbq9pP86+LqWSjaJ+wGXX7MW82+hv35XncWwlJpbO+k24tVEXHddh2ERKKAcgTu1yKEhxlYcDoyMJMAWfkwyAF5GOGk8D6STfhp1NpHrln1xmnmGhxzfmoYSWuAic65slkyDYTXppSt8R5S88jDD3MBJHYbTX10= 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=BtlSferJ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=O5Kp2LYY; arc=none smtp.client-ip=103.168.172.153 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="BtlSferJ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="O5Kp2LYY" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3C50411400C3 for ; Thu, 16 May 2024 04:04:27 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 16 May 2024 04:04:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846667; x=1715933067; bh=dAl/1qfoYT z9UBAhXaSj+QsGNh2/ov575pC+22gcKC8=; b=BtlSferJ5mtVUqPfb9evJUTPGE K1wDlYqAHAbAoZAEFmqg7s+FL3NcJBvAw4Aeo2AMoyhVvbPRfAI6pX4Z1F9LMIEt 4CRHplTwDe5MCfZ9IoHXlCNNKllZLcOievRYyW36H7PamnPxNViG05N83TqBBzMv 0HRFUUK/G/SC27vd7FsZ3tNPXxHtDbMk6rmVArEicDNTr0q3d+PeV5D1xIV0atUm N1t6GvA4c9avEGeXwOVVA5O7fJ9ZFeW7aUgakwYGYiWsnzBHZp+no3CvNKxDMkhx +0ol74ugRIn7EzUEYF67HSXO4UPnOqOLIWbXlf17k+OifvFySMPUv71sadbw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846667; x=1715933067; bh=dAl/1qfoYTz9UBAhXaSj+QsGNh2/ ov575pC+22gcKC8=; b=O5Kp2LYYmuhMl7I6xT2HXOPNacXYqkvBVUh5kEVW3Ltq u6eEiCV8LaYAiIDemTDVKbzmBQyRuMX8oKU80kALEVJNcu0cCHAYtN1ZtRZY1C+L 243SnTLquNv6JImEoZFs9OQFuffvgN+YlkoodTnA5fbqJmzRsPBZLyGFY/PwNGgA o64WzExzNUGfLRmmbh09Ua7eu+L8kbnUBV6xN6Uwck4DuLYeNuaG3WQByihtD60w j7C4C/nTDBrg/fDnP94dkbsFdedcLNKrOp3PSnlyKYA78QFmMDuuDs1QKQ4ZUibu H5xl2CxHK29tNShOCa0g9MulhInAkPE27lzfFcPNpw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:04:26 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 5faf3c65 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:04:01 +0000 (UTC) Date: Thu, 16 May 2024 10:04:23 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 03/16] refs: implement releasing ref storages Message-ID: <282fbe35a7c9db715a8a805f93f9b465d42885a5.1715836916.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 | 7 +++++++ refs/files-backend.c | 9 +++++++++ refs/packed-backend.c | 10 ++++++++++ refs/refs-internal.h | 6 ++++++ refs/reftable-backend.c | 22 ++++++++++++++++++++++ 7 files changed, 65 insertions(+) diff --git a/refs.c b/refs.c index ad7987efab..edb0a633d1 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 e9804e4c22..5ecdfb16dc 100644 --- a/refs.h +++ b/refs.h @@ -118,6 +118,11 @@ int is_branch(const char *refname); int ref_store_create(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 58fb4557ed..27aae42134 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -33,6 +33,12 @@ 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); +} + static int debug_create(struct ref_store *refs, int flags, struct strbuf *err) { struct debug_ref_store *drefs = (struct debug_ref_store *)refs; @@ -427,6 +433,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 = debug_create, /* diff --git a/refs/files-backend.c b/refs/files-backend.c index f766d18d5a..368df075c1 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,6 +3292,7 @@ static int files_ref_store_create(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 = files_ref_store_create, .transaction_prepare = files_transaction_prepare, .transaction_finish = files_transaction_finish, diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 716513efed..bebceb4aa7 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,6 +1716,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, + .release = packed_ref_store_release, .create = packed_ref_store_create, .transaction_prepare = packed_transaction_prepare, .transaction_finish = packed_transaction_finish, diff --git a/refs/refs-internal.h b/refs/refs-internal.h index eb42212764..cc1fe6e633 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -530,6 +530,11 @@ 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_fn(struct ref_store *refs, int flags, struct strbuf *err); @@ -668,6 +673,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_fn *create; ref_transaction_prepare_fn *transaction_prepare; diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index a4bb71cd76..6c262c2193 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->main_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(struct ref_store *ref_store, int flags UNUSED, struct strbuf *err UNUSED) @@ -2248,6 +2269,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, + .release = reftable_be_release, .create = reftable_be_create, .transaction_prepare = reftable_be_transaction_prepare, .transaction_finish = reftable_be_transaction_finish, From patchwork Thu May 16 08:04: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: 13665807 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 1341A12E1C0 for ; Thu, 16 May 2024 08:04:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846673; cv=none; b=Ozg+NAZldxvA2F8janLNuMriF/FHtDyI4zl6K0r93vFsOq8ByRpL1dQcHffYV5Nn826YBp8jYIwqxBKdPiTzIIexE33BAJpPbgctgnyUTykAsKqyJ/zMkfW+IBYcViwGQe7a03308VUV0E6Vi5pRoVckudcSUZEL2A+C7ys/0VU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846673; c=relaxed/simple; bh=504rxHNROh8V5UdLGZhkWwkZwo2HoWtsKBSEmqKGLZU=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HvwGYYFwzvr0iuTJ9mhzdHBc1nkpu3tXDVS9xt73toubjUWvDghsXXr1ilp2u1/2MW33EeOYetYsuyH80JUg7onJ5nHpVARW64U+Lme5ohKISsg3BHowSwYfjfF82PdJo2wmOReLdy6EfcD0ImzMJPoI8iXRo1M3H+HfJnfc6mQ= 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=OeBQVgKG; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FQmKGJ9Z; arc=none smtp.client-ip=103.168.172.147 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="OeBQVgKG"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FQmKGJ9Z" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 32A77138039C for ; Thu, 16 May 2024 04:04:31 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 16 May 2024 04:04:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846671; x=1715933071; bh=UChDxkO81j yTHSnpHwBlFocQtje6/LiE2Ch1C5pFFUk=; b=OeBQVgKG1xv9OutSizOT3xT/6l EFExEjuromxWQjvsFU/5xq+ahTcZiyzQW41z4QCJcbwN0YLVqpaR9FJrEmYP8PdB mGPDyGEIOSdKmDZsAwuE/xtDFxZAOsMFX+/F9O06Lf8KZaH8J+rMFGfH+rzUjL+v M9dgrKinWQ5oA/8SyiNDveKLIBQdgUUtBBR3AHEJM0U/ScBaQJF/ZmPomtPwBUks TxZfF6az9lhwyf1BiV3dkYvrZAxMDNcx9GghNrREJHJEkXlceYpyb+FXZMqeuJlh PWTVWfd9+hV1gmimChed+P7muwEXD3QrBK01509efi7ygnpPedWrW3/JyFRw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846671; x=1715933071; bh=UChDxkO81jyTHSnpHwBlFocQtje6 /LiE2Ch1C5pFFUk=; b=FQmKGJ9Z8AY0vRNbD1mYULbEDoA9bJP4GYZLr6qMd0VM T6zMTE+vKAoOwKmW1+kJ3wz8MbUUs8detVGKdDW9rlksoSl/v88y99lbDwjGInqL BqEyBRB7I1WH9Dn0BMiO4mCZsGGLivGF2Va+YSdGuAEIcX32AbCF/KzBitYi0NdA c+6V496ETnrCNEqWEfewsREkG8bKnb4sPIyW2EvY9pKpwZE0Uqtm9etW6B4yCgD/ 2kKkHvVqjJ+5JgfErYlv90VOjfjQ+X37hx0au3RMLTtktrDqznByL2xMMDbjc6LX MKoEWEKqaYQoHcLXXeM+A1xaTeG0MQg5gDT1tFjNYA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:04:30 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id c549adba (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:04:06 +0000 (UTC) Date: Thu, 16 May 2024 10:04:28 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 04/16] refs: track ref stores via strmap Message-ID: <52798936a290ffa64b244f9bbd1c5f17d1b24db3.1715836916.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 edb0a633d1..542acb25ff 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 Thu May 16 08:04:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13665808 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 EDDC012E1C0 for ; Thu, 16 May 2024 08:04:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846678; cv=none; b=FhlLObdmIn9wAFmeqr5euzMkTTvotiw9G7N4DvwGz5PONQ288SPy4XRDye31qvAuNk7s1LAuYPCqggXcwbhABnWxggOdd53P2JsIJugn+GcIRD+Rl8zA8Raaq9rKeeUyPVQsG5WD6WhKowYyiLY1xxbG768GB0zPp4Is2tCMDu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846678; c=relaxed/simple; bh=DmKzALg+xAvZPK6Jlu02OUQsqfCa9FW8dDp0qQTRRQg=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=P87b4G/p6tacZcwHlAsdjmvn/u2jOTyhik1uKQOzag1RP1HXmFgwzmELc5pudah5WHBLUO6D/bg9KowH9xWBSetJizw4+qx5lkOAh0XOEseF8PlAb3U+NOmEsZ+w3Yyc3Ryiyuecy9qiaPCLSSAOctjxont1yoaKtHoZweZwi8k= 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=F+99qccj; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QNR+J4iS; arc=none smtp.client-ip=103.168.172.147 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="F+99qccj"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QNR+J4iS" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 2E6391380E32 for ; Thu, 16 May 2024 04:04:36 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 16 May 2024 04:04:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846676; x=1715933076; bh=QCipGYi0nV ixXlMW9UEz6Rbo3Slnuhx6CiMW1POtWZo=; b=F+99qccjp6pwUzyQ2sUZXqMsg8 vSCaO8TxTqjAXGoDmjBIMu4t3aMGQbTAnp9Vydcy2U7HfbWaShzY4qkKzHCJ75Rs mqIGMBFjAnqw8MU+adqOlSr16VwPc3U0GlIk5ZYYr7EBqx7FzO0cmZlCd58BAXVV 2iIBrUqhsaVRen4Nea/TQwIyaq7uWxC442sn08k/BeAvZwekSXOnjdxfgu7bt7Ts Fm2Taoia/Wvxen83BjDoR0+jAac+QVN2bi5GWwTZ5kL6gI4/OeJycIhBkvEe8rL4 g2tawmuAHG2xsSISStkl33mw7LJKfzTIjguHubW6lt/zxDOu3ThyLU0icf1Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846676; x=1715933076; bh=QCipGYi0nVixXlMW9UEz6Rbo3Sln uhx6CiMW1POtWZo=; b=QNR+J4iSdvoR1qBTjUwFRwOdEXgp/HAwRdKBwbJtXsoF xYHNGxNygi16brLDVj7ASQDEvAFThKjkTeMNsWRGBhWm0+GC+weBDWD/dYpv1PHA ftMVQ6FAHQEyPNht66kLEJPFbEVlrN36u6cibnAH00piUUQh8MT5TyxejQHZ1mI+ HUD5ffPSb5cMFAleV73GjukasR9b5sXkIxYtV+RJBqjMsDCGqhM53WcuAPo0rX9e eJ72T8XI/6ybAMyvl94x4YibQwemQ4LyPKZe36+tx7hUrykB6mapyWjN/sDcwK5U mLbT2Jo7enghv4rZqyYjAeiDgi9qOEtG8MQgjymuWg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepudenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:04:35 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 00ae21b8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:04:10 +0000 (UTC) Date: Thu, 16 May 2024 10:04:33 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 05/16] refs: pass repo when retrieving submodule ref store Message-ID: <1d48289809d5bff3d168b42b2b7f150e3ee953e2.1715836916.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: 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. 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 542acb25ff..86008ce7b4 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 5ecdfb16dc..fc1a873e8a 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 cc1fe6e633..3c3f9a3555 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -706,7 +706,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 Thu May 16 08:04:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13665809 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 05F25130A7C for ; Thu, 16 May 2024 08:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846683; cv=none; b=Ki9/R34djJxn8WF4Nrhh1QJGLVu+nzjInQw7T97BgVo4VBWIRIoFu0fYsdp03oXuyPnLsE/eG9XwsmaBMQ9iHJw3nye5CniWsmwhE6TxC2xugf+UaAxlMyzt3GP5wqidASXsw1edLkSbORKw56qKxjIiyXDtyf5hTXQWfLVLd3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846683; c=relaxed/simple; bh=RiQvg4NR+6SrLvtPDxVDRxF5jXser0Fxmwf70TteTlo=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Oh/HvSMECDthZ2G74T08/Avuvh/NtaAgyM8y/Z8XsV6NHanPACVkpJZC/iIymtXUjxKsNQTTecSxQ35IhWPdtpThmaBePqCVzXW+n6xcdH4sNYriZak2YLZFzpoiSdnxPSVEjVAizebjSRcGthMpzB2AsX7AwNXk/Xe6ZQmRwJg= 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=EOCe3Fyh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Q59K3WcN; arc=none smtp.client-ip=103.168.172.147 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="EOCe3Fyh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Q59K3WcN" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 2943A1380282 for ; Thu, 16 May 2024 04:04:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 16 May 2024 04:04:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846681; x=1715933081; bh=9N2ivfh72J hXuQm/au9koCqc1hN3aSykZcndVoB2vQ8=; b=EOCe3FyhgPHixXoyPtW854yXev naDayW1JYu2pE0F2qmLgRv4jErJ8SEtyQRy0KcaxGGiK8OE5RJx23xMs9D6bgyAx gVpTKqhql86fPuS6gLxklP+ZM9LHZLLgQBXWo42cfGQAJW+dD4yfMl9g+rDq3qY0 s9A7h78ehuQsCQctQkYuaaCLbzecD1/T6gPR1bSYt3gpVDZmUiinEIT3SqQSoHJG JGYbxAuxSoiBKTys5yrxtIfoJ1GrsyYhDh4ytRZvSCLu5Qfr8AkxthB+8ct4S+ck OJf3bm68VlxQMvTQ2PrHMr002a9gXjPopSKQfKhWjKf5/NW0EeSyYxzy0Xog== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846681; x=1715933081; bh=9N2ivfh72JhXuQm/au9koCqc1hN3 aSykZcndVoB2vQ8=; b=Q59K3WcNA8+aOR3MkEfjck6e8sDGJ9MEv0I1HyrYPaWl EiCWpRhsdJJgwng+aFh2xy5z9pNpAfrUOJ/X7HLIvT6IIIY8S5AMy3Gk1fnjP0tZ USgT7ac4Z3siANAjoxVsDieF1TxQEL3o5LIjEbslfaCFqdQQSgE2I43+JGkNvgQK Qjb2GuqHyc0zUKs32Pn2v6cWv7iEpj5vraK4mVfHdg9E0h2FyHAg6JPv6VhgN0EX t4CFNczVx+VgjmawhB3JGT5K2zIUW369CJBy7CtvRo9XyVyhneX8TysEgX0L09YW Vm+Za1IMH6h4LjfjyVSqYjbCQ9KWTQ0XRjRCGLp06w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepudenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:04:40 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 69e04e85 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:04:15 +0000 (UTC) Date: Thu, 16 May 2024 10:04:38 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 06/16] refs: refactor `resolve_gitlink_ref()` to accept a repository Message-ID: <7b4ea1ffd255245ff7b4f00a7d77599dad61f80b.1715836916.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: 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 86008ce7b4..40e241216e 100644 --- a/refs.c +++ b/refs.c @@ -1943,13 +1943,14 @@ int ref_store_create(struct ref_store *refs, int flags, struct strbuf *err) return refs->be->create(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 fc1a873e8a..5a2b493507 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 Thu May 16 08:04:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13665810 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 0DCB04120A for ; Thu, 16 May 2024 08:04:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846688; cv=none; b=Xn5yN+RM0Ev5LMgqirqYjTtaegGP3A8Y+sNc/RTbNDmg6Rh2sFCiYPXxoermiUPXlo4LOOUjhbyXl582OXQUscPb0kVhaQjJ3lm9dLPCgXfVAvMV1tVndV++F0594ZEYoEVGwE4FdNhoSEmNO22i3Xq87NBEGE/+XZaWs6yvl/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846688; c=relaxed/simple; bh=epyjz92EAI/ahcGjHrQ84R0qQia5zZQ2G9z4iXLLsyM=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iUWKT7ec9RoTqy3hmz+F4TIIf61fO8eozTtDtrFzCLf4zl+rOWOkHbM75NQjAcD+3orfX3L1NJumff6twIRK4hNdpWkRX3oJkHPHCRrRZrx/erhS3eQwIfQEv2wmdm2gO9q1/kmSMSEBEai+2U2OtdtuBVicCOtxoOwLMVN1BeY= 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=P6R3U65j; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XPPmTR4s; arc=none smtp.client-ip=103.168.172.147 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="P6R3U65j"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XPPmTR4s" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 1F2BF1380282 for ; Thu, 16 May 2024 04:04:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 16 May 2024 04:04:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846686; x=1715933086; bh=NLAe59edwt AOnW2lmFNFEWPU3g+vYB+mgdu3sG0MIyI=; b=P6R3U65jGWyWkbh5JvwP+T1b65 fKbzzDF9JZDfBOy8trJgXeld/jIy9lIPURw9WKjvuwuoaCgKnaopg+ryGM/l39sZ 7Ksl3upcv9/5BKrW+6+bM0ejS1TCV6gEcHqFXpMIdJoqYsUDTC1QD2j5yUlD76er UuFZP2Izol6iidQzxeE2tbDdZOVII74fnOXHSy1M0k+J7EyzgbZB0hbysdFtYPIw mXBZQQWeMQ19buBIKS5wnKXrDv5NcaZlEClbvQe2bhSTGo49qIwt27ROoIoNKQRW rGr7sKQh6dj6lvfHEd4Hf/+yRpSl8dPaQmLt3oKc/M7iZ63+fjHL6dgJjYEw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846686; x=1715933086; bh=NLAe59edwtAOnW2lmFNFEWPU3g+v YB+mgdu3sG0MIyI=; b=XPPmTR4stgXBt2kqF6om76bms4HvdRegq0mNnl3DKoZM IR0C1//4b/aUQuWBKICF8eMsFH3VO/IDU7mjJGengBSxWrNFdzS+rKDUdm8W0BhE hbuquyBkUXQyhKeOrY5OgPKPaSp7qnFuiNHB9BQwZ80BnuEabuqYcCQXGwcQ/M4Q iu4bjiSL0b3ZPoMgXh9qSav58+B6lhNcflLAN59Q1569D4MxzpisATEjLllf4Pjl ge8124lUVUiKYIsFlZOrHpTKwQTy+KDTvBWK9WG7Ga9kt7Sz/P/IZJQW+wf/Hh6m tVascJ9GA1BI7/I+vejIousGoUNbUrS8OLTlE7SjOA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepvdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:04:45 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id dd335ec2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:04:20 +0000 (UTC) Date: Thu, 16 May 2024 10:04:42 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 07/16] refs: retrieve worktree ref stores via associated repository Message-ID: <4d55dbbceb2162aab1ee83f5efe752f6a721bc8f.1715836916.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 40e241216e..03bf5d0e69 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 Thu May 16 08:04:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13665811 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 DFF34134404 for ; Thu, 16 May 2024 08:04:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846693; cv=none; b=HZfxUq3nshf13t7BefmpP2HZXZH5POfLnkw6UyjYg8hK5kR6XtHHyAu1Ee8Y6Y4bZv8LIjeLXgwg/pZr2upTLhHPgv7CqTUbx54n6NP6zcNWyFj1pfL3gI+O8gBmY8HbFdDFU31DngHsQBjXzHwMuoZ8t717jxO+PjvJOzFerHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846693; c=relaxed/simple; bh=2VsIhrbv5RIlC8mwbqnmdNsmUyeJpPYli18bVJzGWR0=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Tm3g9IpIEfvBq68rCwk5S1+TAyEb/1GXJ4nAxmSoJUH3jl0CoplZhaAdo7lkBAWDb7im2+ue3FFq6gdck8JX5EiFTkos3z8NHj4pXpmDGvmhgMrYvQShrVQxPEo9YuA8IvgDIhZjZFpKRRYx3Cs7OEAeWPZAKhYBoSuOfEFwOw8= 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=olyz5Q4K; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fW1oe5Mg; arc=none smtp.client-ip=103.168.172.147 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="olyz5Q4K"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fW1oe5Mg" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 0C86F1380282 for ; Thu, 16 May 2024 04:04:51 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 16 May 2024 04:04:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846691; x=1715933091; bh=ieijI9OHGb iVAeodlTBlD7C1wksib4B9ge48d94o3qE=; b=olyz5Q4Kqz/E40OG0Oa9lOZ+eN pC2es3LjDGtKXfa6eYXEw5yIAIiH7HbFMX8de87KQnCsnv57+4KqXl8oAYrJ4rjn uHmMQlPREl4UNectNwqkjb9uushcaEErhZsZf0NCgKSueVOHvkSBnl8MGGw1qcsY Q5eJwM6AqSxbIDhPvvFVS3AOU1gnpRuVk7HyTlSkFAvQHQo2SQbUnH8HJ5Slb2XW w+9QlnvqDg/paI9N8MrikikwXHKdKcvCcwCnqstIvIAQdn/8YPo1yQU7PiGYEbQI pghO+z2rVjbn3cNbck0rq1Nak5C3ySDGDjhpEqOKedkM0/Nms8wrPgjoPUSg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846691; x=1715933091; bh=ieijI9OHGbiVAeodlTBlD7C1wksi b4B9ge48d94o3qE=; b=fW1oe5MgF/9y9gF3nl1UnwfcFbk7rZ/SaFc9qOwHX4jN ULNSX1U0OA7nXv52cGca+kZZuTwktHxJD6p7cEnYSStIRskkaztWox/AlVPqiVkM vQz9mBKhgHNlrpl9F2/Y6Nv0OEJ48xk5KBSc/SEKNYgkYunEzogIhAWNT5i+O/JY SNewejnpCAZl++5jAeioD0Ql9lnDw4K9UrkJS+HAjpv/exvSIk33r6g8Cka5ZGqs tjo8Wjzrb5o2ZOAAvNLYseK9k2tpBxkUqALDskAyLerSj7DUmFr1JZh6K1VxxWi0 jizjciVTC//YYR9Rm/DmiivBAWAEHl+jX/88f/B8gg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepvdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:04:50 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 0112ae4a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:04:25 +0000 (UTC) Date: Thu, 16 May 2024 10:04:48 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 08/16] refs: convert iteration over replace refs to accept ref store Message-ID: <160e64e42ac2aebb5cb070c2834315b105214991.1715836916.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 03bf5d0e69..345d6a1e06 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 5a2b493507..77f9887235 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 3c3f9a3555..fc77240c93 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 Thu May 16 08:04: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: 13665812 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 CBC701311B1 for ; Thu, 16 May 2024 08:04:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846698; cv=none; b=af/kIP9ysw587Ds89y09q7mjyn/ZlH4nSnxrQmd1DCEQ0sT8hMcpUo6sV47kmaqsfKjl0R98kTtNUAtB807pPRUD2SRSr/fPo6+YZrRlxM78FsYT4ArCdW76sydqcR45uUBiNQ+npXrgkiJxTH23SVmjdTBb56lgyNTN9k7VZQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846698; c=relaxed/simple; bh=mMu39OqqWmVANxdAmcQ8xN6Dma87VooSlYYbxUJt+vM=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CaeI2FfcyJ6Xp+oBhqFkAz5urnY2UmFZYuytjkSY78b0SMXrMDkTc85TyIQlvAexyn3ZQ7QOGcByChOPisith+X2gaiFa/EiP8wiwtSOcybyjlVW1KMMjJODG+TRSI4iv79NMDdVMwiqNxL+5/6eE5E0Pj6M+0lwg5y8FfL4Tcg= 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=dH4qaMIb; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=j3LxLwDy; arc=none smtp.client-ip=103.168.172.147 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="dH4qaMIb"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="j3LxLwDy" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id EF5921380E54 for ; Thu, 16 May 2024 04:04:55 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 16 May 2024 04:04:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846695; x=1715933095; bh=Ml2nQ9xdcP 448Z5PS94oiBupAgbvPBCJH2dzR3IfHGQ=; b=dH4qaMIbbKSRbpxX6IClOhdPwl 4giA+UhgmD1GjAf71Wt4g8f70Q1qffUJNkfk0ENjQbcDxAcKcxoLHUqxK2TOJuED Nchg6qANtuAZ8ahm3aeEASZiNWeZH9/FTpV3i4glcdwCRCR0KvVu4sAz2+v8EtVd L3TKClcHyc/DGed1zFT07s8T15/k8cBsGINFldCNHlrXRpXi5mJLAmH+6clQSgTF VdscipGd8+F7W24/uORxj2qTF1GHWRpHiZ998CgDiOTkUz9zENHEiqfRLQraHpJC ah2Dw8kjwu6vrJRyt+rEe/My3xhUuA2QalIkZwnU2WWhIYdzNIIsUHXjfUDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846695; x=1715933095; bh=Ml2nQ9xdcP448Z5PS94oiBupAgbv PBCJH2dzR3IfHGQ=; b=j3LxLwDyYF++G35ZJo12wiLTAsSgJvo0H233VX0+CnuK 5JsPMxkWV9aPK5gsydSrVkKkkQ7/2wB7GcvjEUVWKjNq4p4OFP0M4oPVBCVtugTZ BLLCYeSIjELNNaUdqy7PceuvABR2dp3kMu37ScU5hcbqJd2RYXUhZkJjvyXqxms7 Cz7y5UnvPLwa3Mq375xod9A+myC+yLpfb4FEpSNkh1iJKyltvo18LmPCWPvCBBas ui266RsKBYTVRlGd+LEe66m7Dq3ynIeBk/Zx/x9nqgLUbbPcVyDF8qQvj7H/tiLH ixA+bSC0s00CvxV5+IRnVLiDX8wJwjO0UoNGV5xnPA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepfeenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:04:55 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 87b5a060 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:04:30 +0000 (UTC) Date: Thu, 16 May 2024 10:04:53 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 09/16] refs: pass ref store when detecting dangling symrefs Message-ID: <50c5d72c6af22c6f2f40ccb78ea7076d80c385d7.1715836916.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 345d6a1e06..e6bae9d52c 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 77f9887235..492ecfa4a1 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 Thu May 16 08:04:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13665813 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 999B5134CE3 for ; Thu, 16 May 2024 08:05:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846704; cv=none; b=hsni4gsRtBM6URkYB598iPr81U+0H0QKIzGYL6mdGAms1/M1B5EP8DA9gWVEOnCuzUHWWTVygCBoozXb+uwCdf75ppPOotUO5+OIYA826OT07Sz5GuXSURW4qrtU+2Ny7L+0VsnyPZOHIitkkn4eWUc5fKf7szubQEq6Lw15iZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846704; c=relaxed/simple; bh=taiIa1uxzmIo04QS9ZMbJcjKUKj1ucXpnvpLb9A4Xq0=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rEh3TQJKg9yCfVCVXfRTDRL9q5GSe1X5sgQsWQck7ubrsHTp9WlIbo+1uNGqjfipyaxcGZLjusAIalh0uLC7mcSDorhErrKuQZPCMcTzlS+1zKK+6b2NuQl62SsbgrmvNnP54QPerk6e8ELcZ1Runtw595BVnBDe/v4f1y/TX1I= 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=eq1YYjVV; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Vf53g9b9; arc=none smtp.client-ip=103.168.172.147 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="eq1YYjVV"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Vf53g9b9" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id EE6A11380282 for ; Thu, 16 May 2024 04:05:01 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 16 May 2024 04:05:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846701; x=1715933101; bh=MYxq+RI37q mZTPEZKWLVxaFj83GuyWwEamZLdGg5saw=; b=eq1YYjVVKZOk/b6rx42YzG7+oO wMy1Bs3aNsqZTzErcQoQeMBINGA7ZMNyJkq9hecnA1boI9Jv59I7FX8chLeIPzT4 UKs2sN0ZXHdYADMH/N/0/RJZXezPfu71P0BTMi5ZcbennPiMsCZsWqqomVN31ESG s5bKA/pbEvIZMw8hM7r0Pa7xQoLjmuWC2RI0Gj2BWgI2bL0dMpB58GcVUp1gjfbz nGmltbwUoCVWn+cCl0HDm9aKtXRb8HjDEQ5OoY1G4jnJnjCGVkXJ6/kgrqwW05km XfS24PVwN+gtMIAZX0VAxx++RoC6+kW3Y3LyQaaRAmfBejK5vLLYt8mBLynQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846701; x=1715933101; bh=MYxq+RI37qmZTPEZKWLVxaFj83Gu yWwEamZLdGg5saw=; b=Vf53g9b9Mian8VNijs4dVBzrVTiWy37wUD+8aFfso3qb yArZNXWuJKF1r8v4adkRJWHzdgZeProSS+ICIr78p9L376qlEBWorU3zEFNhWVqA ItAeqzFWTfsalX4fA2gDU0e03Ty+kxV5/fU49lHOi8VKEQk6ldbiJrDcGiHHqGOB BSuElu6dEBdM/4YVHWYIo0Oa5GxBnXupKdWOtpODrX+D08W9SeMX9GbLtnfVBH4Y sVLHlAly2wCXtjIkSPhchkp3HloF+lUtan+IoucTr2xBwwOdj9DfdY6EBNr1ahDw 2QOF7mfFpfpe/1RKoU1GYcxEpcN+7GZtTzLwovkhQg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepfeenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:05:01 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 3280460f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:04:36 +0000 (UTC) Date: Thu, 16 May 2024 10:04:58 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 10/16] refs: move object peeling into "object.c" 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: 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 e6bae9d52c..02d756f24f 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 fc77240c93..df9b16a872 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 Thu May 16 08:05: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: 13665814 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 9A216135A59 for ; Thu, 16 May 2024 08:05:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846710; cv=none; b=TnX9gWlaPDAG38gvDwZ8qL47QrzmVEcMf8j25UI0dyoQWcyUjGqnHHwJTT3DGEhPAceZwp+JYbtyiCBkntC3kvumSbVratT1Bd77U77N9QZXHJvJBlSU655m/7TLQyBN/qc7hdC2Q0i/vAevyYFberRPzN1FOci4ldGDvb+U4m4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846710; c=relaxed/simple; bh=qUHv8ehyMh5zaG3eLqQ5E2mhFnAUwOGpotVj3uF7J/4=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=B+oD7GJq87av9jKCursLgYrHjPKSncZI/RDpQ0t+ZjFzziCTdnUPHAOyYD24ins3/67aIP3Nqz27nxbGPa7Malp4vmqHz9NhhmwC/iGQKGrbpc78BS2LMIIZ+T3G3KEcZq3FhXrSW1G6s0dArS2/JeewGjyY/oQ5He6olrB3ru4= 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=Kxf6BIs4; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=d+b//XfD; arc=none smtp.client-ip=103.168.172.153 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="Kxf6BIs4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="d+b//XfD" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id E3146114006F for ; Thu, 16 May 2024 04:05:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 16 May 2024 04:05:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846707; x=1715933107; bh=biRZiYTrcm uUFbVFwKqM7VCyqwWKNmtqSFV7UU11Yqw=; b=Kxf6BIs4L3yDH37W4Fhpeeu1GL FWJJBZu6HPIv1i7QlDKDMDLZsoGazgqLJTuzfPnSMoehD2XiY/ZoezVXdCS3+c6H qlCIZkW8T8d5TyP38gstQ5/ymJO1zX9gyqbR5ENjgPIdDBOpZH+co53kYGtQHeUe dgFY5Z2T+s+mamHCz+g4ouhWRjO1xH+C0YNO/MrMENVYoEH2XT4Za4/QMu1oY/ON 8nTP0gNeB4AwaDLai0xi4buvWeguPiFG1KYSUH0uuFURwiKXjH8sj3MBufFu0593 18SToo77hUjs3nLZk0PvF+lRnYW7grnTEFdGSXRDb4R0FGXwdfvKhb44hh3A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846707; x=1715933107; bh=biRZiYTrcmuUFbVFwKqM7VCyqwWK NmtqSFV7UU11Yqw=; b=d+b//XfDC0q9UjAy3hfP9+6mJFp3pHcb2SlBjpSECWix mBAuyGo0leM7bYBWJeRdksXK3DGdOHLg0P50Mil2zKqqp3r8cYjFK9CphedfZOIR hELdZbz5rxqhk/w5shkkdeHJxoO7s6aZl4nbFzlNdZKNNBe92oCf+Bigg4uGAowb 67V8K/9eRZBMHnOP+/XTrWdhoeo12Xz9JQHqbz296CdKrHGs1z2auJc25ebQRLZT tz8XDD1hHGRbKoiEChZC4EMVYL84mnbRz903ZjfUzyByiCm9699F0E7luEEKY4iZ A+eHlBthYWeVJbTJpf+AebwUIo7RP/JvswwaOObg0w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepfeelkeetleetteelkeehteekieduueehhf eljeetkeehgfevvdevledtjedtkefhnecuffhomhgrihhnpehvrghlvddrthgrrhhgvght necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:05:07 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id f977a690 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:04:41 +0000 (UTC) Date: Thu, 16 May 2024 10:05:04 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 11/16] refs: pass repo when peeling objects 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: 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 02d756f24f..7aecf11bf4 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 492ecfa4a1..9769a25edd 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 bebceb4aa7..1b06fd936a 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 6c262c2193..4a8f83cb1a 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 Thu May 16 08:05:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13665815 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 D120B134751 for ; Thu, 16 May 2024 08:05:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846715; cv=none; b=mMXTt58cazkl7mwcwFlHfmm33lODZ+hSViz51Y8PWM0I06R3Ylv50yjTv3vkeVsWCTI1qc6QdMx6IcfOhr9LmmmEw0/P0tuQH+gncqsijR3Z7VNCTE8kexPc/V+j7yfKbICgKujb0Kt+iIMrNxNv4jytAILqPpSh1gdltvO6NaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846715; c=relaxed/simple; bh=29NLNaMne9BcWDHneTr/0xDnhRky03+2o8nupwC8+Y4=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Q3mJV43PDWWotVd3pAAhimmSMGlyagSRb2ZgOwHo0qW+KSBwL/egmzI47rhWYtiuc82AN3yPPTkhTseJQRufKGcKXHs9xhreMs/MhkY9JIBhs+NJt3OKURp0YPPcyXCvS1F2U4zi6Rt7cF7OGXprmo7njmzhVD6CnlLPdYOm32U= 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=t32E9/pN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Hn7sHm3H; arc=none smtp.client-ip=103.168.172.147 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="t32E9/pN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Hn7sHm3H" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id E485A1380282 for ; Thu, 16 May 2024 04:05:12 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 16 May 2024 04:05:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846712; x=1715933112; bh=sDqH7sm5Sj cT57mZOUx/cTEE6+xN/O1tS8WjKfpwrXc=; b=t32E9/pNzZC88OiDk5uCL8UK+R 3zqAQIDuKMlsFzR/rb77KPyaXmvL+L6WelI9M96+f+T3FOq/zbl4PVbUWK8d5/F5 b3OicyQRF3o3+UpHVwqy9UBQRx3lmEQqrKInaeVYbKAHdM/YPRlxj0H3sB9OtNXE lLjNGmoYriFcH7NR6SplWy8D74hlsFhVdGz8rORxKoHE/RwDt3thITLUGtjmyzVs lW2yb4Zbr3lFttLpaABULDDe+3zGddAxjQF0iqFIwMHf+EFs4iVTZF8eQVaAa+U3 RmR1IyaTjgzsWn6znMe+RDpApWmf/Afv5ZQHsIpsiFomgvDgYXZJlZeJEmaQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846712; x=1715933112; bh=sDqH7sm5SjcT57mZOUx/cTEE6+xN /O1tS8WjKfpwrXc=; b=Hn7sHm3HEtBMKvFF2uEXUKikYYepL5RxMh0CrmN0cstG 4epVngWCm+Xyb4i/EPkN97UUsewDvnekZGc+ZS4+398arRBtzxS+wbZRTELrmBFL e2YqUyLQwiCQD1G6XVHcQ1rsXn305chB2m9+QPFu/6+GCmjIu8Dsfp+bDKyETqzw eev2Emw2Jd7MuQktcQe0lX53AUz+koq3GNpFk4/mqCUDjlfUDo0QA3whKb1n5pls VCTT0cZB4+YU7wr2xigEV4otud2nhgQQ2zszYmovqeZ0xVjYnqzOxa07gRGXEDWP 4NGRaX+Bzrib4w3UTmcB54hLlpHi0kK0wPL/Ri1HrA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:05:12 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id f19032ba (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:04:47 +0000 (UTC) Date: Thu, 16 May 2024 10:05:10 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 12/16] refs: drop `git_default_branch_name()` Message-ID: <09ca848e7d8a9c4f4d8927d8f01a1c3cb5d34e8c.1715836916.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `git_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 7aecf11bf4..3618c8f7a4 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 9769a25edd..95c3437443 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 4a738f4c90..15ad84d3be 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 Thu May 16 08:05: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: 13665816 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 B580F6EB7A for ; Thu, 16 May 2024 08:05:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846720; cv=none; b=oRRs32ga3GwDZ4tlAvx9spdcxAYMLSDCg0kjDuZqBdcM78JufsV6X7B+lmaYtKXNRSs2bgF2z+fqrM9SuXDb1CtSGp0DKrLyDD4ufw4tvH3yIfF8UF2SF8mtoSIQHfvYyNxJxYHZk/l3y5pjduVUzwSggZOseIRiI2iiVOu29Vw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846720; c=relaxed/simple; bh=UkcZLLGo6apXJ+9UVKOEn/mYkigcX9mekUsCpbGztDE=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RFGKveJme0OWMK70dbCV8tDBjjyL+SREe1eQeeFSCffJqb7Mt1rLZQIa9/DllAsE2bGE6QOdNK6P7h53B0eocf62Ht7R9zVtmOtlAc6nftkE8/grDQIUBEBy+858OleYm6X3bmIrha6YNIttVlxhPiJG7tXRN987zk74rqfp4Q4= 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=kXdYXAWy; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=hOUo75Wj; arc=none smtp.client-ip=103.168.172.153 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="kXdYXAWy"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="hOUo75Wj" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id DE1F3114006F for ; Thu, 16 May 2024 04:05:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 16 May 2024 04:05:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846717; x=1715933117; bh=wp53xAXT2z 7YH2gofho6DPDe69XaV3HuEPogUPr4QAo=; b=kXdYXAWyQ0FUAZaHgAiNRPllHE Eo0xn5k70n9s7f2jSkNqtTum9EXLCdBZHNBV0vqgrWDKxXUwj5ZUaR3hAb5GgMmx 7HLKK0tOikOYIs2g/9KlmFW3JUcyRv0ZI5cLMh2+CYcd59F/ncgvTshEK/g73tPx 4vnVLqQv9Fl9Fmv12GEuVuxIFYZIBoZhg1znA8gzbxx/fbUfOa3MyilYnxNB07TS PS5RSE8dvvsh+AD5L8mPPQBnlHWdys8a6S+g2BCueQ9j3A7rCxPpY6jY0plb8wE5 4Vx9F2+4KQlH/Ukg64/xCmY+/HZeoEXKvQIjPlI7clhlRY2m1SB/n4WMVpNA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846717; x=1715933117; bh=wp53xAXT2z7YH2gofho6DPDe69Xa V3HuEPogUPr4QAo=; b=hOUo75WjDJ5f/iHl2kY6r+NpyPd2a5jOIfunjDfIK0BA 57HLyykMFWuoLPRNUAhAR3w3zE2bmWDSnKx5AbN73EcOP6MKieuBwEhcL1SIge9I eJxPT8QMGR4YqHvrXdOSKrZTOKqh1rhudBI08WkbrMUUV/LnB6HZ8yeA/T02jXy2 0UR0TggalJOSfa5obufH2T5JVHu4OV4rzNVkBXkD1pxMnmF+BZeWre/KuUE1MBww FVgmHRd1fQgvybQAkTOBUbzlI82vhKut1I4OWujNcHKOdJ/FZViG7EqcqJFyMz+D W+/aGYjT+eUXIJPsBBPHvivKqQSfgDZ3aLrDhTmV+A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepgeenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:05:17 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 7129f1b0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:04:52 +0000 (UTC) Date: Thu, 16 May 2024 10:05:14 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 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 3618c8f7a4..723bf7af20 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 95c3437443..fe0b6b44c5 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 Thu May 16 08:05: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: 13665817 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 B75F11369BE for ; Thu, 16 May 2024 08:05:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846725; cv=none; b=XcOdv8Vu+zIQzYRxtxdlQc2V/BFZxA470ChYG9zGkIi2GIVlo3Y9MwV91GU/YiVDRx4epudanY/mtL6qyDjD62yItIOOZqBYf3bJhs/8vqOpusgQMz3cydtH2a1jUKbxN+xk6Pq7sH8wDuHCBrVzBZ5eyDcYuCYd4P6zEQDr9GY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846725; c=relaxed/simple; bh=of00KeCKh7fit4FFaqUli0Wg/xyngjgewbW7g2JqDK0=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bTJdLseAU//hrNhLGrzl0Upx0sH/ApCRAfxACmfCtDl47YMYH8GRymvRLhagRJrAtGP/LgMtE4b9T2vTMf2/bxxk/DbY0jQlWxyHB6LQZcVoKQ1vFcSXLkzDSxDP/4f3GL1D2zmLvz1km5XgGZf6JP6JgcjEgdJHxyoEx/VR++0= 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=t9OTaFpf; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MJ5Hp9P8; arc=none smtp.client-ip=103.168.172.153 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="t9OTaFpf"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MJ5Hp9P8" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id CE9D61140065 for ; Thu, 16 May 2024 04:05:22 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 16 May 2024 04:05:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846722; x=1715933122; bh=h8Cb57n7dG j7zYyVt/pKAMSSElzsL2Jhj1AjSpo5R7o=; b=t9OTaFpftHF0NtGM0PaHkeX7M2 Z+XkK/pNxhi+DYL1kcmVbI6DSexDRT4vcUZ1xHk65LcIl/U/0oaxOjKiNO4rBH1K sejV0CF3lW5CbRFlQCG/Oi0oH//U/nnl2UcxoGeRmlvPqtHPFJrW5hTUoa57hpRt RTigC19Cb/ThYbBBuwdcKGQ4ZBAMbQfeGL6LaAozhmxiC2nUUIfhpGLrNvVnLlvp 02n6yCdAg/P9YG8twAvcZZLef4TT2Tk2A5mBT1ZQb4XegnkoJL7F2K54Tsx71vNT JqHoCLGzhjVXG8Q9NNAPQ/Y/MAvEaDezsoMHxP2KKT2ACztNgDrbs5ou5qbw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846722; x=1715933122; bh=h8Cb57n7dGj7zYyVt/pKAMSSElzs L2Jhj1AjSpo5R7o=; b=MJ5Hp9P8sTIejFBkvMfUH74/7fDfycWyuhhgoL6TjCgZ 8B44/NjDxkbghH5h7DOzv+BYiYi8Yi1hA2bWRGmcwmiAD5UfW3c4wBR82AU6s/LJ /PawhveS2gBSXUqdvK1DBLzuTDsfS421P6656lorER6DNfZgWKTRPzAWGtBrCEOc VXcrHZ62to7G0Hjo9ZGLQNoNS0A0JhFxZdZUpiGxX1UnBORI4cYMhFftpQEOw6BV pNWCjbNz3c0e7DE79Qcrf6XbTzrXHgqwT3pbav4fcV/sxAhoj0tZdIIPK/JU/Pp2 ZIToThReGM1b3BCkkoXvecriKgloVvsYAwY8PfCMsw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepudenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:05:22 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id ef70aece (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:04:57 +0000 (UTC) Date: Thu, 16 May 2024 10:05:19 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 14/16] refs/files: use correct repository Message-ID: <7ce6b7454df672610da001186949e54672895ae0.1715836916.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: 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 368df075c1..5294282770 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 Thu May 16 08:05: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: 13665818 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 85DA471739 for ; Thu, 16 May 2024 08:05:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846728; cv=none; b=IQvMQ5O5NkOoWNEBUd20fn/dbuavJKdR8VqisTm9MbtIUE/W/Ubw614MRPPDsPdl/TAhlbQLXFLrMasNolq0KEX75Ey0W24bbyesmHRTSPViekKXX7spwgFYW8QVp3OaIwZnE9eI56uNoNvL0Rs3H4qUq2VSMmZVfPFPzNQAqpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846728; c=relaxed/simple; bh=gHrD8PHPX2sGKJGC6lFYmlwsKp97qFOOnZQjWn33akc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PwRtgRS2rQEnXeWlI0FfeoxE2uED+KZVSiWZg7V5/hqWJ9389xbwMarJzlf7vUvWG7mGrU9toVbNIxWbJucLK9yVhnl++LVlfEzkiYd9ntbn/d0CR/EOy8i0gNCJR5PoJqvxITacO80SX+JsI326lo7UEpb7fsrA2p3zHD63lQY= 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=dB1QaVWr; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fD2mhAPG; arc=none smtp.client-ip=103.168.172.153 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="dB1QaVWr"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fD2mhAPG" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id D0D2611400C8 for ; Thu, 16 May 2024 04:05:26 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 16 May 2024 04:05:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846726; x=1715933126; bh=s6kcr1QYKI Pzm7Vnx+gA/IjC5xrEfZwZdAlB0yDOJjg=; b=dB1QaVWrMawY/PctUCTEruXVTq u02CNpYyzdKeoYYd7IUw1SUgoSTYu6y05Urlxh3LECpVAr2N4o4IQoisXaxAP4sZ ekRR2PNirv+IcX+NVO/eKEo9OupTgRTsDXm94D3uwlhgEBIUHyghDv5HwL5GarJj SRm9cM7rXTwFrchhfSJL3/NUc3/0UPtZa/4ilthTAXH6+cFQfmlvf8YYtdBmndUs sOgpn3Z3iV50WW4S9mguEZYlxGu0NdbBFGBxzCZ7IfuKQYCLZb7vAuDcsZHpZzzh 7Mir2Op9EhABSM/nyQHgpkerMRG6fk0PhUbaWF86c1+MJIMd5GAKOrNG5Q3Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846726; x=1715933126; bh=s6kcr1QYKIPzm7Vnx+gA/IjC5xrE fZwZdAlB0yDOJjg=; b=fD2mhAPGHJO5TtfDCn+7kJPk7qdtDvTw4S6nrrsjzy7C aWpDIyvqSIzGP68k87QxxLlm/pnw1D4zN2D3lcM7u63e1NtboVO38CXkx4Ik0ZqQ MIXvKcayEKUxwFh1lhX/bZ6/4Cif1FFUg6B/ZdhqU3iwt6Mr35ifdcVzJbGSIjwZ aiUQDGbV2LLtII1n0CRk6NXqa33jpJcQZVPJVC4QzBrq2qfQ/eLI5wk+9+v3ikAW VZruHtwJUlLjTcFMi5+3o8SPjCSKk40NWJ59t9guHWyNbmukOtUa3UemF8BvgiF9 +l8gVWUr7thT8fCGHZHem0Kp5rXeg+xo/0naQ6w9uQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:05:26 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id ea7d4bee (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:05:01 +0000 (UTC) Date: Thu, 16 May 2024 10:05:24 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 15/16] refs/files: remove references to `the_hash_algo` Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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 5294282770..5684f1bfc6 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 Thu May 16 08:05: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: 13665819 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 73300136E39 for ; Thu, 16 May 2024 08:05:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846733; cv=none; b=TrF2aOrvi1AI3h3z86HKion9syRX/Zt7d/jsdQoiPOP6fqqzQgMz29gzufvEIRL+5wY4/gpHmwfMK++Pvuep+F2qdq95+GyXOX/1PH+6AF8JIU1n1gQ8+cAomAUtKyCunqJdAfDmDUTNec1kkAVK9nDsgng8qWNrXxRywS3pQ5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715846733; c=relaxed/simple; bh=4XJ6jVpXKTPjeuntCNxe7awvp1sE+w76XOV6Tx9VC+4=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=I8b7zbHZdfZOOm1N4DS6YvbWbNh6CzdaZChHEOWKueJGTyfxak8N6It8eHJOqcuVf++1m8r8v7HQIKwgDuY7jAX7UESt29FL98prN92DO5iJOKPvmQEheOFj6SXY075K/b4UG8J/NTO50YxW59W/dl9E5P/tQFXbTck4HBX+CzM= 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=Dqju44WL; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XvvGu3Sz; arc=none smtp.client-ip=103.168.172.147 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="Dqju44WL"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XvvGu3Sz" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id BE4E01381145 for ; Thu, 16 May 2024 04:05:31 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 16 May 2024 04:05:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715846731; x=1715933131; bh=F6MUewRA2T tJ1AY+PZLF91qbA4jG0fuS7iUAyz68kp0=; b=Dqju44WLllT5mEYmhCIlgW++VJ F05yZYrRvl6vpf6T2Zuykl3VB9UU8Ve8sXLQnquklePm20JVUyWK4pCe0olKcm2W WXsFsRIHzNzXPsyC9RRjy8GGJoKBbaR2FjfhtjezGB5cUnnNqrAur+hRfvFO22M7 eee2idSTd6nQxPR6Pk5b/kIOw+H6QmH1dJisv86I2+Cy3GMMhhsfQQ+QOo/8KVIk b41uyfpFtBSKvEfvN0XdEg0fuGSdf5Ro/blBZJKzJlVFM0U9Wzj8MgrcyDgA5u/V 5XJSujaWkH0M3JF9t5HuwTBKIDBJszsz20n4fmhM+NUjJz8t9seAygrvFYIA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715846731; x=1715933131; bh=F6MUewRA2TtJ1AY+PZLF91qbA4jG 0fuS7iUAyz68kp0=; b=XvvGu3Szwfy7qWZ6o17QA7Cp92LoVuXgYHohyJCKlT4w W9gg4KweFUfsOyHQqPZvoDgTK9bTT5+qgYzJirUt99M21SCyrkeg6OrRpFp7O6/n XG1z0S2njEyg4TnI4zj0pYGSfbJ9c7ZVBtRmLa2Rn5EhOp7Ol1fkD6eRxko/589f 5MVduhZ0aYhCHCPQJ0u3/kRgzxeKibA61TWjjU6lAE752IJNPTTKcPJ/dorZy2pL lbdLTKwTYjJObwZlc7GilytRA2oTE+v5KRyAiTnQxo2IcGRtZuTj+dd4QG1doPBa 3Izn6vglEvFtMd4vVOnBbecKbkybDVSikdPAwlKCWQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehtddgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 16 May 2024 04:05:30 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id deca745f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 16 May 2024 08:05:06 +0000 (UTC) Date: Thu, 16 May 2024 10:05:29 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 16/16] refs/packed: remove references to `the_hash_algo` Message-ID: <9cd554166f61b0d1c17b45682422ed9a91814c03.1715836916.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 1b06fd936a..1d24c1ff28 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,