Blame SOURCES/0001-Revert-leaves-Treat-recommends-as-dependencies.patch

6cb0e3
From 61c94be108ed5b525ab330175523a224b8922b70 Mon Sep 17 00:00:00 2001
6cb0e3
From: Emil Renner Berthing <esmil@mailme.dk>
6cb0e3
Date: Wed, 1 Jun 2022 15:07:27 +0200
6cb0e3
Subject: [PATCH 1/2] Revert "leaves: Treat recommends as dependencies when
6cb0e3
 install_weak_deps=True"
6cb0e3
6cb0e3
This reverts commit 5275fe83fa5a941f994a81a2546ae1d8dc095e96.
6cb0e3
---
6cb0e3
 dnf/plugins/leaves/dnf-command-leaves.c | 60 +++++++++++--------------
6cb0e3
 1 file changed, 27 insertions(+), 33 deletions(-)
6cb0e3
6cb0e3
diff --git a/dnf/plugins/leaves/dnf-command-leaves.c b/dnf/plugins/leaves/dnf-command-leaves.c
6cb0e3
index 7789dfc..f264f65 100644
6cb0e3
--- a/dnf/plugins/leaves/dnf-command-leaves.c
6cb0e3
+++ b/dnf/plugins/leaves/dnf-command-leaves.c
6cb0e3
@@ -80,35 +80,8 @@ gtree_dnf_package_cmp (gconstpointer a, gconstpointer b)
6cb0e3
   return dnf_package_cmp ((DnfPackage *)a, (DnfPackage *)b);
6cb0e3
 }
6cb0e3
 
6cb0e3
-static void
6cb0e3
-add_edges (GHashTable *edges, HyQuery query, GTree *pkg2idx, DnfReldepList *deps)
6cb0e3
-{
6cb0e3
-  const gint ndeps = dnf_reldep_list_count (deps);
6cb0e3
-
6cb0e3
-  // resolve dependencies and add an edge if there is exactly one package satisfying it
6cb0e3
-  for (gint j = 0; j < ndeps; j++)
6cb0e3
-    {
6cb0e3
-      DnfReldep *dep = dnf_reldep_list_index (deps, j);
6cb0e3
-
6cb0e3
-      hy_query_filter_reldep (query, HY_PKG_PROVIDES, dep);
6cb0e3
-      g_autoptr(GPtrArray) ppkgs = hy_query_run (query);
6cb0e3
-      hy_query_clear (query);
6cb0e3
-      dnf_reldep_free (dep);
6cb0e3
-
6cb0e3
-      if (ppkgs->len != 1)
6cb0e3
-        continue;
6cb0e3
-
6cb0e3
-      const DnfPackage *ppkg = g_ptr_array_index (ppkgs, 0);
6cb0e3
-      GTreeNode *node = g_tree_lookup_node (pkg2idx, ppkg);;
6cb0e3
-      g_assert (node);
6cb0e3
-      g_hash_table_insert (edges, g_tree_node_value (node), NULL);
6cb0e3
-    }
6cb0e3
-
6cb0e3
-  dnf_reldep_list_free (deps);
6cb0e3
-}
6cb0e3
-
6cb0e3
 static GPtrArray *
6cb0e3
-build_graph (HyQuery query, const GPtrArray *pkgs, gboolean recommends)
6cb0e3
+build_graph (HyQuery query, const GPtrArray *pkgs)
6cb0e3
 {
6cb0e3
   // create pkg2idx to map DnfPackages to their index in pkgs
6cb0e3
   g_autoptr(GTree) pkg2idx = g_tree_new (gtree_dnf_package_cmp);
6cb0e3
@@ -121,13 +94,34 @@ build_graph (HyQuery query, const GPtrArray *pkgs, gboolean recommends)
6cb0e3
   GPtrArray *graph = g_ptr_array_new_full (pkgs->len, g_free);
6cb0e3
   g_autoptr(GHashTable) edges = g_hash_table_new (g_direct_hash, g_direct_equal);
6cb0e3
 
6cb0e3
+  // for each package resolve its dependencies and add an edge if there is
6cb0e3
+  // exactly one package satisfying it
6cb0e3
   for (guint i = 0; i < pkgs->len; i++)
6cb0e3
     {
6cb0e3
       DnfPackage *pkg = g_ptr_array_index (pkgs, i);
6cb0e3
-      add_edges (edges, query, pkg2idx, dnf_package_get_requires (pkg));
6cb0e3
-      if (recommends)
6cb0e3
-        add_edges (edges, query, pkg2idx, dnf_package_get_recommends (pkg));
6cb0e3
-      g_hash_table_remove (edges, GUINT_TO_POINTER (i)); // remove self-edges
6cb0e3
+      g_autoptr(DnfReldepList) reqs = dnf_package_get_requires (pkg);
6cb0e3
+
6cb0e3
+      const gint nreqs = dnf_reldep_list_count (reqs);
6cb0e3
+      for (gint j = 0; j < nreqs; j++)
6cb0e3
+        {
6cb0e3
+          DnfReldep *req = dnf_reldep_list_index (reqs, j);
6cb0e3
+
6cb0e3
+          hy_query_filter_reldep (query, HY_PKG_PROVIDES, req);
6cb0e3
+          g_autoptr(GPtrArray) ppkgs = hy_query_run (query);
6cb0e3
+          hy_query_clear (query);
6cb0e3
+          dnf_reldep_free (req);
6cb0e3
+
6cb0e3
+          if (ppkgs->len != 1)
6cb0e3
+            continue;
6cb0e3
+
6cb0e3
+          DnfPackage *ppkg = g_ptr_array_index (ppkgs, 0);
6cb0e3
+          GTreeNode *node = g_tree_lookup_node (pkg2idx, ppkg);;
6cb0e3
+          g_assert (node);
6cb0e3
+          guint idx = GPOINTER_TO_UINT (g_tree_node_value (node));
6cb0e3
+          if (idx != i) // don't add self-edges
6cb0e3
+            g_hash_table_insert (edges, GUINT_TO_POINTER (idx), NULL);
6cb0e3
+        }
6cb0e3
+
6cb0e3
       g_ptr_array_add (graph, idx_array_from_set (edges));
6cb0e3
     }
6cb0e3
 
6cb0e3
@@ -341,7 +335,7 @@ dnf_command_leaves_run (DnfCommand      *cmd,
6cb0e3
   g_ptr_array_sort (pkgs, gptrarr_dnf_package_cmp);
6cb0e3
 
6cb0e3
   // build the directed graph of dependencies
6cb0e3
-  g_autoptr(GPtrArray) graph = build_graph (query, pkgs, dnf_context_get_install_weak_deps ());
6cb0e3
+  g_autoptr(GPtrArray) graph = build_graph (query, pkgs);
6cb0e3
 
6cb0e3
   // run Kosaraju's algorithm to find strongly connected components
6cb0e3
   // withhout any incoming edges
6cb0e3
-- 
6cb0e3
2.37.3
6cb0e3