commit:     18c65792094cb90b6876940b86a35e21e3da488c
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 16 13:21:57 2021 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Aug 16 13:21:57 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=18c65792

libq/atom: introduce atom_compare_flg

atom_compare_flg allows to give match behaviour flags, such that often
used exceptions can now be handled without having to modify the input
atoms.

atom_compare is now a macro calling atom_compare_flg with
flags=ATOM_COMP_DEFAULT.

Updated all callers that can use this feature.

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

 libq/atom.c | 50 ++++++++++++++++++++++++++++----------------------
 libq/atom.h | 10 +++++++++-
 qlop.c      | 19 +++++++++----------
 qmerge.c    | 17 +++--------------
 quse.c      |  8 +++-----
 5 files changed, 52 insertions(+), 52 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index f4c7c1e..0959be5 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -514,7 +514,7 @@ _atom_compare_match(int ret, atom_operator op)
  * foo-1 <NOT_EQUAL> bar-1
  */
 atom_equality
-atom_compare(const depend_atom *data, const depend_atom *query)
+atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags)
 {
        atom_operator pfx_op;
        atom_operator sfx_op;
@@ -551,27 +551,32 @@ atom_compare(const depend_atom *data, const depend_atom 
*query)
         */
        bl_op = query->blocker;
        if (bl_op == ATOM_BL_ANTISLOT) {
-               /* ^perl -> match anything with a SLOT */
-               if (query->SLOT == NULL && data->SLOT == NULL)
-                       return NOT_EQUAL;
-               if (query->SLOT != NULL) {
-                       if (query->SUBSLOT == NULL) {
-                               /* ^perl:0 -> match different SLOT */
-                               if (data->SLOT == NULL ||
-                                               strcmp(query->SLOT, data->SLOT) 
== 0)
-                                       return NOT_EQUAL;
-                       } else {
-                               /* ^perl:0/5.28 -> match SLOT, but different 
SUBSLOT */
-                               if (data->SLOT == NULL ||
-                                               strcmp(query->SLOT, data->SLOT) 
!= 0)
-                                       return NOT_EQUAL;
-                               if (data->SUBSLOT == NULL ||
-                                               strcmp(query->SUBSLOT, 
data->SUBSLOT) == 0)
-                                       return NOT_EQUAL;
+               /* just disable/ignore antislot op when SLOT is supposed to be
+                * ignored */
+               if (!(flags & ATOM_COMP_NOSLOT)) {
+                       /* ^perl -> match anything with a SLOT */
+                       if (query->SLOT == NULL && data->SLOT == NULL)
+                               return NOT_EQUAL;
+                       if (query->SLOT != NULL) {
+                               if (query->SUBSLOT == NULL || flags & 
ATOM_COMP_NOSUBSLOT) {
+                                       /* ^perl:0 -> match different SLOT */
+                                       if (data->SLOT == NULL ||
+                                                       strcmp(query->SLOT, 
data->SLOT) == 0)
+                                               return NOT_EQUAL;
+                               } else {
+                                       /* ^perl:0/5.28 -> match SLOT, but 
different SUBSLOT */
+                                       if (data->SLOT == NULL ||
+                                                       strcmp(query->SLOT, 
data->SLOT) != 0)
+                                               return NOT_EQUAL;
+                                       if (!(flags & ATOM_COMP_NOSUBSLOT))
+                                               if (data->SUBSLOT == NULL ||
+                                                               
strcmp(query->SUBSLOT, data->SUBSLOT) == 0)
+                                                       return NOT_EQUAL;
+                               }
                        }
                }
                bl_op = ATOM_BL_NONE;  /* ease work below */
-       } else if (query->SLOT != NULL) {
+       } else if (query->SLOT != NULL && !(flags & ATOM_COMP_NOSLOT)) {
                /* check SLOT only when query side has it */
                if (data->SLOT == NULL) {
                        if (bl_op == ATOM_BL_NONE)
@@ -581,7 +586,7 @@ atom_compare(const depend_atom *data, const depend_atom 
*query)
                                /* slot has differs */
                                if (bl_op == ATOM_BL_NONE)
                                        return NOT_EQUAL;
-                       } else {
+                       } else if (!(flags & ATOM_COMP_NOSUBSLOT)) {
                                if (query->SUBSLOT != NULL) {
                                        if (data->SUBSLOT == NULL) {
                                                if (bl_op == ATOM_BL_NONE)
@@ -623,7 +628,7 @@ atom_compare(const depend_atom *data, const depend_atom 
*query)
        }
 
        /* check REPO, if query has it, ignore blocker stuff for this one */
-       if (query->REPO != NULL) {
+       if (query->REPO != NULL && !(flags & ATOM_COMP_NOREPO)) {
                if (data->REPO == NULL)
                        return NOT_EQUAL;
                if (strcmp(query->REPO, data->REPO) != 0)
@@ -753,8 +758,9 @@ atom_compare(const depend_atom *data, const depend_atom 
*query)
                return EQUAL;
 
        /* Make sure the -r# is the same. */
-       if ((sfx_op == ATOM_OP_STAR && !query->PR_int) ||
+       if ((sfx_op == ATOM_OP_STAR && query->PR_int == 0) ||
            pfx_op == ATOM_OP_PV_EQUAL ||
+               flags & ATOM_COMP_NOREV ||
            data->PR_int == query->PR_int)
                return _atom_compare_match(EQUAL, pfx_op);
        else if (data->PR_int < query->PR_int)

diff --git a/libq/atom.h b/libq/atom.h
index ead9154..8291daf 100644
--- a/libq/atom.h
+++ b/libq/atom.h
@@ -96,11 +96,19 @@ typedef enum {
        OLDER
 } atom_equality;
 
+/* bitflags to control compare behaviour */
+#define ATOM_COMP_DEFAULT    (0<<0)
+#define ATOM_COMP_NOREV      (1<<0)
+#define ATOM_COMP_NOSLOT     (1<<1)
+#define ATOM_COMP_NOSUBSLOT  (1<<2)
+#define ATOM_COMP_NOREPO     (1<<3)
+
 depend_atom *atom_explode_cat(const char *atom, const char *cat);
 #define atom_explode(A) atom_explode_cat(A, NULL)
 depend_atom *atom_clone(depend_atom *atom);
 void atom_implode(depend_atom *atom);
-atom_equality atom_compare(const depend_atom *a1, const depend_atom *a2);
+atom_equality atom_compare_flg(const depend_atom *a1, const depend_atom *a2, 
int flags);
+#define atom_compare(A,B) atom_compare_flg(A, B, ATOM_COMP_DEFAULT)
 atom_equality atom_compare_str(const char * const s1, const char * const s2);
 char *atom_to_string_r(char *buf, size_t buflen, depend_atom *a);
 char *atom_format_r(char *buf, size_t buflen,

diff --git a/qlop.c b/qlop.c
index 4783528..0e381bd 100644
--- a/qlop.c
+++ b/qlop.c
@@ -593,7 +593,7 @@ static int do_emerge_log(
                        continue;
 
                /* are we interested in this line? */
-               if (flags->show_emerge && verbose && (strpfx(p, "  *** emerge 
") == 0))
+               if (flags->show_emerge && verbose && p[7] == 'm' /* emerge */)
                {
                        char shortopts[8];  /* must hold as many opts converted 
below */
                        int numopts = 0;
@@ -753,15 +753,17 @@ static int do_emerge_log(
                                /* see if we need this atom */
                                atomw = NULL;
                                if (atomset == NULL) {
-                                       int orev = atom->PR_int;
-                                       if (flags->do_predict)
-                                               atom->PR_int = 0;  /* allow 
matching a revision */
+                                       /* match without revisions when we try 
to predict,
+                                        * such that our set remains rich 
enough to cover
+                                        * various predictions */
                                        array_for_each(atoms, i, atomw) {
-                                               if (atom_compare(atom, atomw) 
== EQUAL)
+                                               if (atom_compare_flg(atom, 
atomw,
+                                                                       
flags->do_predict
+                                                                       ? 
ATOM_COMP_NOREV
+                                                                       : 
ATOM_COMP_DEFAULT) == EQUAL)
                                                        break;
                                                atomw = NULL;
                                        }
-                                       atom->PR_int = orev;
                                } else {
                                        snprintf(afmt, sizeof(afmt), "%s/%s",
                                                        atom->CATEGORY, 
atom->PN);
@@ -1229,11 +1231,8 @@ static int do_emerge_log(
 
                        array_for_each(avgs, j, pkg) {
                                if (pkgstate == P_INIT) {
-                                       int orev = pkg->atom->PR_int;
                                        atom_equality eq;
-                                       pkg->atom->PR_int = 0;
-                                       eq = atom_compare(pkg->atom, atom);
-                                       pkg->atom->PR_int = orev;
+                                       eq = atom_compare_flg(pkg->atom, atom, 
ATOM_COMP_NOREV);
                                        switch (eq) {
                                                case EQUAL:
                                                        /* version-less atoms 
equal any versioned

diff --git a/qmerge.c b/qmerge.c
index a624b89..cf511ad 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -1095,23 +1095,12 @@ pkg_merge(int level, const depend_atom *qatom, const 
tree_match_ctx *mpkg)
 
        previnst = best_version(slotatom, BV_INSTALLED);
        if (previnst != NULL) {
-               char *orepo;
-               char *osubslot;
-
                /* drop REPO and SUBSLOT from query, we don't care about where
                 * the replacement comes from here, SUBSLOT only affects rebuild
                 * triggering */
-               orepo                   = previnst->atom->REPO;
-               osubslot                = previnst->atom->SUBSLOT;
-               previnst->atom->REPO    = NULL;
-               previnst->atom->SUBSLOT = NULL;
-
-               replacing               = atom_compare(mpkg->atom, 
previnst->atom);
-               replver                 = previnst->atom->PVR;
-
-               /* restore atom for later printing/handling */
-               previnst->atom->REPO    = orepo;
-               previnst->atom->SUBSLOT = osubslot;
+               replacing = atom_compare_flg(mpkg->atom, previnst->atom,
+                               ATOM_COMP_NOSUBSLOT | ATOM_COMP_NOREPO);
+               replver   = previnst->atom->PVR;
        }
 
        (void)qprint_tree_node(level, mpkg, previnst, replacing);

diff --git a/quse.c b/quse.c
index 400339a..ad0d9a2 100644
--- a/quse.c
+++ b/quse.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2020 Gentoo Foundation
+ * Copyright 2005-2021 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <[email protected]>
@@ -140,11 +140,9 @@ quse_search_use_local_desc(int portdirfd, struct 
quse_state *state)
                        if ((atom = atom_explode(buf)) == NULL)
                                continue;
 
-                       atom->REPO = (char *)state->repo;
-                       if (state->match != NULL)
-                               atom->SLOT = state->match->SLOT;  /* fake match 
*/
                        if (state->match == NULL ||
-                                       atom_compare(atom, state->match) == 
EQUAL)
+                                       atom_compare_flg(atom, state->match,
+                                               ATOM_COMP_NOSLOT | 
ATOM_COMP_NOREPO) == EQUAL)
                        {
                                if (state->do_list) {
                                        state->retv[i] = xstrdup(q);

Reply via email to