richardphibel / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone

Blame SOURCES/0007-Add-expanding-solvable-provides-for-dependency-matching-RhBug-1819172.patch

1951a4
From add2ce925b65532455e3522113bede4f99993638 Mon Sep 17 00:00:00 2001
1951a4
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= <lhrazky@redhat.com>
1951a4
Date: Wed, 10 Jul 2019 15:42:19 +0200
1951a4
Subject: [PATCH 1/5] Query: use the common dep switch branch for CONFLICTS
1951a4
 when applying
1951a4
1951a4
Join the HY_PKG_CONFLICTS switch branch with the rest of the
1951a4
dependencies and remove the matchtype assert. The assert is done in the
1951a4
filterRcoReldep() function and the rest is the same.
1951a4
---
1951a4
 libdnf/sack/query.cpp | 5 +----
1951a4
 1 file changed, 1 insertion(+), 4 deletions(-)
1951a4
1951a4
diff --git a/libdnf/sack/query.cpp b/libdnf/sack/query.cpp
1951a4
index 122a50df..f044faa6 100644
1951a4
--- a/libdnf/sack/query.cpp
1951a4
+++ b/libdnf/sack/query.cpp
1951a4
@@ -1977,9 +1977,6 @@ Query::Impl::apply()
1951a4
             case HY_PKG_EMPTY:
1951a4
                 /* used to set query empty by keeping Map m empty */
1951a4
                 break;
1951a4
-            case HY_PKG_CONFLICTS:
1951a4
-                filterRcoReldep(f, &m);
1951a4
-                break;
1951a4
             case HY_PKG_NAME:
1951a4
                 filterName(f, &m);
1951a4
                 break;
1951a4
@@ -2019,12 +2016,12 @@ Query::Impl::apply()
1951a4
                 assert(f.getMatchType() == _HY_RELDEP);
1951a4
                 filterProvidesReldep(f, &m);
1951a4
                 break;
1951a4
+            case HY_PKG_CONFLICTS:
1951a4
             case HY_PKG_ENHANCES:
1951a4
             case HY_PKG_RECOMMENDS:
1951a4
             case HY_PKG_REQUIRES:
1951a4
             case HY_PKG_SUGGESTS:
1951a4
             case HY_PKG_SUPPLEMENTS:
1951a4
-                assert(f.getMatchType() == _HY_RELDEP);
1951a4
                 filterRcoReldep(f, &m);
1951a4
                 break;
1951a4
             case HY_PKG_REPONAME:
1951a4
-- 
1951a4
2.25.4
1951a4
1951a4
1951a4
From 8b06d5b286d165eb8002b6a002d336ab2b72b0b2 Mon Sep 17 00:00:00 2001
1951a4
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= <lhrazky@redhat.com>
1951a4
Date: Thu, 11 Jul 2019 11:54:11 +0200
1951a4
Subject: [PATCH 2/5] Query: add a dependency by solvable filter
1951a4
 (RhBug:1534123,1698034)
1951a4
1951a4
This allows to filter all dependencies (requires, conflicts, recommends,
1951a4
etc.) by a list of solvables that match the dependency.
1951a4
1951a4
Can be used in the dnf repoquery command instead of a low-level piece of
1951a4
code which was expanding packages to their provides and then matching the
1951a4
dependencies as reldeps.
1951a4
1951a4
https://bugzilla.redhat.com/show_bug.cgi?id=1534123
1951a4
https://bugzilla.redhat.com/show_bug.cgi?id=1698034
1951a4
---
1951a4
 libdnf/sack/query.cpp | 33 +++++++++++++++++++++++++++++++--
1951a4
 1 file changed, 31 insertions(+), 2 deletions(-)
1951a4
1951a4
diff --git a/libdnf/sack/query.cpp b/libdnf/sack/query.cpp
1951a4
index f044faa6..d96d5d12 100644
1951a4
--- a/libdnf/sack/query.cpp
1951a4
+++ b/libdnf/sack/query.cpp
1951a4
@@ -280,7 +280,7 @@ valid_filter_num(int keyname, int cmp_type)
1951a4
 static bool
1951a4
 valid_filter_pkg(int keyname, int cmp_type)
1951a4
 {
1951a4
-    if (!match_type_pkg(keyname))
1951a4
+    if (!match_type_pkg(keyname) && !match_type_reldep(keyname))
1951a4
         return false;
1951a4
     return cmp_type == HY_EQ || cmp_type == HY_NEQ;
1951a4
 }
