commit:     fd6ab7c570897747dfc89ff37a38a2a89512b96e
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Feb  5 15:35:21 2026 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Feb  5 15:35:21 2026 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=fd6ab7c5

libq/dep: make resolve store a tree_pkg_ctx ptr

instead of replacing atoms and setting flags, just use a pointer to a
pkg from tree, so we keep the original atom, and have all information we
need lateron

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/dep.c | 40 +++++++++++++++++++++++++++++-----------
 libq/dep.h | 14 +++++++++-----
 2 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/libq/dep.c b/libq/dep.c
index 4662e842..7be1f646 100644
--- a/libq/dep.c
+++ b/libq/dep.c
@@ -22,6 +22,24 @@
 #include "set.h"
 #include "tree.h"
 
+/* dep_prune_use: mutilates the tree, setting nodes to NULL that are not
+ * active -> should it return a new tree instead?
+ * dep_resolve_tree: looks up atoms in the tree and populates pkg
+ * pointer for a matching tree_pkg_ctx, doesn't do anything with ||,
+ * leaves nodes alone that don't resolve -> useless?
+ *
+ * needed functionality:
+ * - prune phase -> remove use-dep-groups that are not active
+ *                  downgrade use-dep nodes into group nodes
+ * - resolving   -> simple match of atom to a package from a tree
+ *                  - consider multiple trees, in priorities
+ *                  any-groups downgraded to all-group with the first
+ *                  block from the any-group that matches
+ * - flattening  -> assume all reductions to be done that one wants
+ *                  remove all groups (any, all, use) and return the atom
+ *                  nodes in an array
+ */
+
 #define DEP_TYPES(X) \
   X(NULL) \
   X(ATOM) \
@@ -51,11 +69,11 @@ struct dep_node_ {
   const char       *word;
   size_t            wordlen;
   depend_atom      *atom;
+  tree_pkg_ctx     *pkg;
   dep_node_t       *parent;
   array            *members;
   dep_type_t        type;
   bool              invert:1;
-  bool              atom_resolved:1;
 };
 
 dep_node_t *dep_grow_tree
@@ -454,7 +472,11 @@ void dep_print_tree
   }
   else if (root->type == DEP_ATOM)
   {
-    bool match = false;
+    atom_ctx *a     = root->atom;
+    bool      match = false;
+
+    if (root->pkg != NULL)
+      a = tree_pkg_atom(root->pkg, false);
 
     if (dohl)
     {
@@ -466,7 +488,8 @@ void dep_print_tree
         /* make m query, such that any specifics (SLOT,
          * pfx/sfx) from the depstring are ignored while
          * highlighting */
-        if (atom_compare(root->atom, m) == EQUAL) {
+        if (atom_compare(a, m) == EQUAL)
+        {
           match = true;
           break;
         }
@@ -475,7 +498,7 @@ void dep_print_tree
 
     fprintf(fp, "%s%s%s",
             match ? hlcolor : "",
-            atom_to_string(root->atom),
+            atom_to_string(a),
             match ? NORM : "");
   }
 
@@ -575,18 +598,13 @@ void dep_resolve_tree
 
   if (root->type == DEP_ATOM &&
       root->atom &&
-      !root->atom_resolved)
+      root->pkg == NULL)
   {
     atom_ctx *d = root->atom;
     array    *r = tree_match_atom(t, d, (TREE_MATCH_DEFAULT |
                                          TREE_MATCH_LATEST));
     if (array_cnt(r) > 0)
-    {
-      tree_pkg_ctx *pkg = array_get(r, 0);
-      atom_implode(d);
-      root->atom = atom_clone(tree_pkg_atom(pkg, false));
-      root->atom_resolved = 1;
-    }
+      root->pkg = array_get(r, 0);
     array_free(r);
   }
 

diff --git a/libq/dep.h b/libq/dep.h
index db828966..1de166fb 100644
--- a/libq/dep.h
+++ b/libq/dep.h
@@ -16,11 +16,15 @@ typedef struct dep_node_ dep_node_t;
 
 /* prototypes */
 dep_node_t *dep_grow_tree(const char *depend);
-void dep_print_tree(FILE *fp, const dep_node_t *root, size_t space, array *m, 
const char *c, int verbose);
-void dep_resolve_tree(dep_node_t *root, tree_ctx *t);
-void dep_burn_tree(dep_node_t *root);
-void dep_prune_use(dep_node_t *root, set *use);
-void dep_flatten_tree(dep_node_t *root, array *out);
+void        dep_print_tree(FILE *fp, const dep_node_t *root, size_t space, 
array *m, const char *c, int verbose);
+void        dep_resolve_tree(dep_node_t *root, tree_ctx *t);
+void        dep_burn_tree(dep_node_t *root);
+void        dep_prune_use(dep_node_t *root, set *use);
+void        dep_flatten_tree(dep_node_t *root, array *out);
+
+/* 2026 API boring (but predictable) names for grow/burn */
+#define dep_new_tree(D)  dep_grow_tree(D)
+#define dep_free_tree(D) dep_burn_tree(D)
 
 #endif
 

Reply via email to