From 71727c2a761889855b3c1aaf4243649e98032f67 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 29 Oct 2024 14:06:51 +0100 Subject: apt show: Add pinning information for --full Add new fields `APT-Pin`, `APT-Candidate`, and `APT-Release` to the output, same as in EDSP (limited to one release for now). --- apt-private/private-show.cc | 12 ++++++++++++ test/integration/test-apt-cli-show | 3 +++ 2 files changed, 15 insertions(+) diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index 58c5d92c9..3e969ab89 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -221,6 +221,10 @@ static bool DisplayRecordV2(pkgCacheFile &CacheFile, pkgRecords &Recs, /*{{{*/ // Check and load the package list file pkgCache::PkgFileIterator I = Vf.File(); + // Extract the policy object for use later + pkgDepCache::Policy *Policy = CacheFile.GetPolicy(); + if (Policy == nullptr) + return false; // find matching sources.list metaindex pkgSourceList *SrcList = CacheFile.GetSourceList(); pkgIndexFile *Index; @@ -283,6 +287,14 @@ static bool DisplayRecordV2(pkgCacheFile &CacheFile, pkgRecords &Recs, /*{{{*/ if (manual_installed != nullptr) RW.push_back(pkgTagSection::Tag::Rewrite("APT-Manual-Installed", manual_installed)); RW.push_back(pkgTagSection::Tag::Rewrite("APT-Sources", source_index_file)); + if (_config->FindB("APT::Cache::ShowFull", false)) + { + RW.push_back(pkgTagSection::Tag::Rewrite("APT-Pin", std::to_string(Policy->GetPriority(V)))); + if (Policy->GetCandidateVer(V.ParentPkg()) == V) + RW.push_back(pkgTagSection::Tag::Rewrite("APT-Candidate", "yes")); + if (auto Release = I.RelStr(); not I.Flagged(pkgCache::Flag::NotSource) && not Release.empty()) + RW.push_back(pkgTagSection::Tag::Rewrite("APT-Release", Release)); + } FileFd stdoutfd; if (stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false) == false || diff --git a/test/integration/test-apt-cli-show b/test/integration/test-apt-cli-show index 010775d9b..8f9aa036f 100755 --- a/test/integration/test-apt-cli-show +++ b/test/integration/test-apt-cli-show @@ -57,6 +57,9 @@ SHA256: 0000000000000000000000000000000000000000000000000000000000000000 Download-Size: 42 B APT-Manual-Installed: yes APT-Sources: file:$APTARCHIVE unstable/main all Packages +APT-Pin: 500 +APT-Candidate: yes +APT-Release: a=unstable,n=sid,c=main,b=all Description: Some description That has multiple lines " apt show foo --full -- cgit v1.2.3-70-g09d2