- add pool_match_nevr() to match a single solvable's nevr against
authorMichael Schroeder <mls@suse.de>
Tue, 6 May 2008 16:22:12 +0000 (16:22 +0000)
committerMichael Schroeder <mls@suse.de>
Tue, 6 May 2008 16:22:12 +0000 (16:22 +0000)
  a dependency (that's also how rpm4 handles obsoletes).
- use it for obsoetes and _NAME jobs

src/policy.c
src/pool.c
src/pool.h
src/solver.c
src/solverdebug.c

index 3e397452357212635354493d0ae28e5340a5491b..48b2f26c8e17bbb4eb249514f9de4430d5e22f67 100644 (file)
 #include "poolarch.h"
 
 
-static inline Id dep2name(Pool *pool, Id dep) 
-{
-  while (ISRELDEP(dep))
-    {    
-      Reldep *rd = rd = GETRELDEP(pool, dep);
-      dep = rd->name;
-    }    
-  return dep; 
-}
-
 static Solver *prune_best_version_arch_sortcmp_data;
 
 /*-----------------------------------------------------------------*/
@@ -258,12 +248,11 @@ prune_to_best_version(Solver *solv, Queue *plist)
       obsp = s->repo->idarraydata + s->obsoletes;
       while ((obs = *obsp++) != 0)
        {
-         Id obsname = dep2name(pool, obs);
          FOR_PROVIDES(p, pp, obs)
            {
              if (pool->solvables[p].name == s->name)
                continue;
-             if (!solv->obsoleteusesprovides && obsname != pool->solvables[p].name)
+             if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
                continue;
              for (j = 0; j < plist->count; j++)
                {
@@ -448,10 +437,9 @@ policy_findupdatepackages(Solver *solv, Solvable *s, Queue *qs, int allowall)
          obsp = ps->repo->idarraydata + ps->obsoletes;
          while ((obs = *obsp++) != 0)  /* for all obsoletes */
            {
-             Id obsname = dep2name(pool, obs);
              FOR_PROVIDES(p2, pp2, obs)   /* and all matching providers of the obsoletes */
                {
-                 if (!solv->obsoleteusesprovides && obsname != pool->solvables[p2].name)
+                 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
                    continue;
                  if (p2 == n)          /* match ! */
                    break;
index 13f985a67abebb403e659e568e9b1e4386eddd43..613c9b01daee059154cfcfa955eff436f7e48836 100644 (file)
@@ -403,6 +403,52 @@ pool_queuetowhatprovides(Pool *pool, Queue *q)
 
 /*************************************************************************/
 
+/* check if a package's nevr matches a dependency */
+
+int
+pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
+{
+  Reldep *rd = GETRELDEP(pool, d);
+  Id name = rd->name;
+  Id evr = rd->evr;
+  int flags = rd->flags;
+
+  if (flags > 7)
+    {
+      switch (flags)
+       {
+       case REL_ARCH:
+         if (s->arch != evr)
+           return 0;
+         return pool_match_nevr(pool, s, name);
+       case REL_OR:
+         if (pool_match_nevr(pool, s, name))
+           return 1;
+         return pool_match_nevr(pool, s, evr);
+       case REL_AND:
+       case REL_WITH:
+         if (!pool_match_nevr(pool, s, name))
+           return 0;
+         return pool_match_nevr(pool, s, evr);
+       default:
+         return 0;
+       }
+    }
+  if (!pool_match_nevr(pool, s, name))
+    return 0;
+  if (evr == s->evr)
+    return flags & 2 ? 1 : 0;
+  if (!flags)
+    return 0;
+  if (flags == 7)
+    return 1;
+  if (flags != 2 && flags != 5)
+    flags ^= 5;
+  if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
+    return 1;
+  return 0;
+}
+
 /*
  * addrelproviders
  * 
index 1f9485e885916b48fc89848aa574ee62b31f9507..113347fb3e52c33ae0d660adebd9ecf942dbcabc 100644 (file)
@@ -183,6 +183,15 @@ int solvable_trivial_installable_queue(Solvable *s, Queue *installed);
 
 void pool_create_state_maps(Pool *pool, Queue *installed, Map *installedmap, Map *conflictsmap);
 
+int pool_match_nevr_rel(Pool *pool, Solvable *s, Id d);
+
+static inline int pool_match_nevr(Pool *pool, Solvable *s, Id d)
+{
+  if (!ISRELDEP(d))
+    return d == s->name;
+  else
+    return pool_match_nevr_rel(pool, s, d);
+}
 
 
 /**
index 08a7a5d6847559bb8b3abbe31f5f962d4d53d209..afcdd5920847f4fe94fa22eb1501c886df41a8e8 100644 (file)
  *
  */
 
-static inline Id dep2name(Pool *pool, Id dep) 
-{
-  while (ISRELDEP(dep))
-    {    
-      Reldep *rd = rd = GETRELDEP(pool, dep);
-      dep = rd->name;
-    }    
-  return dep; 
-}
-
 int
 solver_splitprovides(Solver *solv, Id dep)
 {
@@ -744,7 +734,7 @@ disableupdaterules(Solver *solv, Queue *job, int jobidx)
 {
   Pool *pool = solv->pool;
   int i, j;
-  Id name, how, what, p, *pp;
+  Id how, what, p, *pp;
   Solvable *s;
   Repo *installed;
   Rule *r;
@@ -800,15 +790,9 @@ disableupdaterules(Solver *solv, Queue *job, int jobidx)
          break;
        case SOLVER_ERASE_SOLVABLE_NAME:                  /* remove by capability */
        case SOLVER_ERASE_SOLVABLE_PROVIDES:
-         name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
-         while (ISRELDEP(name))
-           {
-             Reldep *rd = GETRELDEP(pool, name);
-             name = rd->name;
-           }
          FOR_PROVIDES(p, pp, what)
            {
-             if (name && pool->solvables[p].name != name)
+             if (how == SOLVER_ERASE_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
                continue;
              if (pool->solvables[p].repo == installed)
                MAPSET(&solv->noupdate, p - installed->start);
@@ -867,16 +851,10 @@ disableupdaterules(Solver *solv, Queue *job, int jobidx)
          break;
        case SOLVER_ERASE_SOLVABLE_NAME:                  /* remove by capability */
        case SOLVER_ERASE_SOLVABLE_PROVIDES:
-         name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
-         while (ISRELDEP(name))
-           {
-             Reldep *rd = GETRELDEP(pool, name);
-             name = rd->name;
-           }
          FOR_PROVIDES(p, pp, what)
            {
-             if (name && pool->solvables[p].name != name)
-               continue;
+             if (how == SOLVER_ERASE_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
+               continue;
              if (pool->solvables[p].repo != installed)
                continue;
              if (MAPTST(&solv->noupdate, p - installed->start))
@@ -1125,10 +1103,9 @@ addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
              obsp = s->repo->idarraydata + s->obsoletes;
              while ((obs = *obsp++) != 0)
                {
-                 Id obsname = dep2name(pool, obs);
                  FOR_PROVIDES(p, pp, obs)
                    {
-                     if (!solv->obsoleteusesprovides && obsname != pool->solvables[p].name)
+                     if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
                        continue;
                      addrule(solv, -n, -p);
                    }
@@ -2949,12 +2926,11 @@ solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep,
          obsp = s->repo->idarraydata + s->obsoletes;
          while ((obs = *obsp++) != 0)
            {
-             Id obsname = dep2name(pool, obs);
              FOR_PROVIDES(p, pp, obs)
                {
                  if (p != -r->w2)
                    continue;
-                 if (!solv->obsoleteusesprovides && obsname != pool->solvables[p].name)
+                 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
                    continue;
                  *depp = obs;
                  *sourcep = -r->p;
@@ -2968,12 +2944,11 @@ solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep,
          obsp = s2->repo->idarraydata + s2->obsoletes;
          while ((obs = *obsp++) != 0)
            {
-             Id obsname = dep2name(pool, obs);
              FOR_PROVIDES(p, pp, obs)
                {
                  if (p != -r->p)
                    continue;
-                 if (!solv->obsoleteusesprovides && obsname != pool->solvables[p].name)
+                 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
                    continue;
                  *depp = obs;
                  *sourcep = -r->w2;
@@ -3149,14 +3124,13 @@ create_obsolete_index(Solver *solv)
       obsp = s->repo->idarraydata + s->obsoletes;
       while ((obs = *obsp++) != 0)
        {
-         Id obsname = dep2name(pool, obs);
          FOR_PROVIDES(p, pp, obs)
            {
              if (pool->solvables[p].repo != installed)
                continue;
              if (pool->solvables[p].name == s->name)
                continue;
-             if (!solv->obsoleteusesprovides && obsname != pool->solvables[p].name)
+             if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
                continue;
              obsoletes[p - installed->start]++;
            }
@@ -3181,14 +3155,13 @@ create_obsolete_index(Solver *solv)
       obsp = s->repo->idarraydata + s->obsoletes;
       while ((obs = *obsp++) != 0)
        {
-         Id obsname = dep2name(pool, obs);
          FOR_PROVIDES(p, pp, obs)
            {
              if (pool->solvables[p].repo != installed)
                continue;
              if (pool->solvables[p].name == s->name)
                continue;
-             if (!solv->obsoleteusesprovides && obsname != pool->solvables[p].name)
+             if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
                continue;
              p -= installed->start;
              if (obsoletes_data[obsoletes[p]] != i)
@@ -3327,7 +3300,7 @@ solver_solve(Solver *solv, Queue *job)
   int i;
   int oldnrules;
   Map addedmap;                       /* '1' == have rpm-rules for solvable */
-  Id how, what, weak, name, p, *pp, d;
+  Id how, what, weak, p, *pp, d;
   Queue q, redoq;
   Solvable *s;
   int goterase;
@@ -3391,16 +3364,10 @@ solver_solve(Solver *solv, Queue *job)
          break;
        case SOLVER_INSTALL_SOLVABLE_NAME:
        case SOLVER_INSTALL_SOLVABLE_PROVIDES:
-         name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
-         while (ISRELDEP(name))
-           {
-             Reldep *rd = GETRELDEP(pool, name);
-             name = rd->name;
-           }
          FOR_PROVIDES(p, pp, what)
            {
              /* if by name, ensure that the name matches */
-             if (name && pool->solvables[p].name != name)
+             if (how == SOLVER_INSTALL_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
                continue;
              addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
            }
@@ -3578,16 +3545,10 @@ solver_solve(Solver *solv, Queue *job)
          if (how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
            POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall provides %s\n", weak ? "weak " : "", dep2str(pool, what));
          queue_empty(&q);
-         name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
-         while (ISRELDEP(name))
-           {
-             Reldep *rd = GETRELDEP(pool, name);
-             name = rd->name;
-           }
          FOR_PROVIDES(p, pp, what)
            {
               /* if by name, ensure that the name matches */
-             if (name && pool->solvables[p].name != name)
+             if (how == SOLVER_INSTALL_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
                continue;
              queue_push(&q, p);
            }
@@ -3613,16 +3574,10 @@ solver_solve(Solver *solv, Queue *job)
            POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase name %s\n", weak ? "weak " : "", dep2str(pool, what));
          if (how == SOLVER_ERASE_SOLVABLE_PROVIDES)
            POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase provides %s\n", weak ? "weak " : "", dep2str(pool, what));
-         name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
-         while (ISRELDEP(name))
-           {
-             Reldep *rd = GETRELDEP(pool, name);
-             name = rd->name;
-           }
          FOR_PROVIDES(p, pp, what)
            {
              /* if by name, ensure that the name matches */
-             if (name && pool->solvables[p].name != name)
+             if (how == SOLVER_ERASE_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
                continue;
              addrule(solv, -p, 0);  /* add 'remove' rule */
              queue_push(&solv->ruletojob, i);
index 24acd4fa0a3ca9f98a5ec3017edbd05f5f5508de..3c9ec41f22a00e649ed4e8cb9b836e8ac4450d36 100644 (file)
  *
  */
 
-static inline Id dep2name(Pool *pool, Id dep) 
-{
-  while (ISRELDEP(dep))
-    {    
-      Reldep *rd = rd = GETRELDEP(pool, dep);
-      dep = rd->name;
-    }    
-  return dep; 
-}
-
 Id *
 solver_create_decisions_obsoletesmap(Solver *solv)
 {
@@ -99,10 +89,9 @@ solver_create_decisions_obsoletesmap(Solver *solv)
          obsp = s->repo->idarraydata + s->obsoletes;
          while ((obs = *obsp++) != 0)
            {
-             Id obsname = dep2name(pool, obs);
              FOR_PROVIDES(p, pp, obs)
                {
-                 if (!solv->obsoleteusesprovides && obsname != pool->solvables[p].name)
+                 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
                    continue;
                  if (pool->solvables[p].repo == installed && !obsoletesmap[p])
                    {