richardphibel / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone
Blob Blame History Raw
From add2ce925b65532455e3522113bede4f99993638 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= <lhrazky@redhat.com>
Date: Wed, 10 Jul 2019 15:42:19 +0200
Subject: [PATCH 1/5] Query: use the common dep switch branch for CONFLICTS
 when applying

Join the HY_PKG_CONFLICTS switch branch with the rest of the
dependencies and remove the matchtype assert. The assert is done in the
filterRcoReldep() function and the rest is the same.
---
 libdnf/sack/query.cpp | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libdnf/sack/query.cpp b/libdnf/sack/query.cpp
index 122a50df..f044faa6 100644
--- a/libdnf/sack/query.cpp
+++ b/libdnf/sack/query.cpp
@@ -1977,9 +1977,6 @@ Query::Impl::apply()
             case HY_PKG_EMPTY:
                 /* used to set query empty by keeping Map m empty */
                 break;
-            case HY_PKG_CONFLICTS:
-                filterRcoReldep(f, &m);
-                break;
             case HY_PKG_NAME:
                 filterName(f, &m);
                 break;
@@ -2019,12 +2016,12 @@ Query::Impl::apply()
                 assert(f.getMatchType() == _HY_RELDEP);
                 filterProvidesReldep(f, &m);
                 break;
+            case HY_PKG_CONFLICTS:
             case HY_PKG_ENHANCES:
             case HY_PKG_RECOMMENDS:
             case HY_PKG_REQUIRES:
             case HY_PKG_SUGGESTS:
             case HY_PKG_SUPPLEMENTS:
-                assert(f.getMatchType() == _HY_RELDEP);
                 filterRcoReldep(f, &m);
                 break;
             case HY_PKG_REPONAME:
-- 
2.25.4


From 8b06d5b286d165eb8002b6a002d336ab2b72b0b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= <lhrazky@redhat.com>
Date: Thu, 11 Jul 2019 11:54:11 +0200
Subject: [PATCH 2/5] Query: add a dependency by solvable filter
 (RhBug:1534123,1698034)

This allows to filter all dependencies (requires, conflicts, recommends,
etc.) by a list of solvables that match the dependency.

Can be used in the dnf repoquery command instead of a low-level piece of
code which was expanding packages to their provides and then matching the
dependencies as reldeps.

https://bugzilla.redhat.com/show_bug.cgi?id=1534123
https://bugzilla.redhat.com/show_bug.cgi?id=1698034
---
 libdnf/sack/query.cpp | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/libdnf/sack/query.cpp b/libdnf/sack/query.cpp
index f044faa6..d96d5d12 100644
--- a/libdnf/sack/query.cpp
+++ b/libdnf/sack/query.cpp
@@ -280,7 +280,7 @@ valid_filter_num(int keyname, int cmp_type)
 static bool
 valid_filter_pkg(int keyname, int cmp_type)
 {
-    if (!match_type_pkg(keyname))
+    if (!match_type_pkg(keyname) && !match_type_reldep(keyname))
         return false;
     return cmp_type == HY_EQ || cmp_type == HY_NEQ;
 }
@@ -683,6 +683,7 @@ private:
     void filterNevraStrict(int cmpType, const char **matches);
     void initResult();
     void filterPkg(const Filter & f, Map *m);
+    void filterDepSolvable(const Filter & f, Map * m);
     void filterRcoReldep(const Filter & f, Map *m);
     void filterName(const Filter & f, Map *m);
     void filterEpoch(const Filter & f, Map *m);
@@ -1058,6 +1059,30 @@ Query::Impl::filterPkg(const Filter & f, Map *m)
     map_init_clone(m, dnf_packageset_get_map(f.getMatches()[0].pset));
 }
 
