From patchwork Thu Jun 6 05:29:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13687823 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB9681EB3E for ; Thu, 6 Jun 2024 05:29:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717651768; cv=none; b=cMgUd5tD7pDlRybJo5c2S6rPSdkAMCTl4W5wT4yCn8Utuvbszrwh7VlhBQElkfF26KV3Zg8EforxqNUyXdSAP0QLFkcPuWDVu/YRIMK/9/agFKDrbw50sNdtzLTg1c718Ck2FsydEO4vhwend3ngHSWZpTWCGmcsr+O82Z4Q9SE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717651768; c=relaxed/simple; bh=KIEow5x8ANkf91C51IUkchPizzQarlOpQ8kcOeN1XpE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dXzIKgRZ3Hq91aB7+Kue43fazHQtVas51k4buZtr4BChEBiiCRN4OMoOLeIRfprPupN3Lr6Dp0fPnpIbB3svrXy+X9p9nhUzRxEAtC0LCFHo4OtWikNAVu8vYV9WhsQxbiHSFa23HQTMojjW6mI/TuKP0ByiZ4wmkidCeU1+hS0= 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=V1REwk4i; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fH7VtIP3; arc=none smtp.client-ip=64.147.123.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="V1REwk4i"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fH7VtIP3" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id 9A3CC1C001D3; Thu, 6 Jun 2024 01:29:25 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 06 Jun 2024 01:29:26 -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=1717651765; x=1717738165; bh=WQJP1pnefI aouRU8eOongE19YDHwuzNv0UWTEwiZDgk=; b=V1REwk4iowKxpqLm0ql+dHdSkB h4sp75g8iicCCBZfwS5WmgYc8WcC4t4TABKO9CBg9XHD0AHSiE5B9TgnnuC8tx4M Lpayb+20YZkIEIel/OBtXyToEFNOTO3x5IUbZ3/stbxqhrFQmEfqmP8UFjDd+dHB 1SrNlDl8907pmrSI2rXIz48aJ8ZSq6K6gvjVLioTs4zC36XdP/xTXcm/4sUPB0Tx x/GNXT5m7Ar6cve/cBDKpwab46OJ20JTaEf8Ktwf+DzUVNRslPZMnisMI18ofZLf KSzyakXKFXho4J/A0HRTOiquZIrWhXVssad/gUUCSxXWbtybjGPKjY7SjMyQ== 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=1717651765; x=1717738165; bh=WQJP1pnefIaouRU8eOongE19YDHw uzNv0UWTEwiZDgk=; b=fH7VtIP3kWr0dPl1eIA9AI5vHSvQYS08v3W8uavMVEm/ yGR96icOAv2gbMMUvSUuwaRT00nJDe/Wd3rqgGQ72zmNiYa+RSRo58+IoTHUvWzl aSrgAct5j8+VbjUtxxZy5EhbqPtwX44mXMv/WZDOxpKPu9Phf5VumNijMmDBwEix FtURXsrqc3zMCVHMAxMH25Z/+hAW30gzMZVvwQNYHD31k2iFjcVziv9DNvh6eyH/ 9qgvvSrE3soZ9JiXobue2n7VchVpFgbmJqqU0nRhvNU3fjullDw69pRx6ArEBvyu e2KNZzubvm+RHRNAElRX/Iwvq8iUuUZhjSSxTZkLYw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeljedgleeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 6 Jun 2024 01:29:23 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id c501f3c2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 6 Jun 2024 05:28:53 +0000 (UTC) Date: Thu, 6 Jun 2024 07:29:20 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Eric Sunshine , Junio C Hamano , Ramsay Jones , Justin Tobler , Karthik Nayak , Jeff King Subject: [PATCH v5 06/12] refs/files: extract function to iterate through root refs Message-ID: <86cf0c84b121f23e7cbc3ba96299d9264123b485.1717649802.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: 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 | 51 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index b4e5437ffe..de8cc83174 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,49 @@ 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); } + + ret = 0; + +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,