commit: ea5f39546da6d94bcf910740f1dcff64ea44e010 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> AuthorDate: Sun Apr 20 08:41:02 2025 +0000 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> CommitDate: Sun Apr 20 08:41:02 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=ea5f3954
libq/tree: rename misleading cachetype to treetype Originally this implementation only contained the PMS and MD5 caches, but has grown to more or less generically support all kinds of trees, including raw ebuilds (e.g. no cache whatsoever). Rename the struct member to treetype, and the CACHE_* enums to TREE_* respectively. No code changes other than renaming symbols are done in this commit. Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> libq/tree.c | 66 ++++++++++++++++++++++++++++++------------------------------- libq/tree.h | 18 ++++++++--------- qgrep.c | 6 +++--- qmerge.c | 2 +- qwhich.c | 30 ++++++++++++++-------------- 5 files changed, 61 insertions(+), 61 deletions(-) diff --git a/libq/tree.c b/libq/tree.c index 335ac79..80e570f 100644 --- a/libq/tree.c +++ b/libq/tree.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2023 Gentoo Foundation + * Copyright 2005-2025 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2008 Ned Ludd - <[email protected]> @@ -96,7 +96,7 @@ tree_open(const char *sroot, const char *portdir) snprintf(buf, sizeof(buf), "%s/%s", portdir, portcachedir_md5); ret = tree_open_int(sroot, buf, true); if (ret != NULL) { - ret->cachetype = CACHE_METADATA_MD5; + ret->treetype = TREE_METADATA_MD5; ret->repo = repo; return ret; } @@ -104,14 +104,14 @@ tree_open(const char *sroot, const char *portdir) snprintf(buf, sizeof(buf), "%s/%s", portdir, portcachedir_pms); ret = tree_open_int(sroot, buf, true); if (ret != NULL) { - ret->cachetype = CACHE_METADATA_PMS; + ret->treetype = TREE_METADATA_PMS; ret->repo = repo; return ret; } ret = tree_open_int(sroot, portdir, true); if (ret != NULL) { - ret->cachetype = CACHE_EBUILD; + ret->treetype = TREE_EBUILD; ret->repo = repo; return ret; } @@ -128,7 +128,7 @@ tree_open_vdb(const char *sroot, const char *svdb) { tree_ctx *ret = tree_open_int(sroot, svdb, false); if (ret != NULL) - ret->cachetype = CACHE_VDB; + ret->treetype = TREE_VDB; return ret; } @@ -146,7 +146,7 @@ tree_open_ebuild(const char *sroot, const char *portdir) (void)rmspace(repo); ret->repo = repo; } - ret->cachetype = CACHE_EBUILD; + ret->treetype = TREE_EBUILD; } return ret; } @@ -159,11 +159,11 @@ tree_open_binpkg(const char *sroot, const char *spkg) int fd; if (ret != NULL) { - ret->cachetype = CACHE_BINPKGS; + ret->treetype = TREE_BINPKGS; fd = openat(ret->tree_fd, binpkg_packages, O_RDONLY | O_CLOEXEC); if (eat_file_fd(fd, &ret->cache.store, &ret->cache.storesize)) { - ret->cachetype = CACHE_PACKAGES; + ret->treetype = TREE_PACKAGES; } else if (ret->cache.store != NULL) { free(ret->cache.store); ret->cache.store = NULL; @@ -552,7 +552,7 @@ tree_next_pkg(tree_cat_ctx *cat_ctx) if (ctx->do_sort && cat_ctx->pkg_ctxs != NULL) { /* bypass to use the cache if it exists */ ret = tree_next_pkg_int(cat_ctx); - } else if (ctx->cachetype == CACHE_EBUILD) { + } else if (ctx->treetype == TREE_EBUILD) { char *p; /* serve *.ebuild files each as separate pkg_ctx with name set @@ -572,7 +572,7 @@ tree_next_pkg(tree_cat_ctx *cat_ctx) pkgdir->tree_fd = cat_ctx->fd; pkgdir->do_sort = ctx->do_sort; pkgdir->repo = ctx->repo; - pkgdir->cachetype = ctx->cachetype; + pkgdir->treetype = ctx->treetype; ctx->ebuilddir_cat_ctx = tree_open_cat(pkgdir, ctx->ebuilddir_pkg_ctx->name); @@ -601,7 +601,7 @@ tree_next_pkg(tree_cat_ctx *cat_ctx) } } } while (ret == NULL); - } else if (ctx->cachetype == CACHE_BINPKGS) { + } else if (ctx->treetype == TREE_BINPKGS) { char *p = NULL; ret = NULL; do { @@ -1092,7 +1092,7 @@ tree_pkg_read(tree_pkg_ctx *pkg_ctx) return pkg_ctx->meta; if (pkg_ctx->fd == -1) { - if (ctx->cachetype == CACHE_EBUILD || ctx->cachetype == CACHE_BINPKGS) { + if (ctx->treetype == TREE_EBUILD || ctx->treetype == TREE_BINPKGS) { char *p = (char *)pkg_ctx->name; p += strlen(p); *p = '.'; @@ -1107,24 +1107,24 @@ tree_pkg_read(tree_pkg_ctx *pkg_ctx) return NULL; } - if (ctx->cachetype == CACHE_METADATA_MD5) { + if (ctx->treetype == TREE_METADATA_MD5) { ret = tree_read_file_md5(pkg_ctx); /* md5-cache, is sort of documented in egencache man-page * key-points are that an md5 is provided for the ebuild itself, * and if it includes eclasses, the md5s for each eclass. These * are available as _md5_ and _eclasses_ keys. The latter uses * tab-separation of form <eclass-name>\t<md5>\t... */ - } else if (ctx->cachetype == CACHE_METADATA_PMS) { + } else if (ctx->treetype == TREE_METADATA_PMS) { ret = tree_read_file_pms(pkg_ctx); /* PMS implies to do an mtime and existence check (the cache may * contain extra stuff) but since this form of metadata in fact * is extinct, because these checks are insufficient and * impossible on e.g. a git-based tree. */ - } else if (ctx->cachetype == CACHE_EBUILD) { + } else if (ctx->treetype == TREE_EBUILD) { ret = tree_read_file_ebuild(pkg_ctx); - } else if (ctx->cachetype == CACHE_BINPKGS) { + } else if (ctx->treetype == TREE_BINPKGS) { ret = tree_read_file_binpkg(pkg_ctx); - } else if (ctx->cachetype == CACHE_PACKAGES) { + } else if (ctx->treetype == TREE_PACKAGES) { ret = (tree_pkg_meta *)pkg_ctx->cat_ctx->ctx->pkgs; } @@ -1190,7 +1190,7 @@ tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t offset, const char *keyn) * key, the tree_pkg_meta_get macro as called by the user takes care * of offset and keyn pointing to the same thing */ - if (ctx->cachetype == CACHE_VDB) { + if (ctx->treetype == TREE_VDB) { if (pkg_ctx->meta == NULL) pkg_ctx->meta = xzalloc(sizeof(tree_pkg_meta)); @@ -1253,8 +1253,8 @@ tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t offset, const char *keyn) * contain everything available (for a semi-good reason though) * We cannot downgrade the tree execution to BINPKGS, because * we're running from tree_foreach_packages */ - if (*key == NULL && ctx->cachetype == CACHE_PACKAGES) { - ctx->cachetype = CACHE_BINPKGS; + if (*key == NULL && ctx->treetype == TREE_PACKAGES) { + ctx->treetype = TREE_BINPKGS; pkg_ctx->fd = -1; /* trigger tree_pkg_read to do something */ @@ -1263,7 +1263,7 @@ tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t offset, const char *keyn) pkg_ctx->meta = NULL; pkg_ctx->meta = tree_pkg_read(pkg_ctx); - ctx->cachetype = CACHE_PACKAGES; + ctx->treetype = TREE_PACKAGES; if (pkg_ctx->meta == NULL) { /* hrmffff. */ pkg_ctx->fd = -2; @@ -1295,7 +1295,7 @@ tree_pkg_metadata(tree_pkg_ctx *pkg_ctx) * tag, but practically speaking we don't care at all, so we can * just extract everything between <email> and </email> */ - if (ctx->cachetype == CACHE_EBUILD) { + if (ctx->treetype == TREE_EBUILD) { fd = openat(pkg_ctx->cat_ctx->fd, "metadata", O_RDONLY | O_CLOEXEC); } else { char buf[_Q_PATH_MAX]; @@ -1574,7 +1574,7 @@ tree_foreach_pkg(tree_ctx *ctx, tree_pkg_cb callback, void *priv, ctx->query_atom = query; /* handle Packages (binpkgs index) file separately */ - if (ctx->cachetype == CACHE_PACKAGES) + if (ctx->treetype == TREE_PACKAGES) return tree_foreach_packages(ctx, callback, priv); ret = 0; @@ -1611,7 +1611,7 @@ tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete) if (complete) { tree_ctx *ctx = pkg_ctx->cat_ctx->ctx; - if (ctx->cachetype == CACHE_VDB) { + if (ctx->treetype == TREE_VDB) { if (pkg_ctx->atom->SLOT == NULL) { /* FIXME: use tree_meta_get !!! */ if (pkg_ctx->slot == NULL) @@ -1641,7 +1641,7 @@ tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete) } /* repo is set from the tree, when found */ if (pkg_ctx->atom->REPO == NULL) { - if (pkg_ctx->repo == NULL && ctx->cachetype == CACHE_BINPKGS) { + if (pkg_ctx->repo == NULL && ctx->treetype == TREE_BINPKGS) { if (meta == NULL) meta = tree_pkg_read(pkg_ctx); if (meta != NULL && meta->Q_repository != NULL) { @@ -1741,7 +1741,7 @@ tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void *priv) pkg->repo = tctx->repo != NULL ? xstrdup(tctx->repo) : NULL; if (meta != NULL) { pkg->fd = -2; /* don't try to read, we fill it in here */ - if (tctx->cachetype == CACHE_PACKAGES) { + if (tctx->treetype == TREE_PACKAGES) { /* need to copy, source is based on temp space in foreach */ pkg->meta = tree_clone_meta(meta); } else { @@ -1768,7 +1768,7 @@ tree_match_atom(tree_ctx *ctx, const depend_atom *query, int flags) ctx->do_sort = true; /* sort uses buffer, which cache relies on */ ctx->query_atom = NULL; /* ensure the cache contains ALL pkgs */ - if ((ctx->cachetype == CACHE_PACKAGES || ctx->cachetype == CACHE_BINPKGS) + if ((ctx->treetype == TREE_PACKAGES || ctx->treetype == TREE_BINPKGS) && ctx->cache.categories == NULL) { set *cache; @@ -1838,7 +1838,7 @@ tree_match_atom(tree_ctx *ctx, const depend_atom *query, int flags) n = xzalloc(sizeof(tree_match_ctx)); \ n->atom = atom; \ n->pkg = pkg_ctx; \ - if (C->ctx->cachetype == CACHE_PACKAGES && \ + if (C->ctx->treetype == TREE_PACKAGES && \ pkg_ctx->meta->Q_PATH != NULL) \ { \ /* binpkg-multi-instance has a PATH ready for us */ \ @@ -1847,14 +1847,14 @@ tree_match_atom(tree_ctx *ctx, const depend_atom *query, int flags) } else { \ snprintf(n->path, sizeof(n->path), "%s/%s/%s%s", \ (char *)C->ctx->path, C->name, pkg_ctx->name, \ - C->ctx->cachetype == CACHE_EBUILD ? ".ebuild" : \ - C->ctx->cachetype == CACHE_BINPKGS ? ".tbz2" : \ - C->ctx->cachetype == CACHE_PACKAGES ? ".tbz2" : ""); \ + C->ctx->treetype == TREE_EBUILD ? ".ebuild" : \ + C->ctx->treetype == TREE_BINPKGS ? ".tbz2" : \ + C->ctx->treetype == TREE_PACKAGES ? ".tbz2" : ""); \ } \ if (flags & TREE_MATCH_METADATA) \ n->meta = tree_pkg_read(pkg_ctx); \ - if (C->ctx->cachetype == CACHE_BINPKGS || \ - C->ctx->cachetype == CACHE_PACKAGES) \ + if (C->ctx->treetype == TREE_BINPKGS || \ + C->ctx->treetype == TREE_PACKAGES) \ n->free_atom = n->free_meta = 0; \ n->next = ret; \ ret = n; \ diff --git a/libq/tree.h b/libq/tree.h index efafe73..ed7b55b 100644 --- a/libq/tree.h +++ b/libq/tree.h @@ -1,5 +1,5 @@ /* - * Copyright 2005-2023 Gentoo Foundation + * Copyright 2005-2025 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 */ @@ -31,14 +31,14 @@ struct tree_ctx { size_t cat_cur; bool do_sort:1; enum { - CACHE_UNSET = 0, - CACHE_METADATA_MD5, - CACHE_METADATA_PMS, - CACHE_EBUILD, - CACHE_VDB, - CACHE_PACKAGES, - CACHE_BINPKGS, - } cachetype:3; + TREE_UNSET = 0, + TREE_METADATA_MD5, + TREE_METADATA_PMS, + TREE_EBUILD, + TREE_VDB, + TREE_PACKAGES, + TREE_BINPKGS, + } treetype:3; tree_pkg_ctx *ebuilddir_pkg_ctx; tree_cat_ctx *ebuilddir_cat_ctx; tree_ctx *ebuilddir_ctx; diff --git a/qgrep.c b/qgrep.c index ad7a126..51c2a07 100644 --- a/qgrep.c +++ b/qgrep.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2020 Gentoo Foundation + * Copyright 2005-2025 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005 Petteri Räty - <[email protected]> @@ -404,9 +404,9 @@ qgrep_cache_cb(tree_pkg_ctx *pkg_ctx, void *priv) /* need to construct path in portdir to ebuild, pass it to grep */ cctx = (tree_ctx *)(pkg_ctx->cat_ctx->ctx); - if (cctx->cachetype == CACHE_EBUILD) { + if (cctx->treetype == TREE_EBUILD) { pfd = cctx->tree_fd; - } else if (cctx->cachetype == CACHE_VDB) { + } else if (cctx->treetype == TREE_VDB) { pfd = openat(cctx->portroot_fd, data->portdir, O_RDONLY|O_CLOEXEC); } else { pfd = openat(cctx->tree_fd, "../..", O_RDONLY|O_CLOEXEC); diff --git a/qmerge.c b/qmerge.c index 836973c..a856940 100644 --- a/qmerge.c +++ b/qmerge.c @@ -1162,7 +1162,7 @@ pkg_merge(int level, const depend_atom *qatom, const tree_match_ctx *mpkg) continue; } - if (bpkg->pkg->cat_ctx->ctx->cachetype != CACHE_VDB) + if (bpkg->pkg->cat_ctx->ctx->treetype != TREE_VDB) pkg_fetch(level + 1, subatom, bpkg); tree_match_close(bpkg); diff --git a/qwhich.c b/qwhich.c index daae2f5..ce3416b 100644 --- a/qwhich.c +++ b/qwhich.c @@ -1,5 +1,5 @@ /* - * Copyright 2021-2024 Gentoo Foundation + * Copyright 2021-2025 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2021- Fabian Groffen - <[email protected]> @@ -176,21 +176,21 @@ int qwhich_main(int argc, char **argv) repolen = strlen(reponam); } else { reponam = t->path; - if (t->cachetype == CACHE_METADATA_MD5) + if (t->treetype == TREE_METADATA_MD5) repolen = strlen(t->path) - (sizeof("/metadata/md5-cache") - 1); - else if (t->cachetype == CACHE_METADATA_PMS) + else if (t->treetype == TREE_METADATA_PMS) repolen = strlen(t->path) - (sizeof("/metadata/cache") - 1); - else if (t->cachetype == CACHE_EBUILD || - t->cachetype == CACHE_BINPKGS || - t->cachetype == CACHE_PACKAGES) + else if (t->treetype == TREE_EBUILD || + t->treetype == TREE_BINPKGS || + t->treetype == TREE_PACKAGES) repolen = strlen(t->path); else repolen = 0; } - switch (t->cachetype) { - case CACHE_BINPKGS: - case CACHE_PACKAGES: + switch (t->treetype) { + case TREE_BINPKGS: + case TREE_PACKAGES: ext = "tbz2"; break; default: @@ -208,11 +208,11 @@ int qwhich_main(int argc, char **argv) if (m.print_atom) { printf("%s\n", atom_format(m.fmt, tmcw->atom)); } else { - if (t->cachetype == CACHE_METADATA_MD5 || - t->cachetype == CACHE_METADATA_PMS || - t->cachetype == CACHE_EBUILD || - t->cachetype == CACHE_BINPKGS || - t->cachetype == CACHE_PACKAGES) + if (t->treetype == TREE_METADATA_MD5 || + t->treetype == TREE_METADATA_PMS || + t->treetype == TREE_EBUILD || + t->treetype == TREE_BINPKGS || + t->treetype == TREE_PACKAGES) { if (m.print_path) printf("%s%.*s%s%s%s/%s%s%s\n", @@ -229,7 +229,7 @@ int qwhich_main(int argc, char **argv) DKBLUE, tmcw->atom->PN, BLUE, tmcw->atom->PF, DKGREEN, ext, NORM); - } else if (t->cachetype == CACHE_VDB && !m.print_path) { + } else if (t->treetype == TREE_VDB && !m.print_path) { printf("%s%s/%s%s%s.ebuild%s\n", DKBLUE, tmcw->path, BLUE, tmcw->atom->PF,
