]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Add pool_whatcontainsdep, selection_make_containsdep, and SELECTION_MATCH_DEPSTR
authorMichael Schroeder <mls@suse.de>
Fri, 22 Apr 2016 13:39:54 +0000 (15:39 +0200)
committerMichael Schroeder <mls@suse.de>
Fri, 22 Apr 2016 13:40:32 +0000 (15:40 +0200)
examples/solv/solv.c
src/libsolv.ver
src/pool.c
src/pool.h
src/selection.c
src/selection.h

index 6840a6ed61ad78d745105be9b54ddf8eb0d81ff3..e0f55c381b1b095dee83cd872429ab22ca0c4ad7 100644 (file)
@@ -236,6 +236,7 @@ main(int argc, char **argv)
   int forcebest = 0;
   char *rootdir = 0;
   char *keyname = 0;
+  int keyname_depstr = 0;
   int debuglevel = 0;
 
   argc--;
@@ -323,7 +324,13 @@ main(int argc, char **argv)
          argc--;
          argv++;
        }
-      if (argc > 2 && !strcmp(argv[1], "--keyname"))
+      else if (argc > 1 && !strcmp(argv[1], "--depstr"))
+       {
+         keyname_depstr = 1;
+         argc--;
+         argv++;
+       }
+      else if (argc > 2 && !strcmp(argv[1], "--keyname"))
        {
          keyname = argv[2];
          argc -= 2;
@@ -529,7 +536,11 @@ main(int argc, char **argv)
       if (!keyname)
         rflags = selection_make(pool, &job2, argv[i], flags);
       else
-        rflags = selection_make_matchdeps(pool, &job2, argv[i], flags, pool_str2id(pool, keyname, 1), 0);
+       {
+         if (keyname_depstr)
+           flags |= SELECTION_MATCH_DEPSTR;
+          rflags = selection_make_matchdeps(pool, &job2, argv[i], flags, pool_str2id(pool, keyname, 1), 0);
+       }
       if (repofilter.count)
        selection_filter(pool, &job2, &repofilter);
       if (archfilter.count)
index cc79704a05b1d770bd329a87551a96f9ddd151c9..531eaa182ddfd90707a72047259e4fab413be5d4 100644 (file)
@@ -120,6 +120,7 @@ SOLV_1.0 {
                pool_trivial_installable_multiversionmap;
                pool_vendor2mask;
                pool_whatmatchesdep;
+               pool_whatcontainsdep;
                queue_alloc_one;
                queue_alloc_one_head;
                queue_delete;
@@ -245,6 +246,7 @@ SOLV_1.0 {
                selection_add;
                selection_filter;
                selection_make;
+               selection_make_containsdep;
                selection_make_matchdeps;
                selection_solvables;
                solv_bin2hex;
index ecc3686ef688ae0809f00d8a431c9cd526815baa..c51c62eca9d43c8263fe70ab807d99cc3fe8d86f 100644 (file)
@@ -1331,8 +1331,11 @@ void
 pool_whatmatchesdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker)
 {
   Id p;
+  Queue qq;
+  int i;
 
   queue_empty(q);
+  queue_init(&qq);
   FOR_POOL_SOLVABLES(p)
     {
       Solvable *s = pool->solvables + p;
@@ -1340,9 +1343,49 @@ pool_whatmatchesdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker)
        continue;
       if (s->repo != pool->installed && !pool_installable(pool, s))
        continue;
-      if (solvable_matchesdep(s, keyname, dep, marker))
-       queue_push(q, p);
+      if (qq.count)
+       queue_empty(&qq);
+      solvable_lookup_deparray(s, keyname, &qq, marker);
+      for (i = 0; i < qq.count; i++)
+       if (pool_match_dep(pool, qq.elements[i], dep))
+         {
+           queue_push(q, p);
+           break;
+         }
+    }
+  queue_free(&qq);
+}
+
+/* check if keyname contains dep, return list of matching packages */
+void
+pool_whatcontainsdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker)
+{
+  Id p;
+  Queue qq;
+  int i;
+
+  queue_empty(q);
+  if (!dep)
+    return;
+  queue_init(&qq);
+  FOR_POOL_SOLVABLES(p)
+    {
+      Solvable *s = pool->solvables + p;
+      if (s->repo->disabled)
+        continue;
+      if (s->repo != pool->installed && !pool_installable(pool, s))
+        continue;
+      if (qq.count)
+        queue_empty(&qq);
+      solvable_lookup_deparray(s, keyname, &qq, marker);
+      for (i = 0; i < qq.count; i++)
+        if (qq.elements[i] == dep)
+          {
+            queue_push(q, p);
+            break;
+          }
     }
+  queue_free(&qq);
 }
 
 /*************************************************************************/
index b9e2ed60cb98b4935032f82efc1fadf9dc212afc..069594b3958386ab0e8ab51bd89a9a5c9c2d84e2 100644 (file)
@@ -347,6 +347,7 @@ static inline Id *pool_whatprovides_ptr(Pool *pool, Id d)
 }
 
 void pool_whatmatchesdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker);
