Unify the three rpmdsFooMatchesDep() functions into one
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 13 Sep 2012 09:46:41 +0000 (12:46 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 13 Sep 2012 10:03:38 +0000 (13:03 +0300)
- These all do more or less the same thing, easily handled with a common
  function that takes a couple of more extra parameters. The old variants
  become just wrappers to call the pool-aware rpmdsMatches() with suitable
  arguments.

lib/rpmds.c
lib/rpmds.h

index 2ed3d8d..973490f 100644 (file)
@@ -858,58 +858,56 @@ exit:
     return result;
 }
 
-int rpmdsMatchesDep (const Header h, int ix, const rpmds req, int nopromote)
+int rpmdsMatches(rpmstrPool pool, Header h, int prix,
+                rpmds req, int selfevr, int nopromote)
 {
-    /* Get provides information from header */
-    rpmds provides = rpmdsInit(rpmdsNew(h, RPMTAG_PROVIDENAME, 0));
-    int result = 0;
-
-    rpmdsSetIx(provides,ix);
-    result = rpmdsCompare(provides, req);
-
-    rpmdsFree(provides);
-    return result;
-}
-
-int rpmdsAnyMatchesDep (const Header h, const rpmds req, int nopromote)
-{
-    rpmds provides = NULL;
+    rpmds provides;
+    rpmTagVal tag = RPMTAG_PROVIDENAME;
     int result = 0;
 
     /* Get provides information from header */
-    provides = rpmdsInit(rpmdsNew(h, RPMTAG_PROVIDENAME, 0));
-    if (provides == NULL)
-       goto exit;      /* XXX should never happen */
-
-    (void) rpmdsSetNoPromote(provides, nopromote);
+    if (selfevr)
+       provides = rpmdsThisPool(pool, h, tag, RPMSENSE_EQUAL);
+    else
+       provides = rpmdsNewPool(pool, h, tag, 0);
 
-    while (rpmdsNext(provides) >= 0) {
+    rpmdsSetNoPromote(provides, nopromote);
 
+    /*
+     * For a self-provide and indexed provide, we only need one comparison.
+     * Otherwise loop through the provides until match or end.
+     */
+    if (prix >= 0 || selfevr) {
+       if (prix >= 0)
+           rpmdsSetIx(provides, prix);
        result = rpmdsCompare(provides, req);
-
-       /* If this provide matches the require, we're done. */
-       if (result)
-           break;
+    } else {
+       provides = rpmdsInit(provides);
+       while (rpmdsNext(provides) >= 0) {
+           result = rpmdsCompare(provides, req);
+           /* If this provide matches the require, we're done. */
+           if (result)
+               break;
+       }
     }
 
-exit:
     rpmdsFree(provides);
-
     return result;
 }
 
-int rpmdsNVRMatchesDep(const Header h, const rpmds req, int nopromote)
+int rpmdsMatchesDep (const Header h, int ix, const rpmds req, int nopromote)
 {
-    rpmds pkg;
-    int rc = 1;        /* XXX assume match, names already match here */
+    return rpmdsMatches(NULL, h, ix, req, 0, nopromote);
+}
 
-    /* Get package information from header */
-    pkg = rpmdsThis(h, RPMTAG_PROVIDENAME, RPMSENSE_EQUAL);
-    rpmdsSetNoPromote(pkg, nopromote);
-    rc = rpmdsCompare(pkg, req);
-    rpmdsFree(pkg);
+int rpmdsAnyMatchesDep (const Header h, const rpmds req, int nopromote)
+{
+    return rpmdsMatches(NULL, h, -1, req, 0, nopromote);
+}
 
-    return rc;
+int rpmdsNVRMatchesDep(const Header h, const rpmds req, int nopromote)
+{
+    return rpmdsMatches(NULL, h, -1, req, 1, nopromote);
 }
 
 /**
index 9127e51..750fe37 100644 (file)
@@ -377,6 +377,18 @@ int rpmdsMatchesDep (const Header h, int ix, const rpmds req, int nopromote);
  */
 int rpmdsNVRMatchesDep(const Header h, const rpmds req, int nopromote);
 
+/** \ingroup rpmds
+ * Swiss army knife dependency matching function.
+ * @param pool         string pool (or NULL for private pool)
+ * @param h            header
+ * @param prix         index to provides (or -1 or any)
+ * @param req          dependency set
+ * @param selfevr      only look at package EVR?
+ * @param nopromote    dont promote epoch in comparison?
+ * @return             1 if dependency overlaps, 0 otherwise
+ */
+int rpmdsMatches(rpmstrPool pool, Header h, int prix,
+                rpmds req, int selfevr, int nopromote);
 /**
  * Load rpmlib provides into a dependency set.
  * @retval *dsp                (loaded) depedency set