Blame SOURCES/0003-Rename-update-command-to-upgrade-update-remain-as-compatibility-alias-RhBug-1905471.patch

57ce62
From dfb32883ee6e822289716bba82f4301bdf9d3c59 Mon Sep 17 00:00:00 2001
57ce62
From: Jaroslav Rohel <jrohel@redhat.com>
57ce62
Date: Mon, 7 Dec 2020 09:23:36 +0100
57ce62
Subject: [PATCH 1/3] Command "update" renamed to "upgrade"
57ce62
57ce62
Compatibility with DNF.
57ce62
DNF uses "upgrade". "update" is deprecated in DNF and is
57ce62
only supported for compatibility.
57ce62
---
57ce62
 dnf/CMakeLists.txt                            |  8 ++--
57ce62
 dnf/meson.build                               | 12 ++---
57ce62
 .../update/dnf-command-update.gresource.xml   |  6 ---
57ce62
 dnf/plugins/update/update.plugin              |  9 ----
57ce62
 .../dnf-command-upgrade.c}                    | 44 +++++++++----------
57ce62
 .../upgrade/dnf-command-upgrade.gresource.xml |  6 +++
57ce62
 .../dnf-command-upgrade.h}                    |  8 ++--
57ce62
 dnf/plugins/upgrade/upgrade.plugin            |  9 ++++
57ce62
 8 files changed, 51 insertions(+), 51 deletions(-)
57ce62
 delete mode 100644 dnf/plugins/update/dnf-command-update.gresource.xml
57ce62
 delete mode 100644 dnf/plugins/update/update.plugin
57ce62
 rename dnf/plugins/{update/dnf-command-update.c => upgrade/dnf-command-upgrade.c} (69%)
57ce62
 create mode 100644 dnf/plugins/upgrade/dnf-command-upgrade.gresource.xml
57ce62
 rename dnf/plugins/{update/dnf-command-update.h => upgrade/dnf-command-upgrade.h} (74%)
57ce62
 create mode 100644 dnf/plugins/upgrade/upgrade.plugin
57ce62
57ce62
diff --git a/dnf/CMakeLists.txt b/dnf/CMakeLists.txt
57ce62
index 1d640be..7f421f3 100644
57ce62
--- a/dnf/CMakeLists.txt
57ce62
+++ b/dnf/CMakeLists.txt
57ce62
@@ -15,10 +15,10 @@ glib_compile_resources (DNF_COMMAND_REMOVE plugins/remove/dnf-command-remove.gre
57ce62
                         INTERNAL)
57ce62
 list (APPEND DNF_COMMAND_REMOVE "plugins/remove/dnf-command-remove.c")
57ce62
 