1951a4
@@ -683,6 +683,7 @@ private:
1951a4
     void filterNevraStrict(int cmpType, const char **matches);
1951a4
     void initResult();
1951a4
     void filterPkg(const Filter & f, Map *m);
1951a4
+    void filterDepSolvable(const Filter & f, Map * m);
1951a4
     void filterRcoReldep(const Filter & f, Map *m);
1951a4
     void filterName(const Filter & f, Map *m);
1951a4
     void filterEpoch(const Filter & f, Map *m);
1951a4
@@ -1058,6 +1059,30 @@ Query::Impl::filterPkg(const Filter & f, Map *m)
1951a4
     map_init_clone(m, dnf_packageset_get_map(f.getMatches()[0].pset));
1951a4
 }
1951a4
 
1951a4
+void
1951a4
+Query::Impl::filterDepSolvable(const Filter & f, Map * m)
1951a4
+{
1951a4
+    assert(f.getMatchType() == _HY_PKG);
1951a4
+    assert(f.getMatches().size() == 1);
1951a4
+
1951a4
+    dnf_sack_make_provides_ready(sack);
1951a4
+    Pool * pool = dnf_sack_get_pool(sack);
1951a4
+    Id rco_key = reldep_keyname2id(f.getKeyname());
1951a4
+
1951a4
+    IdQueue out;
1951a4
+
1951a4
+    const auto filter_pset = f.getMatches()[0].pset;
1951a4
+    Id id = -1;
1951a4
+    while ((id = filter_pset->next(id)) != -1) {
1951a4
+        out.clear();
1951a4
+        pool_whatmatchessolvable(pool, rco_key, id, out.getQueue(), -1);
1951a4
+
1951a4
+        for (int j = 0; j < out.size(); ++j) {
1951a4
+            MAPSET(m, out[j]);
1951a4
+        }
1951a4
+    }
1951a4
+}
1951a4
+
1951a4
 void
1951a4
 Query::Impl::filterRcoReldep(const Filter & f, Map *m)
