commit:     868b2b4b4f5140da7188389acf9f719fcf343ab2
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri Apr 19 11:47:29 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Apr 19 11:47:29 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=868b2b4b

atom: allow category-only atoms

This allows to match categories via atom matches, using e.g. mail-client/

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

 libq/atom.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index 4c06c1a..58565bc 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -160,6 +160,11 @@ atom_explode(const char *atom)
        if ((ptr = strrchr(ret->CATEGORY, '/')) != NULL) {
                ret->PN = ptr + 1;
                *ptr = '\0';
+
+               /* set PN to NULL if there's nothing */
+               if (ret->PN[0] == '\0')
+                       ret->PN = NULL;
+
                /* eat extra crap in case it exists, this is a feature to allow
                 * /path/to/pkg.ebuild, doesn't work with prefix operators
                 * though */
@@ -170,6 +175,13 @@ atom_explode(const char *atom)
                ret->CATEGORY = NULL;
        }
 
+       if (ret->PN == NULL) {
+               /* atom has no name, this is it */
+               ret->P = NULL;
+               ret->PVR = NULL;
+               return ret;
+       }
+
        /* hunt down build with USE dependencies */
        if ((ptr = strrchr(ret->PN, ']')) != NULL && ptr[1] == '\0' &&
                        (ptr = strrchr(ret->PN, '[')) != NULL)
@@ -378,15 +390,22 @@ int
 atom_compare(const depend_atom *a1, const depend_atom *a2)
 {
        /* sanity check that at most one has operators */
-       if (a1->pfx_op != ATOM_OP_NONE || a1->sfx_op != ATOM_OP_NONE) {
-               /* this is bogus, so punt it */
-               if (a2->pfx_op != ATOM_OP_NONE || a2->sfx_op != ATOM_OP_NONE)
+       if (a1->pfx_op != ATOM_OP_NONE ||
+                       a1->sfx_op != ATOM_OP_NONE ||
+                       a1->blocker != ATOM_BL_NONE)
+       {
+               /* is the other also having operators, then punt it */
+               if (a2->pfx_op != ATOM_OP_NONE ||
+                               a2->sfx_op != ATOM_OP_NONE ||
+                               a2->blocker != ATOM_BL_NONE)
                        return NOT_EQUAL;
+
                /* swap a1 & a2 so that a2 is the atom with operators */
                const depend_atom *as = a2;
                a2 = a1;
                a1 = as;
        }
+
        atom_operator pfx_op = a2->pfx_op;
        atom_operator sfx_op = a2->sfx_op;
 
@@ -437,6 +456,9 @@ atom_compare(const depend_atom *a1, const depend_atom *a2)
        if (a1->PN && a2->PN) {
                if (strcmp(a1->PN, a2->PN))
                        return NOT_EQUAL;
+       } else if (a1->CATEGORY && a2->CATEGORY) {
+               /* if CAT is set, and one side has empty PN, accept as match */
+               return a2->blocker != ATOM_BL_NONE ? NOT_EQUAL : EQUAL;
        } else if (a1->PN || a2->PN)
                return NOT_EQUAL;
 

Reply via email to