Blame SOURCES/0020-cli-commands-history-Fix-history-undo-on-a-Reason-Ch.patch

bc72d2
From fe87499e6745795b1dc6225fa102a1242eb9ffc8 Mon Sep 17 00:00:00 2001
bc72d2
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= <lhrazky@redhat.com>
bc72d2
Date: Thu, 17 Feb 2022 18:46:22 +0100
bc72d2
Subject: [PATCH] cli/commands/history: Fix history undo on a Reason Change
bc72d2
bc72d2
The previous reason needs to be fetched from the history db. It's
bc72d2
inefficient to parse the nevra after it was serialized in a previous
bc72d2
step, but that would need bigger code restructuring.
bc72d2
bc72d2
= changelog =
bc72d2
msg: Fix history undo on a Reason Change
bc72d2
type: bugfix
bc72d2
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2053014
bc72d2
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2010259
bc72d2
---
bc72d2
 dnf.spec                    |  2 +-
bc72d2
 dnf/cli/commands/history.py | 11 +++++++++++
bc72d2
 2 files changed, 12 insertions(+), 1 deletion(-)
bc72d2
bc72d2
diff --git a/dnf.spec b/dnf.spec
bc72d2
index 02c8b577..36c3932e 100644
bc72d2
--- a/dnf.spec
bc72d2
+++ b/dnf.spec
bc72d2
@@ -2,7 +2,7 @@
bc72d2
 %define __cmake_in_source_build 1
bc72d2
 
bc72d2
 # default dependencies
bc72d2
-%global hawkey_version 0.61.1
bc72d2
+%global hawkey_version 0.66.0
bc72d2
 %global libcomps_version 0.1.8
bc72d2
 %global libmodulemd_version 2.9.3
bc72d2
 %global rpm_version 4.14.0
bc72d2
diff --git a/dnf/cli/commands/history.py b/dnf/cli/commands/history.py
bc72d2
index 293d93fc..21d04a1a 100644
bc72d2
--- a/dnf/cli/commands/history.py
bc72d2
+++ b/dnf/cli/commands/history.py
bc72d2
@@ -223,6 +223,7 @@ class HistoryCommand(commands.Command):
bc72d2
             "Reinstall": "Reinstalled",
bc72d2
             "Obsoleted": "Install",
bc72d2
             "Obsolete": "Obsoleted",
bc72d2
+            "Reason Change": "Reason Change",
bc72d2
         }
bc72d2
 
bc72d2
         data = serialize_transaction(trans)
bc72d2
@@ -235,6 +236,16 @@ class HistoryCommand(commands.Command):
bc72d2
                 if ti["action"] == "Install" and ti.get("reason", None) == "clean":
bc72d2
                     ti["reason"] = "dependency"
bc72d2
 
bc72d2
+                if ti["action"] == "Reason Change" and "nevra" in ti:
bc72d2
+                    subj = hawkey.Subject(ti["nevra"])
bc72d2
+                    nevra = subj.get_nevra_possibilities(forms=[hawkey.FORM_NEVRA])[0]
bc72d2
+                    reason = self.output.history.swdb.resolveRPMTransactionItemReason(
bc72d2
+                        nevra.name,
bc72d2
+                        nevra.arch,
bc72d2
+                        trans.tids()[0] - 1
bc72d2
+                    )
bc72d2
+                    ti["reason"] = libdnf.transaction.TransactionItemReasonToString(reason)
bc72d2
+
bc72d2
                 if ti.get("repo_id") == hawkey.SYSTEM_REPO_NAME:
bc72d2
                     # erase repo_id, because it's not possible to perform forward actions from the @System repo
bc72d2
                     ti["repo_id"] = None
bc72d2
-- 
bc72d2
2.35.1
bc72d2