1951a4
 {
1951a4
@@ -2022,7 +2047,11 @@ Query::Impl::apply()
1951a4
             case HY_PKG_REQUIRES:
1951a4
             case HY_PKG_SUGGESTS:
1951a4
             case HY_PKG_SUPPLEMENTS:
1951a4
-                filterRcoReldep(f, &m);
1951a4
+                if (f.getMatchType() == _HY_RELDEP)
1951a4
+                    filterRcoReldep(f, &m);
1951a4
+                else {
1951a4
+                    filterDepSolvable(f, &m);
1951a4
+                }
1951a4
                 break;
1951a4
             case HY_PKG_REPONAME:
1951a4
                 filterReponame(f, &m);
1951a4
-- 
1951a4
2.25.4
1951a4
1951a4
1951a4
From 1a62aa8336ab390a1825d052a096b613805b20ca Mon Sep 17 00:00:00 2001
1951a4
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= <lhrazky@redhat.com>
1951a4
Date: Wed, 21 Aug 2019 16:50:49 +0200
1951a4
Subject: [PATCH 3/5] Hawkey tests: fix filtering on requires by passing a
1951a4
 query
1951a4
1951a4
Fixes tests after allowing to pass a query (or an iterable of packages)
1951a4
as an argument to dependency filters (requires, suggests, etc.) in
1951a4
"Query: add a dependency by solvable filter".
1951a4
1951a4
Drops the exception check and adds a simple test for the new
1951a4
functionality.
1951a4
---
1951a4
 python/hawkey/tests/tests/test_query.py | 7 ++++++-
1951a4
 1 file changed, 6 insertions(+), 1 deletion(-)
1951a4
1951a4
diff --git a/python/hawkey/tests/tests/test_query.py b/python/hawkey/tests/tests/test_query.py
1951a4
index 1d45f163..3ee009dd 100644
1951a4
--- a/python/hawkey/tests/tests/test_query.py
1951a4
+++ b/python/hawkey/tests/tests/test_query.py
1951a4
@@ -352,12 +352,17 @@ class TestQueryUpdates(base.TestCase):
1951a4
         q = hawkey.Query(self.sack).filter(name="penny")
1951a4
         o = hawkey.Query(self.sack)
1951a4
         self.assertRaises(hawkey.QueryException, o.filter, obsoletes__gt=q)
1951a4
-        self.assertRaises(hawkey.ValueException, o.filter, requires=q)
1951a4
 
1951a4
         o = hawkey.Query(self.sack).filter(obsoletes=q)
1951a4
         self.assertLength(o, 1)
1951a4
         self.assertEqual(str(o[0]), "fool-1-5.noarch")
1951a4
 
1951a4
+    def test_requires_with_package_list(self):
1951a4
+        q = hawkey.Query(self.sack).filter(name="fool")
1951a4
+        o = hawkey.Query(self.sack).filter(requires=q)
1951a4
+        self.assertLength(o, 1)
1951a4
+        self.assertEqual(str(o[0]), "walrus-2-6.noarch")
1951a4
+
1951a4
     def test_subquery_evaluated(self):
1951a4
         q = hawkey.Query(self.sack).filter(name="penny")
1951a4
         self.assertFalse(q.evaluated)
1951a4
-- 
1951a4
2.25.4
1951a4
1951a4
1951a4
From d1554451b123c2a83f665d743214ca4d3d0ef3a0 Mon Sep 17 00:00:00 2001
1951a4
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= <lhrazky@redhat.com>
1951a4
Date: Tue, 14 Jan 2020 13:40:58 +0100
1951a4
Subject: [PATCH 4/5] Query: Add support for a sequence of packages to
1951a4
 dependency queries
1951a4
1951a4
In addition to supporting a query as an argument to the dependency
1951a4
filters (which then gets resolved to a list of packages), add support
1951a4
for passing a sequence of packages directly.
1951a4
---
1951a4
 python/hawkey/query-py.cpp              | 16 ++++++++--------
1951a4
 python/hawkey/tests/tests/test_query.py |  8 +++++++-
1951a4
 2 files changed, 15 insertions(+), 9 deletions(-)
1951a4
1951a4
diff --git a/python/hawkey/query-py.cpp b/python/hawkey/query-py.cpp
1951a4
index 274b8c3e..5e1d368b 100644
1951a4
--- a/python/hawkey/query-py.cpp
1951a4
+++ b/python/hawkey/query-py.cpp
1951a4
@@ -345,7 +345,13 @@ filter_add(HyQuery query, key_t keyname, int cmp_type, PyObject *match)
1951a4
     switch (keyname) {
1951a4
     case HY_PKG:
1951a4
     case HY_PKG_OBSOLETES:
1951a4
-    case HY_PKG_OBSOLETES_BY_PRIORITY: {
1951a4
+    case HY_PKG_OBSOLETES_BY_PRIORITY:
1951a4
+    case HY_PKG_CONFLICTS:
1951a4
+    case HY_PKG_REQUIRES:
1951a4
+    case HY_PKG_ENHANCES:
1951a4
+    case HY_PKG_RECOMMENDS:
1951a4
+    case HY_PKG_SUGGESTS:
1951a4
+    case HY_PKG_SUPPLEMENTS: {
1951a4
         // It could be a sequence of packages or reldep/strings. Lets try packages first.
1951a4
         auto pset = pyseq_to_packageset(match, query->getSack());
1951a4
         if (!pset) {
1951a4
@@ -372,13 +378,7 @@ filter_add(HyQuery query, key_t keyname, int cmp_type, PyObject *match)
1951a4
 
1951a4
         break;
1951a4
     }
1951a4
-    case HY_PKG_CONFLICTS:
1951a4
-    case HY_PKG_PROVIDES:
1951a4
-    case HY_PKG_REQUIRES:
1951a4
-    case HY_PKG_ENHANCES:
1951a4
-    case HY_PKG_RECOMMENDS:
1951a4
-    case HY_PKG_SUGGESTS:
1951a4
-    case HY_PKG_SUPPLEMENTS: {
1951a4
+    case HY_PKG_PROVIDES: {
1951a4
         auto reldeplist = pyseq_to_reldeplist(match, query->getSack(), cmp_type);
1951a4
         if (reldeplist == NULL)
1951a4
             return 1;
1951a4
diff --git a/python/hawkey/tests/tests/test_query.py b/python/hawkey/tests/tests/test_query.py
1951a4
index 3ee009dd..ff942e71 100644
1951a4
--- a/python/hawkey/tests/tests/test_query.py
1951a4
+++ b/python/hawkey/tests/tests/test_query.py
1951a4
@@ -357,12 +357,18 @@ class TestQueryUpdates(base.TestCase):
1951a4
         self.assertLength(o, 1)
1951a4
         self.assertEqual(str(o[0]), "fool-1-5.noarch")
1951a4
 
1951a4
-    def test_requires_with_package_list(self):
1951a4
+    def test_requires_with_query(self):
1951a4
         q = hawkey.Query(self.sack).filter(name="fool")
1951a4
         o = hawkey.Query(self.sack).filter(requires=q)
1951a4
         self.assertLength(o, 1)
1951a4
         self.assertEqual(str(o[0]), "walrus-2-6.noarch")
1951a4
 
1951a4
+    def test_requires_with_package_list(self):
1951a4
+        q = hawkey.Query(self.sack).filter(name="fool")
1951a4
+        o = hawkey.Query(self.sack).filter(requires=q.run())
1951a4
+        self.assertLength(o, 1)
1951a4
+        self.assertEqual(str(o[0]), "walrus-2-6.noarch")
1951a4
+
1951a4
     def test_subquery_evaluated(self):
1951a4
         q = hawkey.Query(self.sack).filter(name="penny")
1951a4
         self.assertFalse(q.evaluated)
1951a4
-- 
1951a4
2.25.4
1951a4
1951a4
1951a4
From cbaafb957532dfde13080903503cae4488b0863f Mon Sep 17 00:00:00 2001
1951a4
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
1951a4
Date: Tue, 17 Mar 2020 13:11:14 +0100
1951a4
Subject: [PATCH 5/5] Use libsolv selection for filtering DepSolvables
1951a4
 (RhBug:1812596)
1951a4
1951a4
We cannot use pool_whatmatchessolvable because it considers only
1951a4
installable solvables, which means source rpms are ignored.
1951a4
1951a4
https://bugzilla.redhat.com/show_bug.cgi?id=1812596
1951a4
---
1951a4
 libdnf/sack/query.cpp | 18 ++++++++++++++++--
1951a4
 1 file changed, 16 insertions(+), 2 deletions(-)
1951a4
1951a4
diff --git a/libdnf/sack/query.cpp b/libdnf/sack/query.cpp
1951a4
index d96d5d12..390703c9 100644
1951a4
--- a/libdnf/sack/query.cpp
1951a4
+++ b/libdnf/sack/query.cpp
1951a4
@@ -29,6 +29,7 @@ extern "C" {
1951a4
 #include <solv/bitmap.h>
1951a4
 #include <solv/evr.h>
1951a4
 #include <solv/solver.h>
1951a4
+#include <solv/selection.h>
1951a4
 }
1951a4
 
1951a4
 #include "query.hpp"
1951a4
@@ -1075,9 +1076,22 @@ Query::Impl::filterDepSolvable(const Filter & f, Map * m)
1951a4
     Id id = -1;
1951a4
     while ((id = filter_pset->next(id)) != -1) {
1951a4
         out.clear();
1951a4
-        pool_whatmatchessolvable(pool, rco_key, id, out.getQueue(), -1);
1951a4
 
1951a4
-        for (int j = 0; j < out.size(); ++j) {
1951a4
+        queue_init(out.getQueue());
1951a4
+        // queue_push2 because we are creating a selection, which contains pairs
1951a4
+        // of <flags, Id>, SOLVER_SOOLVABLE_ALL is a special flag which includes
1951a4
+        // all packages from specified pool, Id is ignored.
1951a4
+        queue_push2(out.getQueue(), SOLVER_SOLVABLE_ALL, 0);
1951a4
+
1951a4
+        int flags = 0;
1951a4
+        flags |= SELECTION_FILTER | SELECTION_WITH_ALL;
1951a4
+        selection_make_matchsolvable(pool, out.getQueue(), id, flags, rco_key, 0);
1951a4
+
1951a4
+        // Queue from selection_make_matchsolvable is a selection, which means
1951a4
+        // it conntains pairs <flags, Id>, flags refers to how was the Id
1951a4
+        // matched, that is not important here, so skip it and iterate just
1951a4
+        // over the Ids.
1951a4
+        for (int j = 1; j < out.size(); j += 2) {
1951a4
             MAPSET(m, out[j]);
1951a4
         }
1951a4
     }
1951a4
-- 
1951a4
2.25.4
1951a4