From d4be59fc2d2984b6119096cd5b32862a40e10e0d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 12:18:28 +0200 Subject: Merging upstream version 2.9.0. Signed-off-by: Daniel Baumann --- apt-private/private-output.cc | 153 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 132 insertions(+), 21 deletions(-) (limited to 'apt-private/private-output.cc') diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 93b9424..bbf5039 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -316,6 +316,83 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ out << output; } /*}}}*/ +// ShowWithColumns - Show a list in the style of ls /*{{{*/ +// --------------------------------------------------------------------- +/* This prints out a vector of strings with the given indent and in as + many columns as will fit the screen width. + + The output looks like: + abiword debootstrap gir1.2-upowerglib-1.0 + abiword-common dh-make google-chrome-beta + abiword-plugin-grammar dmeventd gstreamer1.0-clutter-3.0 + binfmt-support dmsetup hostname + console-setup evolution-data-server iproute2 + console-setup-linux evolution-data-server-common + coreutils ffmpeg + */ +struct columnInfo +{ + bool ValidLen; + size_t LineWidth; + vector RemainingWidths; +}; +void ShowWithColumns(ostream &out, vector const &List, size_t Indent, size_t ScreenWidth) +{ + constexpr size_t MinColumnWidth = 2; + constexpr size_t ColumnSpace = 1; + + size_t const ListSize = List.size(); + size_t const MaxScreenCols = (ScreenWidth - Indent) / + MinColumnWidth; + size_t const MaxNumCols = min(MaxScreenCols, ListSize); + + vector ColumnInfo(MaxNumCols); + for (size_t I = 0; I < MaxNumCols; ++I) { + ColumnInfo[I].ValidLen = true; + ColumnInfo[I].LineWidth = (I + 1) * MinColumnWidth; + ColumnInfo[I].RemainingWidths.resize(I + 1, MinColumnWidth); + } + + for (size_t I = 0; I < ListSize; ++I) { + for (size_t J = 0; J < MaxNumCols; ++J) { + auto& Col = ColumnInfo[J]; + if (!Col.ValidLen) + continue; + + size_t Idx = I / ((ListSize + J) / (J + 1)); + size_t RealColLen = List[I].size() + (Idx == J ? 0 : ColumnSpace); + if (Col.RemainingWidths[Idx] < RealColLen) { + Col.LineWidth += RealColLen - Col.RemainingWidths[Idx]; + Col.RemainingWidths[Idx] = RealColLen; + Col.ValidLen = Col.LineWidth < ScreenWidth; + } + } + } + size_t NumCols = MaxNumCols; + while (NumCols > 1 && !ColumnInfo[NumCols - 1].ValidLen) + --NumCols; + + size_t NumRows = ListSize / NumCols + (ListSize % NumCols != 0); + auto const &LineFormat = ColumnInfo[NumCols - 1]; + for (size_t Row = 0; Row < NumRows; ++Row) { + size_t Col = 0; + size_t I = Row; + out << string(Indent, ' '); + while (true) { + out << List[I]; + + size_t CurLen = List[I].size(); + size_t MaxLen = LineFormat.RemainingWidths[Col++]; + I += NumRows; + if (I >= ListSize) + break; + + out << string(MaxLen - CurLen, ' '); + } + out << endl; + } +} + /*}}}*/ // ShowBroken - Debugging aide /*{{{*/ // --------------------------------------------------------------------- /* This prints out the names of all the packages that are broken along @@ -447,8 +524,10 @@ void ShowBroken(ostream &out, CacheFile &Cache, bool const Now) { if (Cache->BrokenCount() == 0) return; - - out << _("The following packages have unmet dependencies:") << endl; + if (_config->FindI("APT::Output-Version") < 30) + out << _("The following packages have unmet dependencies:") << endl; + else + out << _("Unsatisfied dependencies:") << endl; SortedPackageUniverse Universe(Cache); for (auto const &Pkg: Universe) ShowBrokenPackage(out, &Cache, Pkg, Now); @@ -458,7 +537,10 @@ void ShowBroken(ostream &out, pkgCacheFile &Cache, bool const Now) if (Cache->BrokenCount() == 0) return; - out << _("The following packages have unmet dependencies:") << endl; + if (_config->FindI("APT::Output-Version") < 30) + out << _("The following packages have unmet dependencies:") << endl; + else + out << _("Unsatisfied dependencies:") << endl; APT::PackageUniverse Universe(Cache); for (auto const &Pkg: Universe) ShowBrokenPackage(out, &Cache, Pkg, Now); @@ -468,17 +550,33 @@ void ShowBroken(ostream &out, pkgCacheFile &Cache, bool const Now) void ShowNew(ostream &out,CacheFile &Cache) { SortedPackageUniverse Universe(Cache); - ShowList(out,_("The following NEW packages will be installed:"), Universe, - [&Cache](pkgCache::PkgIterator const &Pkg) { return Cache[Pkg].NewInstall(); }, + if (_config->FindI("APT::Output-Version") < 30) { + ShowList(out,_("The following NEW packages will be installed:"), Universe, + [&Cache](pkgCache::PkgIterator const &Pkg) { return Cache[Pkg].NewInstall(); }, + &PrettyFullName, + CandidateVersion(&Cache), + "APT::Color::Green"); + return; + } + + ShowList(out,_("Installing:"), Universe, + [&Cache](pkgCache::PkgIterator const &Pkg) { return Cache[Pkg].NewInstall() && (Cache[Pkg].Flags & pkgCache::Flag::Auto) == 0; }, + &PrettyFullName, + CandidateVersion(&Cache), + "APT::Color::Green"); + ShowList(out,_("Installing dependencies:"), Universe, + [&Cache](pkgCache::PkgIterator const &Pkg) { return Cache[Pkg].NewInstall() && Cache[Pkg].Flags & pkgCache::Flag::Auto;}, &PrettyFullName, - CandidateVersion(&Cache)); + CandidateVersion(&Cache), + "APT::Color::Green"); } /*}}}*/ // ShowDel - Show packages to delete /*{{{*/ void ShowDel(ostream &out,CacheFile &Cache) { SortedPackageUniverse Universe(Cache); - ShowList(out,_("The following packages will be REMOVED:"), Universe, + auto title = _config->FindI("APT::Output-Version") < 30 ? _("The following packages will be REMOVED:") : _("REMOVING:"); + ShowList(out,title, Universe, [&Cache](pkgCache::PkgIterator const &Pkg) { return Cache[Pkg].Delete(); }, [&Cache](pkgCache::PkgIterator const &Pkg) { @@ -487,14 +585,18 @@ void ShowDel(ostream &out,CacheFile &Cache) str.append("*"); return str; }, - CandidateVersion(&Cache)); + CandidateVersion(&Cache), + "APT::Color::Red"); } /*}}}*/ // ShowPhasing - Show packages kept due to phasing /*{{{*/ void ShowPhasing(ostream &out, CacheFile &Cache, APT::PackageVector const &HeldBackPackages) { SortedPackageUniverse Universe(Cache); - ShowList(out, _("The following upgrades have been deferred due to phasing:"), HeldBackPackages, + auto title = _config->FindI("APT::Output-Version") < 30 + ? _("The following upgrades have been deferred due to phasing:") + : _("Not upgrading yet due to phasing:"); + ShowList(out, title, HeldBackPackages, &AlwaysTrue, &PrettyFullName, CurrentToCandidateVersion(&Cache)); @@ -504,7 +606,8 @@ void ShowPhasing(ostream &out, CacheFile &Cache, APT::PackageVector const &HeldB void ShowKept(ostream &out,CacheFile &Cache, APT::PackageVector const &HeldBackPackages) { SortedPackageUniverse Universe(Cache); - ShowList(out,_("The following packages have been kept back:"), HeldBackPackages, + auto title = _config->FindI("APT::Output-Version") < 30 ? _("The following packages have been kept back:") : _("Not upgrading:"); + ShowList(out, title, HeldBackPackages, &AlwaysTrue, &PrettyFullName, CurrentToCandidateVersion(&Cache)); @@ -514,13 +617,15 @@ void ShowKept(ostream &out,CacheFile &Cache, APT::PackageVector const &HeldBackP void ShowUpgraded(ostream &out,CacheFile &Cache) { SortedPackageUniverse Universe(Cache); - ShowList(out,_("The following packages will be upgraded:"), Universe, + auto title = _config->FindI("APT::Output-Version") < 30 ? _("The following packages will be upgraded:") : _("Upgrading:"); + ShowList(out, title, Universe, [&Cache](pkgCache::PkgIterator const &Pkg) { return Cache[Pkg].Upgrade() == true && Cache[Pkg].NewInstall() == false; }, &PrettyFullName, - CurrentToCandidateVersion(&Cache)); + CurrentToCandidateVersion(&Cache), + "APT::Color::Green"); } /*}}}*/ // ShowDowngraded - Show downgraded packages /*{{{*/ @@ -529,20 +634,23 @@ void ShowUpgraded(ostream &out,CacheFile &Cache) bool ShowDowngraded(ostream &out,CacheFile &Cache) { SortedPackageUniverse Universe(Cache); - return ShowList(out,_("The following packages will be DOWNGRADED:"), Universe, + auto title = _config->FindI("APT::Output-Version") < 30 ? _("The following packages will be DOWNGRADED:") : _("DOWNGRADING:"); + return ShowList(out, title, Universe, [&Cache](pkgCache::PkgIterator const &Pkg) { return Cache[Pkg].Downgrade() == true && Cache[Pkg].NewInstall() == false; }, &PrettyFullName, - CurrentToCandidateVersion(&Cache)); + CurrentToCandidateVersion(&Cache), + "APT::Color::Green"); } /*}}}*/ // ShowHold - Show held but changed packages /*{{{*/ bool ShowHold(ostream &out,CacheFile &Cache) { SortedPackageUniverse Universe(Cache); - return ShowList(out,_("The following held packages will be changed:"), Universe, + auto title = _config->FindI("APT::Output-Version") < 30 ? _("The following held packages will be changed:") : _("Changing held packages:Changing held packages:"); + return ShowList(out, title, Universe, [&Cache](pkgCache::PkgIterator const &Pkg) { return Pkg->SelectedState == pkgCache::State::Hold && @@ -633,6 +741,7 @@ void Stats(ostream &out, pkgDepCache &Dep, APT::PackageVector const &HeldBackPac unsigned long Downgrade = 0; unsigned long Install = 0; unsigned long ReInstall = 0; + auto outVer = _config->FindI("APT::Output-Version"); for (pkgCache::PkgIterator I = Dep.PkgBegin(); I.end() == false; ++I) { if (Dep[I].NewInstall() == true) @@ -649,18 +758,20 @@ void Stats(ostream &out, pkgDepCache &Dep, APT::PackageVector const &HeldBackPac if (Dep[I].Delete() == false && (Dep[I].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall) ReInstall++; } - - ioprintf(out,_("%lu upgraded, %lu newly installed, "), + if (outVer >= 30) + ioprintf(out, _("Summary:\n")); + ioprintf(out,outVer < 30 ? _("%lu upgraded, %lu newly installed, ") : _(" Upgrading: %lu, Installing: %lu, "), Upgrade,Install); if (ReInstall != 0) - ioprintf(out,_("%lu reinstalled, "),ReInstall); + ioprintf(out,outVer < 30 ? _("%lu reinstalled, ") : _("Reinstalling: %lu, "),ReInstall); if (Downgrade != 0) - ioprintf(out,_("%lu downgraded, "),Downgrade); + ioprintf(out,outVer < 30 ? _("%lu downgraded, ") : _("Downgrading: %lu, "),Downgrade); - ioprintf(out,_("%lu to remove and %lu not upgraded.\n"), + ioprintf(out, outVer < 30 ? _("%lu to remove and %lu not upgraded.\n") : _("Removing: %lu, Not Upgrading: %lu\n"), Dep.DelCount(), HeldBackPackages.size()); - + + // FIXME: outVer if (Dep.BadCount() != 0) ioprintf(out,_("%lu not fully installed or removed.\n"), Dep.BadCount()); -- cgit v1.2.3