Blob Blame History Raw
From 88602163094d654451a9586121aa8ff6fd7c96b0 Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Wed, 23 Oct 2019 13:14:45 +0200
Subject: [PATCH 1/3] Add option best for transactions (RhBug:1679476)

It adds option `--best` plus default is handled from libdnf.conf and
dnf.conf

https://bugzilla.redhat.com/show_bug.cgi?id=1679476
---
 dnf/dnf-main.c                            | 7 ++++++-
 dnf/plugins/install/dnf-command-install.c | 7 ++++++-
 dnf/plugins/update/dnf-command-update.c   | 8 ++++++--
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/dnf/dnf-main.c b/dnf/dnf-main.c
index 693ad7f..0dce9b2 100644
--- a/dnf/dnf-main.c
+++ b/dnf/dnf-main.c
@@ -28,6 +28,7 @@
 
 static gboolean opt_yes = TRUE;
 static gboolean opt_nodocs = FALSE;
+static gboolean opt_best = FALSE;
 static gboolean show_help = FALSE;
 static gboolean dl_pkgs_printed = FALSE;
 static GSList *enable_disable_repos = NULL;
@@ -82,6 +83,7 @@ process_global_option (const gchar  *option_name,
 
 static const GOptionEntry global_opts[] = {
   { "assumeyes", 'y', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_yes, "Does nothing, we always assume yes", NULL },
+  { "best", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_best, "Try the best available package versions in transactions", NULL },
   { "disablerepo", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_CALLBACK, process_global_option, "Disable repository by an id", "ID" },
   { "enablerepo", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_CALLBACK, process_global_option, "Enable repository by an id", "ID" },
   { "nodocs", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_nodocs, "Install packages without docs", NULL },
@@ -283,7 +285,10 @@ main (int   argc,
 
       dnf_transaction_set_flags (txn, flags);
     }
-
+  if (!show_help && opt_best)
+    {
+        dnf_context_set_best(opt_best);
+    }
   /*
    * The first non-option is the command.
    * Get it and remove it from arguments.
diff --git a/dnf/plugins/install/dnf-command-install.c b/dnf/plugins/install/dnf-command-install.c
index ea549da..0b2f5e5 100644
--- a/dnf/plugins/install/dnf-command-install.c
+++ b/dnf/plugins/install/dnf-command-install.c
@@ -73,7 +73,12 @@ dnf_command_install_run (DnfCommand      *cmd,
       if (!dnf_context_install (ctx, *pkg, error))
         return FALSE;
     }
-  if (!dnf_goal_depsolve (dnf_context_get_goal (ctx), DNF_INSTALL, error))
+  DnfGoalActions flags = DNF_INSTALL;
+  if (dnf_context_get_best())
+    {
+      flags |= DNF_FORCE_BEST;
+    }
+  if (!dnf_goal_depsolve (dnf_context_get_goal (ctx), flags, error))
     return FALSE;
   if (!dnf_utils_print_transaction (ctx))
     return TRUE;
diff --git a/dnf/plugins/update/dnf-command-update.c b/dnf/plugins/update/dnf-command-update.c
index 652d902..7bf1334 100644
--- a/dnf/plugins/update/dnf-command-update.c
+++ b/dnf/plugins/update/dnf-command-update.c
@@ -70,8 +70,12 @@ dnf_command_update_run (DnfCommand      *cmd,
             return FALSE;
         }
     }
-
-  if (!dnf_goal_depsolve (dnf_context_get_goal (ctx), 0, error))
+  DnfGoalActions flags = 0;
+  if (dnf_context_get_best())
+    {
+      flags |= DNF_FORCE_BEST;
+    }
+  if (!dnf_goal_depsolve (dnf_context_get_goal (ctx), flags, error))
     return FALSE;
   if (!dnf_utils_print_transaction (ctx))
     return TRUE;
-- 
2.21.0


From 6a4a490d368fc7982264f8ab898e4bd195576b30 Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Wed, 23 Oct 2019 13:15:17 +0200
Subject: [PATCH 2/3] Initialized to use tito.

---
 .tito/packages/.readme | 3 +++
 .tito/tito.props       | 5 +++++
 2 files changed, 8 insertions(+)
 create mode 100644 .tito/packages/.readme
 create mode 100644 .tito/tito.props

diff --git a/.tito/packages/.readme b/.tito/packages/.readme
new file mode 100644
index 0000000..b9411e2
--- /dev/null
+++ b/.tito/packages/.readme
@@ -0,0 +1,3 @@
+the .tito/packages directory contains metadata files
+named after their packages. Each file has the latest tagged
+version and the project's relative directory.
diff --git a/.tito/tito.props b/.tito/tito.props
new file mode 100644
index 0000000..eab3f19
--- /dev/null
+++ b/.tito/tito.props
@@ -0,0 +1,5 @@
+[buildconfig]
+builder = tito.builder.Builder
+tagger = tito.tagger.VersionTagger
+changelog_do_not_remove_cherrypick = 0
+changelog_format = %s (%ae)
-- 
2.21.0


From 4af6a4c76e7bce0ce06188319b0b4c21a235266c Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Wed, 23 Oct 2019 15:07:55 +0200
Subject: [PATCH 3/3] Add option --nobest

It is used to overwrite configuration of best option. It is useful when
best=True is default.
---
 dnf/dnf-main.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/dnf/dnf-main.c b/dnf/dnf-main.c
index 0dce9b2..4f19489 100644
--- a/dnf/dnf-main.c
+++ b/dnf/dnf-main.c
@@ -29,6 +29,7 @@
 static gboolean opt_yes = TRUE;
 static gboolean opt_nodocs = FALSE;
 static gboolean opt_best = FALSE;
+static gboolean opt_nobest = FALSE;
 static gboolean show_help = FALSE;
 static gboolean dl_pkgs_printed = FALSE;
 static GSList *enable_disable_repos = NULL;
@@ -86,6 +87,7 @@ static const GOptionEntry global_opts[] = {
   { "best", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_best, "Try the best available package versions in transactions", NULL },
   { "disablerepo", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_CALLBACK, process_global_option, "Disable repository by an id", "ID" },
   { "enablerepo", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_CALLBACK, process_global_option, "Enable repository by an id", "ID" },
+  { "nobest", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_nobest, "Do not limit the transaction to the best candidates", NULL },
   { "nodocs", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_nodocs, "Install packages without docs", NULL },
   { "releasever", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_CALLBACK, process_global_option, "Override the value of $releasever in config and repo files", "RELEASEVER" },
   { "setopt", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_CALLBACK, process_global_option, "Set transaction flag, like tsflags=nodocs", "FLAG" },
@@ -284,11 +286,23 @@ main (int   argc,
         }
 
       dnf_transaction_set_flags (txn, flags);
+      if (opt_best && opt_nobest)
+        {
+          error = g_error_new_literal(G_OPTION_ERROR,
+                                      G_OPTION_ERROR_BAD_VALUE,
+                                      "Argument --nobest is not allowed with argument --best");
+          goto out;
+        }
+      if (opt_best)
+        {
+          dnf_context_set_best(TRUE);
+        }
+      else if (opt_nobest)
+        {
+          dnf_context_set_best(FALSE);
+        }
     }
-  if (!show_help && opt_best)
-    {
-        dnf_context_set_best(opt_best);
-    }
+
   /*
    * The first non-option is the command.
    * Get it and remove it from arguments.
-- 
2.21.0