From patchwork Tue May 28 06:31: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: 13676170 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD05361FD9 for ; Tue, 28 May 2024 06:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716877905; cv=none; b=K2rA0mVvw+ouSxkl5phZOkuxtSKhD6btSM9MShYE6nvYhkPUr5QOihiwm6Fu7TEq6sv8WE67gdlvE/mhBr9J1aX+GiiijQmClYwxbAabWJQQ4BX8hNmTZKnCGWhMF2FbuqScKlv5fnozAXlI4sey61SCizqSGh0rlarLeuyeB0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716877905; c=relaxed/simple; bh=wxqrIvHl4mcgF1rWswr01x79mDPh2xAHD9lQ6LY5Hfo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MitrQTMHoAYFqLcc5SY7+XDsD9uaPzNElnXJz5OJGz+FCNm+/4U6x8B5scb/7Dp18aKdiHhO+gPWr0bflId0vayLdHhEaCTY3bwbC+wE7RIHmTFsWXnQSnKSO+yejcasb9iNS/UvlDHN1wp4jg6n+aGOVBXuYCa5KEt2jrl3WT4= 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=HOmsdAkm; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bKY5U6rA; arc=none smtp.client-ip=103.168.172.154 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="HOmsdAkm"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bKY5U6rA" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id DB3AF1140081; Tue, 28 May 2024 02:31:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 28 May 2024 02:31:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1716877902; x=1716964302; bh=i6v8j4buon QvYUSr0NORYQlNMMWNXvrzs9C9tw3SREo=; b=HOmsdAkmni2AMpNMGQ02wlTj0T 8gGwAjTxpswVI5nXMkuNEJ1SJh0z1bmlcGH7AVA8WcLQlKlnCULRU/bE4IXiSjvy hBcgtp2OfM0XYR1F5LxPBoQcxkcP3aAfLoqcPEovkiHUyJPvYlRJkXRFGRBdSg0S uZdtFH3FxeRk7oZsYS9xpvCNze3wxaiMstHwQq+gCfnIdZE5NPlwt2yKhedjl0hj 0XN8FtUGMr+SKuiVxaTY+4OrgDKkQN/rlTlUrIeWoVLWXUc913kGa4vnn7IG575T P069bYjyiQhHstnKpPy4evopilMGMAucebwgkwRHqFTZZp8CEYYzYaqNx6hA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1716877902; x=1716964302; bh=i6v8j4buonQvYUSr0NORYQlNMMWN Xvrzs9C9tw3SREo=; b=bKY5U6rA/U5VnQmHYjNt60XRxfaDLLyqLWsv6qlqcO7a x8JMbVctPzzWkRFyCz/RnXJNi36EdAsfgfb2+zkJewLxpgVXXjzsYyLhLvt+vD85 Ug6jF7e8douZFWqbzbl5h3lW9vzI8rUX4Y2vPOludRyvxrpU5xj2kAMtnPTRVcOx tUFReaO4hKQcspQ+APr8hlC0NTcwcnrxLuiskHA0VeF2Al1/ladKBqGFpy1n6V2L 05K9kArSCku6TB81LBBxk+TvX/wqslhh9300moWlibqe79U0H4xJ5JOgJ6P6JAHT lToWO+uLlN3g21GM77z5ysc7vskxjzeGV0tQl754gA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejhedguddtjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 28 May 2024 02:31:41 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 72be3910 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 28 May 2024 06:31:29 +0000 (UTC) Date: Tue, 28 May 2024 08:31:38 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Eric Sunshine , Junio C Hamano , Ramsay Jones , Justin Tobler Subject: [PATCH v3 06/12] refs/files: extract function to iterate through root refs 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: Extract a new function that can be used to iterate through all root refs known to the "files" backend. This will be used in the next commit, where we start to teach ref backends to remove themselves. Signed-off-by: Patrick Steinhardt --- refs/files-backend.c | 49 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index b4e5437ffe..b7268b26c8 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -323,17 +323,15 @@ static void loose_fill_ref_dir(struct ref_store *ref_store, add_per_worktree_entries_to_dir(dir, dirname); } -/* - * Add root refs to the ref dir by parsing the directory for any files which - * follow the root ref syntax. - */ -static void add_root_refs(struct files_ref_store *refs, - struct ref_dir *dir) +static int for_each_root_ref(struct files_ref_store *refs, + int (*cb)(const char *refname, void *cb_data), + void *cb_data) { struct strbuf path = STRBUF_INIT, refname = STRBUF_INIT; const char *dirname = refs->loose->root->name; struct dirent *de; size_t dirnamelen; + int ret; DIR *d; files_ref_path(refs, &path, dirname); @@ -341,7 +339,7 @@ static void add_root_refs(struct files_ref_store *refs, d = opendir(path.buf); if (!d) { strbuf_release(&path); - return; + return -1; } strbuf_addstr(&refname, dirname); @@ -357,14 +355,47 @@ static void add_root_refs(struct files_ref_store *refs, strbuf_addstr(&refname, de->d_name); dtype = get_dtype(de, &path, 1); - if (dtype == DT_REG && is_root_ref(de->d_name)) - loose_fill_ref_dir_regular_file(refs, refname.buf, dir); + if (dtype == DT_REG && is_root_ref(de->d_name)) { + ret = cb(refname.buf, cb_data); + if (ret) + goto done; + } strbuf_setlen(&refname, dirnamelen); } + +done: strbuf_release(&refname); strbuf_release(&path); closedir(d); + return ret; +} + +struct fill_root_ref_data { + struct files_ref_store *refs; + struct ref_dir *dir; +}; + +static int fill_root_ref(const char *refname, void *cb_data) +{ + struct fill_root_ref_data *data = cb_data; + loose_fill_ref_dir_regular_file(data->refs, refname, data->dir); + return 0; +} + +/* + * Add root refs to the ref dir by parsing the directory for any files which + * follow the root ref syntax. + */ +static void add_root_refs(struct files_ref_store *refs, + struct ref_dir *dir) +{ + struct fill_root_ref_data data = { + .refs = refs, + .dir = dir, + }; + + for_each_root_ref(refs, fill_root_ref, &data); } static struct ref_cache *get_loose_ref_cache(struct files_ref_store *refs,