57ce62
-glib_compile_resources (DNF_COMMAND_UPDATE plugins/update/dnf-command-update.gresource.xml
57ce62
-                        C_PREFIX dnf_command_update
57ce62
+glib_compile_resources (DNF_COMMAND_UPGRADE plugins/upgrade/dnf-command-upgrade.gresource.xml
57ce62
+                        C_PREFIX dnf_command_upgrade
57ce62
                         INTERNAL)
57ce62
-list (APPEND DNF_COMMAND_UPDATE "plugins/update/dnf-command-update.c")
57ce62
+list (APPEND DNF_COMMAND_UPGRADE "plugins/upgrade/dnf-command-upgrade.c")
57ce62
 
57ce62
 glib_compile_resources (DNF_COMMAND_REPOLIST plugins/repolist/dnf-command-repolist.gresource.xml
57ce62
                         C_PREFIX dnf_command_repolist
57ce62
@@ -56,7 +56,7 @@ add_executable (microdnf dnf-main.c ${DNF_SRCS}
57ce62
                 ${DNF_COMMAND_INSTALL}
57ce62
                 ${DNF_COMMAND_REINSTALL}
57ce62
                 ${DNF_COMMAND_REMOVE}
57ce62
-                ${DNF_COMMAND_UPDATE}
57ce62
+                ${DNF_COMMAND_UPGRADE}
57ce62
                 ${DNF_COMMAND_REPOLIST}
57ce62
                 ${DNF_COMMAND_REPOQUERY}
57ce62
                 ${DNF_COMMAND_CLEAN}
57ce62
diff --git a/dnf/meson.build b/dnf/meson.build
57ce62
index b456202..4d4bd9e 100644
57ce62
--- a/dnf/meson.build
57ce62
+++ b/dnf/meson.build
57ce62
@@ -30,14 +30,14 @@ microdnf_srcs = [
57ce62
   ),
57ce62
   'plugins/remove/dnf-command-remove.c',
57ce62
 
57ce62
-  # update
57ce62
+  # upgrade
57ce62
   gnome.compile_resources(
57ce62
-    'dnf-update',
57ce62
-    'plugins/update/dnf-command-update.gresource.xml',
57ce62
-    c_name : 'dnf_command_update',
57ce62
-    source_dir : 'plugins/update',
57ce62
+    'dnf-upgrade',
57ce62
+    'plugins/upgrade/dnf-command-upgrade.gresource.xml',
57ce62
+    c_name : 'dnf_command_upgrade',
57ce62
+    source_dir : 'plugins/upgrade',
57ce62
   ),
57ce62
-  'plugins/update/dnf-command-update.c',
57ce62
+  'plugins/upgrade/dnf-command-upgrade.c',
57ce62
 
57ce62
   # repolist
57ce62
   gnome.compile_resources(
57ce62
diff --git a/dnf/plugins/update/dnf-command-update.gresource.xml b/dnf/plugins/update/dnf-command-update.gresource.xml
57ce62
deleted file mode 100644
57ce62
index 6168991..0000000
57ce62
--- a/dnf/plugins/update/dnf-command-update.gresource.xml
57ce62
+++ /dev/null
57ce62
@@ -1,6 +0,0 @@
57ce62
-
57ce62
-<gresources>
57ce62
-  <gresource prefix="/org/fedoraproject/dnf/plugins/update">
57ce62
-    <file>update.plugin</file>
57ce62
-  </gresource>
57ce62
-</gresources>
57ce62
diff --git a/dnf/plugins/update/update.plugin b/dnf/plugins/update/update.plugin
57ce62
deleted file mode 100644
57ce62
index a61b911..0000000
57ce62
--- a/dnf/plugins/update/update.plugin
57ce62
+++ /dev/null
57ce62
@@ -1,9 +0,0 @@
57ce62
-[Plugin]
57ce62
-Module = command_update
57ce62
-Embedded = dnf_command_update_register_types
57ce62
-Name = update
57ce62
-Description = Update packages
57ce62
-Authors = Igor Gnatenko <ignatenko@redhat.com>
57ce62
-License = GPL-3.0+
57ce62
-Copyright = Copyright © 2016 Igor Gnatenko
57ce62
-X-Command-Syntax = update [PACKAGE…]
57ce62
diff --git a/dnf/plugins/update/dnf-command-update.c b/dnf/plugins/upgrade/dnf-command-upgrade.c
57ce62
similarity index 69%
57ce62
rename from dnf/plugins/update/dnf-command-update.c
57ce62
rename to dnf/plugins/upgrade/dnf-command-upgrade.c
57ce62
index 45ff797..5dc1c90 100644
57ce62
--- a/dnf/plugins/update/dnf-command-update.c
57ce62
+++ b/dnf/plugins/upgrade/dnf-command-upgrade.c
57ce62
@@ -1,4 +1,4 @@
57ce62
-/* dnf-command-update.c
57ce62
+/* dnf-command-upgrade.c
57ce62
  *
57ce62
  * Copyright © 2016-2017 Igor Gnatenko <ignatenko@redhat.com>
57ce62
  *
57ce62
@@ -16,35 +16,35 @@
57ce62
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
57ce62
  */
57ce62
 
57ce62
-#include "dnf-command-update.h"
57ce62
+#include "dnf-command-upgrade.h"
57ce62
 #include "dnf-utils.h"
57ce62
 
57ce62
-struct _DnfCommandUpdate
57ce62
+struct _DnfCommandUpgrade
57ce62
 {
57ce62
   PeasExtensionBase parent_instance;
57ce62
 };
57ce62
 
57ce62
-static void dnf_command_update_iface_init (DnfCommandInterface *iface);
57ce62
+static void dnf_command_upgrade_iface_init (DnfCommandInterface *iface);
57ce62
 
57ce62
-G_DEFINE_DYNAMIC_TYPE_EXTENDED (DnfCommandUpdate,
57ce62
-                                dnf_command_update,
57ce62
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (DnfCommandUpgrade,
57ce62
+                                dnf_command_upgrade,
57ce62
                                 PEAS_TYPE_EXTENSION_BASE,
57ce62
                                 0,
57ce62
                                 G_IMPLEMENT_INTERFACE (DNF_TYPE_COMMAND,
57ce62
-                                                       dnf_command_update_iface_init))
57ce62
+                                                       dnf_command_upgrade_iface_init))
57ce62
 
57ce62
 static void
57ce62
-dnf_command_update_init (DnfCommandUpdate *self)
57ce62
+dnf_command_upgrade_init (DnfCommandUpgrade *self)
57ce62
 {
57ce62
 }
57ce62
 
57ce62
 static gboolean
57ce62
-dnf_command_update_run (DnfCommand      *cmd,
57ce62
-                        int              argc,
57ce62
-                        char            *argv[],
57ce62
-                        GOptionContext  *opt_ctx,
57ce62
-                        DnfContext      *ctx,
57ce62
-                        GError         **error)
57ce62
+dnf_command_upgrade_run (DnfCommand      *cmd,
57ce62
+                         int              argc,
57ce62
+                         char            *argv[],
57ce62
+                         GOptionContext  *opt_ctx,
57ce62
+                         DnfContext      *ctx,
57ce62
+                         GError         **error)
57ce62
 {
57ce62
   g_auto(GStrv) pkgs = NULL;
57ce62
   const GOptionEntry opts[] = {
57ce62
@@ -63,7 +63,7 @@ dnf_command_update_run (DnfCommand      *cmd,
57ce62
     }
57ce62
   else
57ce62
     {
57ce62
-      /* Update each package */
57ce62
+      /* Upgrade each package */
57ce62
       for (GStrv pkg = pkgs; *pkg != NULL; pkg++)
57ce62
         {
57ce62
           if (!dnf_context_update (ctx, *pkg, error))
57ce62
@@ -89,27 +89,27 @@ dnf_command_update_run (DnfCommand      *cmd,
57ce62
 }
57ce62
 
57ce62
 static void
57ce62
-dnf_command_update_class_init (DnfCommandUpdateClass *klass)
57ce62
+dnf_command_upgrade_class_init (DnfCommandUpgradeClass *klass)
57ce62
 {
57ce62
 }
57ce62
 
57ce62
 static void
57ce62
-dnf_command_update_iface_init (DnfCommandInterface *iface)
57ce62
+dnf_command_upgrade_iface_init (DnfCommandInterface *iface)
57ce62
 {
57ce62
-  iface->run = dnf_command_update_run;
57ce62
+  iface->run = dnf_command_upgrade_run;
57ce62
 }
57ce62
 
57ce62
 static void
57ce62
-dnf_command_update_class_finalize (DnfCommandUpdateClass *klass)
57ce62
+dnf_command_upgrade_class_finalize (DnfCommandUpgradeClass *klass)
57ce62
 {
57ce62
 }
57ce62
 
57ce62
 G_MODULE_EXPORT void
57ce62
-dnf_command_update_register_types (PeasObjectModule *module)
57ce62
+dnf_command_upgrade_register_types (PeasObjectModule *module)
57ce62
 {
57ce62
-  dnf_command_update_register_type (G_TYPE_MODULE (module));
57ce62
+  dnf_command_upgrade_register_type (G_TYPE_MODULE (module));
57ce62
 
57ce62
   peas_object_module_register_extension_type (module,
57ce62
                                               DNF_TYPE_COMMAND,
57ce62
-                                              DNF_TYPE_COMMAND_UPDATE);
57ce62
+                                              DNF_TYPE_COMMAND_UPGRADE);
57ce62
 }
57ce62
diff --git a/dnf/plugins/upgrade/dnf-command-upgrade.gresource.xml b/dnf/plugins/upgrade/dnf-command-upgrade.gresource.xml
57ce62
new file mode 100644
57ce62
index 0000000..97c1ce4
57ce62
--- /dev/null
57ce62
+++ b/dnf/plugins/upgrade/dnf-command-upgrade.gresource.xml
57ce62
@@ -0,0 +1,6 @@
57ce62
+
57ce62
+<gresources>
57ce62
+  <gresource prefix="/org/fedoraproject/dnf/plugins/upgrade">
57ce62
+    <file>upgrade.plugin</file>
57ce62
+  </gresource>
57ce62
+</gresources>
57ce62
diff --git a/dnf/plugins/update/dnf-command-update.h b/dnf/plugins/upgrade/dnf-command-upgrade.h
57ce62
similarity index 74%
57ce62
rename from dnf/plugins/update/dnf-command-update.h
57ce62
rename to dnf/plugins/upgrade/dnf-command-upgrade.h
57ce62
index 58bd228..5c8e976 100644
57ce62
--- a/dnf/plugins/update/dnf-command-update.h
57ce62
+++ b/dnf/plugins/upgrade/dnf-command-upgrade.h
57ce62
@@ -1,4 +1,4 @@
57ce62
-/* dnf-command-update.h
57ce62
+/* dnf-command-upgrade.h
57ce62
  *
57ce62
  * Copyright © 2016 Igor Gnatenko <ignatenko@redhat.com>
57ce62
  *
57ce62
@@ -23,9 +23,9 @@
57ce62
 
57ce62
 G_BEGIN_DECLS
57ce62
 
57ce62
-#define DNF_TYPE_COMMAND_UPDATE dnf_command_update_get_type ()
57ce62
-G_DECLARE_FINAL_TYPE (DnfCommandUpdate, dnf_command_update, DNF, COMMAND_UPDATE, PeasExtensionBase)
57ce62
+#define DNF_TYPE_COMMAND_UPGRADE dnf_command_upgrade_get_type ()
57ce62
+G_DECLARE_FINAL_TYPE (DnfCommandUpgrade, dnf_command_upgrade, DNF, COMMAND_UPGRADE, PeasExtensionBase)
57ce62
 
57ce62
-G_MODULE_EXPORT void dnf_command_update_register_types (PeasObjectModule *module);
57ce62
+G_MODULE_EXPORT void dnf_command_upgrade_register_types (PeasObjectModule *module);
57ce62
 
57ce62
 G_END_DECLS
57ce62
diff --git a/dnf/plugins/upgrade/upgrade.plugin b/dnf/plugins/upgrade/upgrade.plugin
57ce62
new file mode 100644
57ce62
index 0000000..1f2bda2
57ce62
--- /dev/null
57ce62
+++ b/dnf/plugins/upgrade/upgrade.plugin
57ce62
@@ -0,0 +1,9 @@
57ce62
+[Plugin]
57ce62
+Module = command_upgrade
57ce62
+Embedded = dnf_command_upgrade_register_types
57ce62
+Name = upgrade
57ce62
+Description = Upgrade packages
57ce62
+Authors = Igor Gnatenko <ignatenko@redhat.com>
57ce62
+License = GPL-2.0+
57ce62
+Copyright = Copyright © 2016 Igor Gnatenko
57ce62
+X-Command-Syntax = upgrade [PACKAGE…]
57ce62
-- 
57ce62
2.26.2
57ce62
57ce62
57ce62
From 1bdeb23b66b44c4549a19e9c538c30833839156e Mon Sep 17 00:00:00 2001
57ce62
From: Jaroslav Rohel <jrohel@redhat.com>
57ce62
Date: Mon, 7 Dec 2020 12:25:48 +0100
57ce62
Subject: [PATCH 2/3] Add support for command aliases
57ce62
57ce62
Added support for new custom keys to "*.plugin" file:
57ce62
X-Alias-Name - command alias name
57ce62
X-Alias-Description - description of alias
57ce62
57ce62
If both keys are present, then information will be added into help.
57ce62
---
57ce62
 dnf/dnf-main.c | 21 ++++++++++++++++++---
57ce62
 1 file changed, 18 insertions(+), 3 deletions(-)
57ce62
57ce62
diff --git a/dnf/dnf-main.c b/dnf/dnf-main.c
57ce62
index 2ea3d76..0cf634f 100644
57ce62
--- a/dnf/dnf-main.c
57ce62
+++ b/dnf/dnf-main.c
57ce62
@@ -358,6 +358,8 @@ main (int   argc,
57ce62
   g_autoptr(GOptionContext) subcmd_opt_ctx = NULL;
57ce62
   g_autofree gchar *subcmd_opt_param = NULL;
57ce62
   GSList *cmds_with_subcmds = NULL;  /* list of commands with subcommands */
57ce62
+  /* dictionary of aliases for commands */
57ce62
+  g_autoptr(GHashTable) cmds_aliases = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
57ce62
 
57ce62
   setlocale (LC_ALL, "");
57ce62
 
57ce62
@@ -397,6 +399,7 @@ main (int   argc,
57ce62
       if (peas_engine_provides_extension (engine, info, DNF_TYPE_COMMAND))
57ce62
         {
57ce62
           g_autofree gchar *command_name = g_strdup (peas_plugin_info_get_name (info));
57ce62
+          g_autofree gchar *command_alias_name = g_strdup (peas_plugin_info_get_external_data (info, "Alias-Name"));
57ce62
 
57ce62
           /* Plugins with a '_' character in command name implement subcommands.
57ce62
              E.g. the "command_module_enable" plugin implements the "enable" subcommand of the "module" command. */
57ce62
@@ -409,11 +412,21 @@ main (int   argc,
57ce62
                   break;
57ce62
                 }
57ce62
             }
57ce62
+
57ce62
+          /* Add command alias to the dictionary. */
57ce62
+          if (command_alias_name)
57ce62
+              g_hash_table_insert (cmds_aliases, g_strdup (command_alias_name), g_strdup (command_name));
57ce62
+
57ce62
           /*
57ce62
            * At least 2 spaces between the command and its description are needed
57ce62
            * so that help2man formats it correctly.
57ce62
            */
57ce62
           g_string_append_printf (cmd_summary, "\n  %-16s     %s", command_name, peas_plugin_info_get_description (info));
57ce62
+
57ce62
+          /* If command has an alias with a description, add it to the help. */
57ce62
+          const gchar *command_alias_description = peas_plugin_info_get_external_data (info, "Alias-Description");
57ce62
+          if (command_alias_name && command_alias_description)
57ce62
+            g_string_append_printf (cmd_summary, "\n  %-16s     %s", command_alias_name, command_alias_description);
57ce62
         }
57ce62
     }
57ce62
   g_option_context_set_summary (opt_ctx, cmd_summary->str);
57ce62
@@ -552,15 +565,17 @@ main (int   argc,
57ce62
    * Command name (cmd_name) can not contain '_' character. It is reserved for subcomands. */
57ce62
   if (cmd_name != NULL && strchr(cmd_name, '_') == NULL)
57ce62
     {
57ce62
-      with_subcmds = g_slist_find_custom (cmds_with_subcmds, cmd_name, compare_strings) != NULL;
57ce62
-      g_autofree gchar *mod_name = g_strdup_printf ("command_%s", cmd_name);
57ce62
+      const gchar *original_cmd_name = g_hash_table_lookup (cmds_aliases, cmd_name);
57ce62
+      const gchar *search_cmd_name = original_cmd_name ? original_cmd_name : cmd_name;
57ce62
+      with_subcmds = g_slist_find_custom (cmds_with_subcmds, search_cmd_name, compare_strings) != NULL;
57ce62
+      g_autofree gchar *mod_name = g_strdup_printf ("command_%s", search_cmd_name);
57ce62
       plug = peas_engine_get_plugin_info (engine, mod_name);
57ce62
       if (plug == NULL && with_subcmds)
57ce62
         {
57ce62
           subcmd_name = get_command (&argc, argv);
57ce62
           if (subcmd_name != NULL)
57ce62
             {
57ce62
-              g_autofree gchar *submod_name = g_strdup_printf ("command_%s_%s", cmd_name, subcmd_name);
57ce62
+              g_autofree gchar *submod_name = g_strdup_printf ("command_%s_%s", search_cmd_name, subcmd_name);
57ce62
               plug = peas_engine_get_plugin_info (engine, submod_name);
57ce62
             }
57ce62
         }
57ce62
-- 
57ce62
2.26.2
57ce62
57ce62
57ce62
From 74a918e84a2250c02dcf2190f4951eab2a3e3296 Mon Sep 17 00:00:00 2001
57ce62
From: Jaroslav Rohel <jrohel@redhat.com>
57ce62
Date: Mon, 7 Dec 2020 12:30:05 +0100
57ce62
Subject: [PATCH 3/3] Added alias "update" to "upgrade" command
57ce62
57ce62
"Update" is deprecated, but is required for compatibility.
57ce62
---
57ce62
 dnf/plugins/upgrade/upgrade.plugin | 2 ++
57ce62
 1 file changed, 2 insertions(+)
57ce62
57ce62
diff --git a/dnf/plugins/upgrade/upgrade.plugin b/dnf/plugins/upgrade/upgrade.plugin
57ce62
index 1f2bda2..87dd93e 100644
57ce62
--- a/dnf/plugins/upgrade/upgrade.plugin
57ce62
+++ b/dnf/plugins/upgrade/upgrade.plugin
57ce62
@@ -7,3 +7,5 @@ Authors = Igor Gnatenko <ignatenko@redhat.com>
57ce62
 License = GPL-2.0+
57ce62
 Copyright = Copyright © 2016 Igor Gnatenko
57ce62
 X-Command-Syntax = upgrade [PACKAGE…]
57ce62
+X-Alias-Name = update
57ce62
+X-Alias-Description = Compatibility alias for the "upgrade" command
57ce62
-- 
57ce62
2.26.2
57ce62