+void pool_whatcontainsdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker);
 
 /* search the pool. the following filters are available:
  *   p     - search just this solvable
index 7d9a918cd67a5af48d984b93222af5c7834ea705..12bc46428197a1084f89722a1ab7eabe7bc3882f 100644 (file)
@@ -867,6 +867,19 @@ selection_make(Pool *pool, Queue *selection, const char *name, int flags)
   return ret;
 }
 
+static inline int
+matchdep_str(const char *pattern, const char *string, int flags)
+{
+  if (flags & SELECTION_GLOB)
+    {
+      int globflags = (flags & SELECTION_NOCASE) != 0 ? FNM_CASEFOLD : 0;
+      return fnmatch(pattern, string, globflags) == 0 ? 1 : 0;
+    }
+  if (flags & SELECTION_NOCASE)
+    return strcasecmp(pattern, string) == 0 ? 1 : 0;
+  return strcmp(pattern, string) == 0 ? 1 : 0;
+}
+
 static int
 matchdep(Pool *pool, Id id, char *rname, int rflags, char *revr, int flags)
 {
@@ -899,14 +912,7 @@ matchdep(Pool *pool, Id id, char *rname, int rflags, char *revr, int flags)
        }
       return 1;
     }
-  if (flags & SELECTION_GLOB)
-    {
-      int globflags = (flags & SELECTION_NOCASE) != 0 ? FNM_CASEFOLD : 0;
-      return fnmatch(rname, pool_id2str(pool, id), globflags) == 0 ? 1 : 0;
-    }
-  if (flags & SELECTION_NOCASE)
-    return strcasecmp(rname, pool_id2str(pool, id)) == 0 ? 1 : 0;
-  return strcmp(rname, pool_id2str(pool, id)) == 0 ? 1 : 0;
+  return matchdep_str(rname, pool_id2str(pool, id), flags);
 }
 
 /*
@@ -924,15 +930,18 @@ selection_make_matchdeps(Pool *pool, Queue *selection, const char *name, int fla
 
   queue_empty(selection);
   rname = solv_strdup(name);
-  if ((r = strpbrk(rname, "<=>")) != 0)
+  if (!(flags & SELECTION_MATCH_DEPSTR))
     {
-      if ((r = splitrel(rname, r, &rflags)) == 0)
+      if ((r = strpbrk(rname, "<=>")) != 0)
        {
-         solv_free(rname);
-         return 0;
+         if ((r = splitrel(rname, r, &rflags)) == 0)
+           {
+             solv_free(rname);
+             return 0;
+           }
        }
     }
-  if ((flags & SELECTION_GLOB) != 0 && !strpbrk(name, "[*?") != 0)
+  if ((flags & SELECTION_GLOB) != 0 && !strpbrk(rname, "[*?") != 0)
     flags &= ~SELECTION_GLOB;
 
   queue_init(&q);
@@ -957,6 +966,12 @@ selection_make_matchdeps(Pool *pool, Queue *selection, const char *name, int fla
       for (i = 0; i < q.count; i++)
        {
          Id id = q.elements[i];
+         if ((flags & SELECTION_MATCH_DEPSTR) != 0)
+           {
+             if (matchdep_str(rname, pool_dep2str(pool, id), flags))
+               break;
+             continue;
+           }
          if (matchdep(pool, id, rname, rflags, r, flags))
            break;
        }
@@ -972,6 +987,50 @@ selection_make_matchdeps(Pool *pool, Queue *selection, const char *name, int fla
   return SELECTION_PROVIDES;
 }
 
+int
+selection_make_containsdep(Pool *pool, Queue *selection, Id dep, int flags, int keyname, int marker)
+{
+  Id p;
+  Queue q;
+
+  queue_empty(selection);
+  if (!dep)
+    return 0;
+  queue_init(&q);
+  FOR_POOL_SOLVABLES(p)
+    {
+      Solvable *s =  pool->solvables + p;
+      int i;
+
+      if (s->repo != pool->installed && !pool_installable(pool, s))
+       {
+         if (!(flags & SELECTION_SOURCE_ONLY) || (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC))
+           continue;
+         if (pool_disabled_solvable(pool, s))
+           continue;
+       }
+      if ((flags & SELECTION_INSTALLED_ONLY) != 0 && s->repo != pool->installed)
+       continue;
+      if ((s->arch == ARCH_SRC || s->arch == ARCH_NOSRC) && !(flags & SELECTION_SOURCE_ONLY) && !(flags & SELECTION_WITH_SOURCE))
+       continue;
+      queue_empty(&q);
+      repo_lookup_deparray(s->repo, p, keyname, &q, marker);
+      for (i = 0; i < q.count; i++)
+       {
+         if (q.elements[i] == dep)
+           break;
+       }
+      if (i < q.count)
+       queue_push2(selection, SOLVER_SOLVABLE | SOLVER_NOAUTOSET, p);
+    }
+  queue_free(&q);
+  if (!selection->count)
+    return 0;
+  if ((flags & SELECTION_FLAT) != 0)
+    selection_flatten(pool, selection);
+  return SELECTION_PROVIDES;
+}
+
 static inline int
 pool_is_kind(Pool *pool, Id name, Id kind)
 {
index fc2b15d7ea251299cbb815d7813d30aca0be242f..29189a351c91637d3246758590b9b8d900a3bfe6 100644 (file)
@@ -33,9 +33,11 @@ extern "C" {
 #define SELECTION_SOURCE_ONLY          (1 << 12)
 #define SELECTION_WITH_SOURCE          (1 << 13)
 #define SELECTION_SKIP_KIND            (1 << 14)
+#define SELECTION_MATCH_DEPSTR         (1 << 15)
 
 extern int  selection_make(Pool *pool, Queue *selection, const char *name, int flags);
 extern int  selection_make_matchdeps(Pool *pool, Queue *selection, const char *name, int flags, int keyname, int marker);
+extern int  selection_make_containsdep(Pool *pool, Queue *selection, Id dep, int flags, int keyname, int marker);
 
 extern void selection_filter(Pool *pool, Queue *sel1, Queue *sel2);
 extern void selection_add(Pool *pool, Queue *sel1, Queue *sel2);