From 816f5455cab0c6324262e49116e2a8d9fc1e4f37 Mon Sep 17 00:00:00 2001 From: Jan Kolarik Date: Thu, 4 Jul 2024 08:33:41 +0000 Subject: [PATCH] Drop replacing lines from the table when they are exact replacements Exclude `replacing` lines from the transaction table output when replacing a single package with the same name. --- libdnf5-cli/output/transaction_table.cpp | 71 +++++++++++++----------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/libdnf5-cli/output/transaction_table.cpp b/libdnf5-cli/output/transaction_table.cpp index 0e8306a1b1..65dabd5299 100644 --- a/libdnf5-cli/output/transaction_table.cpp +++ b/libdnf5-cli/output/transaction_table.cpp @@ -312,43 +312,48 @@ TransactionTable::Impl::Impl(ITransaction & transaction) { scols_cell_set_color(scols_line_get_cell(ln_reason, COL_NAME), replaced_color); section.set_last_line(ln_reason); } - for (auto & replaced : tspkg->get_replaces()) { - // highlight incoming packages with epoch/version change - if (tspkg->get_package()->get_epoch() != replaced->get_epoch() || - tspkg->get_package()->get_version() != replaced->get_version()) { - auto cl_evr = scols_line_get_cell(ln, COL_EVR); - scols_cell_set_color(cl_evr, "bold"); - } + auto replacing_same_pkg = + tspkg->get_replaces().size() == 1 && + tspkg->get_package()->get_name() == tspkg->get_replaces().front()->get_name(); + if (!replacing_same_pkg) { + for (auto & replaced : tspkg->get_replaces()) { + // highlight incoming packages with epoch/version change + if (tspkg->get_package()->get_epoch() != replaced->get_epoch() || + tspkg->get_package()->get_version() != replaced->get_version()) { + auto cl_evr = scols_line_get_cell(ln, COL_EVR); + scols_cell_set_color(cl_evr, "bold"); + } - struct libscols_line * ln_replaced = scols_table_new_line(*tb, ln); - // TODO(jmracek) Translate it - std::string name("replacing "); - name.append(replaced->get_name()); - scols_line_set_data(ln_replaced, COL_NAME, (" " + name).c_str()); - scols_line_set_data(ln_replaced, COL_ARCH, replaced->get_arch().c_str()); - scols_line_set_data(ln_replaced, COL_EVR, replaced->get_evr().c_str()); - scols_line_set_data(ln_replaced, COL_REPO, replaced->get_from_repo_id().c_str()); + struct libscols_line * ln_replaced = scols_table_new_line(*tb, ln); + // TODO(jmracek) Translate it + std::string name("replacing "); + name.append(replaced->get_name()); + scols_line_set_data(ln_replaced, COL_NAME, (" " + name).c_str()); + scols_line_set_data(ln_replaced, COL_ARCH, replaced->get_arch().c_str()); + scols_line_set_data(ln_replaced, COL_EVR, replaced->get_evr().c_str()); + scols_line_set_data(ln_replaced, COL_REPO, replaced->get_from_repo_id().c_str()); - auto replaced_size = static_cast(replaced->get_install_size()); - scols_line_set_data( - ln_replaced, COL_SIZE, libdnf5::cli::utils::units::format_size_aligned(replaced_size).c_str()); - auto replaced_color = action_color(libdnf5::transaction::TransactionItemAction::REPLACED); - auto obsoleted_color = "brown"; + auto replaced_size = static_cast(replaced->get_install_size()); + scols_line_set_data( + ln_replaced, COL_SIZE, libdnf5::cli::utils::units::format_size_aligned(replaced_size).c_str()); + auto replaced_color = action_color(libdnf5::transaction::TransactionItemAction::REPLACED); + auto obsoleted_color = "brown"; - scols_cell_set_color(scols_line_get_cell(ln_replaced, COL_EVR), replaced_color); - if (pkg->get_arch() == replaced->get_arch()) { - scols_cell_set_color(scols_line_get_cell(ln_replaced, COL_ARCH), replaced_color); - } else { - scols_cell_set_color(scols_line_get_cell(ln_replaced, COL_ARCH), obsoleted_color); - } - if (pkg->get_name() == replaced->get_name()) { - scols_cell_set_color(scols_line_get_cell(ln_replaced, COL_NAME), replaced_color); - } else { - scols_cell_set_color(scols_line_get_cell(ln_replaced, COL_NAME), obsoleted_color); + scols_cell_set_color(scols_line_get_cell(ln_replaced, COL_EVR), replaced_color); + if (pkg->get_arch() == replaced->get_arch()) { + scols_cell_set_color(scols_line_get_cell(ln_replaced, COL_ARCH), replaced_color); + } else { + scols_cell_set_color(scols_line_get_cell(ln_replaced, COL_ARCH), obsoleted_color); + } + if (pkg->get_name() == replaced->get_name()) { + scols_cell_set_color(scols_line_get_cell(ln_replaced, COL_NAME), replaced_color); + } else { + scols_cell_set_color(scols_line_get_cell(ln_replaced, COL_NAME), obsoleted_color); + } + scols_cell_set_color(scols_line_get_cell(ln_replaced, COL_REPO), replaced_color); + scols_cell_set_color(scols_line_get_cell(ln_replaced, COL_SIZE), replaced_color); + section.set_last_line(ln_replaced); } - scols_cell_set_color(scols_line_get_cell(ln_replaced, COL_REPO), replaced_color); - scols_cell_set_color(scols_line_get_cell(ln_replaced, COL_SIZE), replaced_color); - section.set_last_line(ln_replaced); } }