Skip to content

Commit

Permalink
Drop replacing lines from the table when they are exact replacements
Browse files Browse the repository at this point in the history
Exclude `replacing` lines from the transaction table output when replacing a single package with the same name.
  • Loading branch information
jan-kolarik committed Jul 4, 2024
1 parent 12c73b2 commit 816f545
Showing 1 changed file with 38 additions and 33 deletions.
71 changes: 38 additions & 33 deletions libdnf5-cli/output/transaction_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>(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<int64_t>(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);
}
}

Expand Down

0 comments on commit 816f545

Please sign in to comment.