Blame SOURCES/0014-Sort-packages-in-transaction-output-by-nevra-RhBug-1773436.patch

878112
From fa6afad083ffc19438603f43d17785f5741505b4 Mon Sep 17 00:00:00 2001
878112
From: Jaroslav Rohel <jrohel@redhat.com>
878112
Date: Mon, 16 Dec 2019 12:52:41 +0100
878112
Subject: [PATCH 1/2] Sort packages in transaction output by nevra
878112
 (RhBug:1773436)
878112
878112
---
878112
 dnf/cli/output.py | 2 +-
878112
 1 file changed, 1 insertion(+), 1 deletion(-)
878112
878112
diff --git a/dnf/cli/output.py b/dnf/cli/output.py
878112
index 2ff41b6255..1d3eb1e94a 100644
878112
--- a/dnf/cli/output.py
878112
+++ b/dnf/cli/output.py
878112
@@ -1147,7 +1147,7 @@ def _add_line(lines, data, a_wid, po, obsoletes=[]):
878112
                 for i in tsi._item.getReplacedBy():
878112
                     replaces.setdefault(i, set()).add(tsi)
878112
 
878112
-            for tsi in pkglist:
878112
+            for tsi in sorted(pkglist, key=lambda x: x.pkg):
878112
                 if tsi.action not in dnf.transaction.FORWARD_ACTIONS + [libdnf.transaction.TransactionItemAction_REMOVE]:
878112
                     continue
878112
 
878112
878112
From 0779b458ca30e895b72bcfb2d513c13b12f605df Mon Sep 17 00:00:00 2001
878112
From: Jaroslav Rohel <jrohel@redhat.com>
878112
Date: Mon, 16 Dec 2019 14:53:00 +0100
878112
Subject: [PATCH 2/2] Sort packages in post transaction output by nevra
878112
878112
---
878112
 dnf/cli/output.py | 20 ++++++++++++++++++--
878112
 1 file changed, 18 insertions(+), 2 deletions(-)
878112
878112
diff --git a/dnf/cli/output.py b/dnf/cli/output.py
878112
index 1d3eb1e94a..5dc0af6f4b 100644
878112
--- a/dnf/cli/output.py
878112
+++ b/dnf/cli/output.py
878112
@@ -23,6 +23,7 @@
878112
 
878112
 from copy import deepcopy
878112
 import fnmatch
878112
+import functools
878112
 import hawkey
878112
 import itertools
878112
 import libdnf.transaction
878112
@@ -1449,11 +1450,26 @@ def _fits_in_cols(msgs, num):
878112
                 col_lens[col] *= -1
878112
             return col_lens
878112
 
878112
+        def _tsi_or_pkg_nevra_cmp(item1, item2):
878112
+            """Compares two transaction items or packages by nevra.
878112
+               Used as a fallback when tsi does not contain package object.
878112
+            """
878112
+            ret = (item1.name > item2.name) - (item1.name < item2.name)
878112
+            if ret != 0:
878112
+                return ret
878112
+            nevra1 = hawkey.NEVRA(name=item1.name, epoch=item1.epoch, version=item1.version,
878112
+                                  release=item1.release, arch=item1.arch)
878112
+            nevra2 = hawkey.NEVRA(name=item2.name, epoch=item2.epoch, version=item2.version,
878112
+                                  release=item2.release, arch=item2.arch)
878112
+            ret = nevra1.evr_cmp(nevra2, self.sack)
878112
+            if ret != 0:
878112
+                return ret
878112
+            return (item1.arch > item2.arch) - (item1.arch < item2.arch)
878112
+
878112
         out = ''
878112
         list_bunch = _make_lists(transaction, self.base._goal)
878112
         skipped_conflicts, skipped_broken = self._skipped_packages(report_problems=False)
878112
         skipped = skipped_conflicts.union(skipped_broken)
878112
-        skipped = sorted(set([str(pkg) for pkg in skipped]))
878112
 
878112
         for (action, tsis) in [(_('Upgraded'), list_bunch.upgraded),
878112
                                (_('Downgraded'), list_bunch.downgraded),
878112
@@ -1471,7 +1487,7 @@ def _fits_in_cols(msgs, num):
878112
                 continue
878112
             msgs = []
878112
             out += '\n%s:\n' % action
878112
-            for tsi in tsis:
878112
+            for tsi in sorted(tsis, key=functools.cmp_to_key(_tsi_or_pkg_nevra_cmp)):
878112
                 msgs.append(str(tsi))
878112
             for num in (8, 7, 6, 5, 4, 3, 2):
878112
                 cols = _fits_in_cols(msgs, num)