From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id D42A7138334 for ; Sat, 13 Jul 2019 09:50:23 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A4098E07FA; Sat, 13 Jul 2019 09:50:22 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 72CA2E07FA for ; Sat, 13 Jul 2019 09:50:22 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 99D38347894 for ; Sat, 13 Jul 2019 09:50:19 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 793E966B for ; Sat, 13 Jul 2019 09:50:17 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1563010751.1b4c0049ff8a9297d0242c87d74946508a58c75c.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: libq/tree.c X-VCS-Directories: libq/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 1b4c0049ff8a9297d0242c87d74946508a58c75c X-VCS-Branch: master Date: Sat, 13 Jul 2019 09:50:17 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 5a6876eb-7530-401a-a0a1-32c90f5f2fed X-Archives-Hash: 5ed5f0791e450742ba7ac7aa5429f834 commit: 1b4c0049ff8a9297d0242c87d74946508a58c75c Author: Fabian Groffen gentoo org> AuthorDate: Sat Jul 13 09:39:11 2019 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Sat Jul 13 09:39:11 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=1b4c0049 libq/tree: greatly simplify tree_get_vdb_atoms use tree_foreach_pkg_fast() to construct the set of string atom names using atom_format() this function likely should be removed as the consumer should work on the atoms instead of their string representation Signed-off-by: Fabian Groffen gentoo.org> libq/tree.c | 91 ++++++++++++++++++------------------------------------------- 1 file changed, 27 insertions(+), 64 deletions(-) diff --git a/libq/tree.c b/libq/tree.c index 6bb6a89..f4314d0 100644 --- a/libq/tree.c +++ b/libq/tree.c @@ -1042,77 +1042,40 @@ tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete) return pkg_ctx->atom; } -set * -tree_get_vdb_atoms(const char *sroot, const char *svdb, int fullcpv) -{ - tree_ctx *ctx; +struct get_vdb_atoms_state { + set *cpf; + bool fullcpv; +}; - int cfd, j; - int dfd, i; +static int tree_get_vdb_atoms_cb(tree_pkg_ctx *pkg_ctx, void *priv) +{ + struct get_vdb_atoms_state *state = (struct get_vdb_atoms_state *)priv; + depend_atom *atom = tree_get_atom(pkg_ctx, false); - char buf[_Q_PATH_MAX]; - char slot[_Q_PATH_MAX]; - char *slotp = slot; - size_t slot_len; + if (state->fullcpv) { + state->cpf = add_set(atom_format("%[CATEGORY]%[PF]", atom), state->cpf); + } else { + state->cpf = add_set_unique(atom_format("%[CATEGORY]%[PN]", atom), + state->cpf, NULL); + } - struct dirent **cat; - struct dirent **pf; + return 0; +} - depend_atom *atom = NULL; - set *cpf = NULL; +set * +tree_get_vdb_atoms(const char *sroot, const char *svdb, int fullcpv) +{ + tree_ctx *ctx; + struct get_vdb_atoms_state state = { + .cpf = NULL, + .fullcpv = fullcpv != 0 + }; ctx = tree_open_vdb(sroot, svdb); if (!ctx) return NULL; - - /* scan the cat first */ - cfd = scandirat(ctx->tree_fd, ".", &cat, tree_filter_cat, alphasort); - if (cfd < 0) - goto fuckit; - - for (j = 0; j < cfd; j++) { - dfd = scandirat(ctx->tree_fd, cat[j]->d_name, - &pf, tree_filter_pkg, alphasort); - if (dfd < 0) - continue; - for (i = 0; i < dfd; i++) { - int blen = snprintf(buf, sizeof(buf), "%s/%s/SLOT", - cat[j]->d_name, pf[i]->d_name); - if (blen < 0 || (size_t)blen >= sizeof(buf)) { - warnf("unable to parse long package: %s/%s", - cat[j]->d_name, pf[i]->d_name); - continue; - } - - /* Chop the SLOT for the atom parsing. */ - buf[blen - 5] = '\0'; - if ((atom = atom_explode(buf)) == NULL) - continue; - /* Restore the SLOT. */ - buf[blen - 5] = '/'; - - slot_len = sizeof(slot); - eat_file_at(ctx->tree_fd, buf, &slotp, &slot_len); - rmspace(slot); - - if (fullcpv) { - if (atom->PR_int) - snprintf(buf, sizeof(buf), "%s/%s-%s-r%i", - atom->CATEGORY, atom->PN, atom->PV, atom->PR_int); - else - snprintf(buf, sizeof(buf), "%s/%s-%s", - atom->CATEGORY, atom->PN, atom->PV); - } else { - snprintf(buf, sizeof(buf), "%s/%s", atom->CATEGORY, atom->PN); - } - atom_implode(atom); - cpf = add_set(buf, cpf); - } - scandir_free(pf, dfd); - } - scandir_free(cat, cfd); - - fuckit: + tree_foreach_pkg_fast(ctx, tree_get_vdb_atoms_cb, &state, NULL); tree_close(ctx); - return cpf; + + return state.cpf; }