+void
+Query::Impl::filterDepSolvable(const Filter & f, Map * m)
+{
+    assert(f.getMatchType() == _HY_PKG);
+    assert(f.getMatches().size() == 1);
+
+    dnf_sack_make_provides_ready(sack);
+    Pool * pool = dnf_sack_get_pool(sack);
+    Id rco_key = reldep_keyname2id(f.getKeyname());
+
+    IdQueue out;
+
+    const auto filter_pset = f.getMatches()[0].pset;
+    Id id = -1;
+    while ((id = filter_pset->next(id)) != -1) {
+        out.clear();
+        pool_whatmatchessolvable(pool, rco_key, id, out.getQueue(), -1);
+
+        for (int j = 0; j < out.size(); ++j) {
+            MAPSET(m, out[j]);
+        }
+    }
+}
+
 void
 Query::Impl::filterRcoReldep(const Filter & f, Map *m)
 {
@@ -2022,7 +2047,11 @@ Query::Impl::apply()
             case HY_PKG_REQUIRES:
             case HY_PKG_SUGGESTS:
             case HY_PKG_SUPPLEMENTS:
-                filterRcoReldep(f, &m);
+                if (f.getMatchType() == _HY_RELDEP)
+                    filterRcoReldep(f, &m);
+                else {
+                    filterDepSolvable(f, &m);
+                }
                 break;
             case HY_PKG_REPONAME:
                 filterReponame(f, &m);
-- 
2.25.4


From 1a62aa8336ab390a1825d052a096b613805b20ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= <lhrazky@redhat.com>
Date: Wed, 21 Aug 2019 16:50:49 +0200
Subject: [PATCH 3/5] Hawkey tests: fix filtering on requires by passing a
 query

Fixes tests after allowing to pass a query (or an iterable of packages)
as an argument to dependency filters (requires, suggests, etc.) in
"Query: add a dependency by solvable filter".

Drops the exception check and adds a simple test for the new
functionality.
---
 python/hawkey/tests/tests/test_query.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/python/hawkey/tests/tests/test_query.py b/python/hawkey/tests/tests/test_query.py
index 1d45f163..3ee009dd 100644
--- a/python/hawkey/tests/tests/test_query.py
+++ b/python/hawkey/tests/tests/test_query.py
@@ -352,12 +352,17 @@ class TestQueryUpdates(base.TestCase):
         q = hawkey.Query(self.sack).filter(name="penny")
         o = hawkey.Query(self.sack)
         self.assertRaises(hawkey.QueryException, o.filter, obsoletes__gt=q)
-        self.assertRaises(hawkey.ValueException, o.filter, requires=q)
 
         o = hawkey.Query(self.sack).filter(obsoletes=q)
         self.assertLength(o, 1)
         self.assertEqual(str(o[0]), "fool-1-5.noarch")
 
+    def test_requires_with_package_list(self):
+        q = hawkey.Query(self.sack).filter(name="fool")
+        o = hawkey.Query(self.sack).filter(requires=q)
+        self.assertLength(o, 1)
+        self.assertEqual(str(o[0]), "walrus-2-6.noarch")
+
     def test_subquery_evaluated(self):
         q = hawkey.Query(self.sack).filter(name="penny")
         self.assertFalse(q.evaluated)
-- 
2.25.4


From d1554451b123c2a83f665d743214ca4d3d0ef3a0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= <lhrazky@redhat.com>
Date: Tue, 14 Jan 2020 13:40:58 +0100
Subject: [PATCH 4/5] Query: Add support for a sequence of packages to
 dependency queries

In addition to supporting a query as an argument to the dependency
filters (which then gets resolved to a list of packages), add support
for passing a sequence of packages directly.
---
 python/hawkey/query-py.cpp              | 16 ++++++++--------
 python/hawkey/tests/tests/test_query.py |  8 +++++++-
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/python/hawkey/query-py.cpp b/python/hawkey/query-py.cpp
index 274b8c3e..5e1d368b 100644
--- a/python/hawkey/query-py.cpp
+++ b/python/hawkey/query-py.cpp
@@ -345,7 +345,13 @@ filter_add(HyQuery query, key_t keyname, int cmp_type, PyObject *match)
     switch (keyname) {
     case HY_PKG:
     case HY_PKG_OBSOLETES:
-    case HY_PKG_OBSOLETES_BY_PRIORITY: {
+    case HY_PKG_OBSOLETES_BY_PRIORITY:
+    case HY_PKG_CONFLICTS:
+    case HY_PKG_REQUIRES:
+    case HY_PKG_ENHANCES:
+    case HY_PKG_RECOMMENDS:
+    case HY_PKG_SUGGESTS:
+    case HY_PKG_SUPPLEMENTS: {
         // It could be a sequence of packages or reldep/strings. Lets try packages first.
         auto pset = pyseq_to_packageset(match, query->getSack());
         if (!pset) {
@@ -372,13 +378,7 @@ filter_add(HyQuery query, key_t keyname, int cmp_type, PyObject *match)
 
         break;
     }
-    case HY_PKG_CONFLICTS:
-    case HY_PKG_PROVIDES:
-    case HY_PKG_REQUIRES:
-    case HY_PKG_ENHANCES:
-    case HY_PKG_RECOMMENDS:
-    case HY_PKG_SUGGESTS:
-    case HY_PKG_SUPPLEMENTS: {
+    case HY_PKG_PROVIDES: {
         auto reldeplist = pyseq_to_reldeplist(match, query->getSack(), cmp_type);
         if (reldeplist == NULL)
             return 1;
diff --git a/python/hawkey/tests/tests/test_query.py b/python/hawkey/tests/tests/test_query.py
index 3ee009dd..ff942e71 100644
--- a/python/hawkey/tests/tests/test_query.py
+++ b/python/hawkey/tests/tests/test_query.py
@@ -357,12 +357,18 @@ class TestQueryUpdates(base.TestCase):
         self.assertLength(o, 1)
         self.assertEqual(str(o[0]), "fool-1-5.noarch")
 
-    def test_requires_with_package_list(self):
+    def test_requires_with_query(self):
         q = hawkey.Query(self.sack).filter(name="fool")
         o = hawkey.Query(self.sack).filter(requires=q)
         self.assertLength(o, 1)
         self.assertEqual(str(o[0]), "walrus-2-6.noarch")
 
+    def test_requires_with_package_list(self):
+        q = hawkey.Query(self.sack).filter(name="fool")
+        o = hawkey.Query(self.sack).filter(requires=q.run())
+        self.assertLength(o, 1)
+        self.assertEqual(str(o[0]), "walrus-2-6.noarch")
+
     def test_subquery_evaluated(self):
         q = hawkey.Query(self.sack).filter(name="penny")
         self.assertFalse(q.evaluated)
-- 
2.25.4


From cbaafb957532dfde13080903503cae4488b0863f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
Date: Tue, 17 Mar 2020 13:11:14 +0100
Subject: [PATCH 5/5] Use libsolv selection for filtering DepSolvables
 (RhBug:1812596)

We cannot use pool_whatmatchessolvable because it considers only
installable solvables, which means source rpms are ignored.

https://bugzilla.redhat.com/show_bug.cgi?id=1812596
---
 libdnf/sack/query.cpp | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/libdnf/sack/query.cpp b/libdnf/sack/query.cpp
index d96d5d12..390703c9 100644
--- a/libdnf/sack/query.cpp
+++ b/libdnf/sack/query.cpp
@@ -29,6 +29,7 @@ extern "C" {
 #include <solv/bitmap.h>
 #include <solv/evr.h>
 #include <solv/solver.h>
+#include <solv/selection.h>
 }
 
 #include "query.hpp"
@@ -1075,9 +1076,22 @@ Query::Impl::filterDepSolvable(const Filter & f, Map * m)
     Id id = -1;
     while ((id = filter_pset->next(id)) != -1) {
         out.clear();
-        pool_whatmatchessolvable(pool, rco_key, id, out.getQueue(), -1);
 
-        for (int j = 0; j < out.size(); ++j) {
+        queue_init(out.getQueue());
+        // queue_push2 because we are creating a selection, which contains pairs
+        // of <flags, Id>, SOLVER_SOOLVABLE_ALL is a special flag which includes
+        // all packages from specified pool, Id is ignored.
+        queue_push2(out.getQueue(), SOLVER_SOLVABLE_ALL, 0);
+
+        int flags = 0;
+        flags |= SELECTION_FILTER | SELECTION_WITH_ALL;
+        selection_make_matchsolvable(pool, out.getQueue(), id, flags, rco_key, 0);
+
+        // Queue from selection_make_matchsolvable is a selection, which means
+        // it conntains pairs <flags, Id>, flags refers to how was the Id
+        // matched, that is not important here, so skip it and iterate just
+        // over the Ids.
+        for (int j = 1; j < out.size(); j += 2) {
             MAPSET(m, out[j]);
         }
     }
-- 
2.25.4