diff options
| author | Julian Andres Klode <julian.klode@canonical.com> | 2024-07-16 13:54:11 +0200 |
|---|---|---|
| committer | Julian Andres Klode <julian.klode@canonical.com> | 2024-07-16 13:55:07 +0200 |
| commit | 62573e3ca6b45b0d12b9be8b02da116ce0d91b75 (patch) | |
| tree | 3ee03fc2e484ed0d787d42c46d400bd5401c1ac3 | |
| parent | a8367745eac915281cc2b9fb98813e9225d1e55c (diff) | |
solver3: Refactor Reason.Pkg()/Reason.Ver() use with iterator
More code but nicer to read
| -rw-r--r-- | apt-pkg/solver3.cc | 12 | ||||
| -rw-r--r-- | apt-pkg/solver3.h | 10 |
2 files changed, 16 insertions, 6 deletions
diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc index 67aa68dca..0aec1ecba 100644 --- a/apt-pkg/solver3.cc +++ b/apt-pkg/solver3.cc @@ -202,10 +202,10 @@ void APT::Solver::Work::Dump(pkgCache &cache) if (optional) std::cerr << "Optional "; std::cerr << "Item (" << ssize_t(size <= solutions.size() ? size : -1) << "@" << depth << (upgrade ? "u" : "") << ") "; - if (auto Pkg = reason.Pkg(); Pkg != 0) - std::cerr << pkgCache::PkgIterator(cache, cache.PkgP + Pkg).FullName(); - if (auto Ver = reason.Ver(); Ver != 0) - std::cerr << pkgCache::VerIterator(cache, cache.VerP + Ver).ParentPkg().FullName() << "=" << pkgCache::VerIterator(cache, cache.VerP + Ver).VerStr(); + if (auto Pkg = reason.Pkg(cache); not Pkg.end()) + std::cerr << Pkg.FullName(); + if (auto Ver = reason.Ver(cache); not Ver.end()) + std::cerr << Ver.ParentPkg().FullName() << "=" << Ver.VerStr(); std::cerr << " -> "; for (auto sol : solutions) { @@ -221,7 +221,7 @@ std::string APT::Solver::WhyStr(Reason reason) while (not reason.empty()) { - if (auto Pkg = pkgCache::PkgIterator(cache, cache.PkgP + reason.Pkg()); not Pkg.end()) + if (auto Pkg = reason.Pkg(cache); not Pkg.end()) { if ((*this)[Pkg].decision == Decision::MUSTNOT) out.push_back(std::string("not ") + Pkg.FullName()); @@ -229,7 +229,7 @@ std::string APT::Solver::WhyStr(Reason reason) out.push_back(Pkg.FullName()); reason = (*this)[Pkg].reason; } - if (auto Ver = pkgCache::VerIterator(cache, cache.VerP + reason.Ver()); not Ver.end()) + if (auto Ver = reason.Ver(cache); not Ver.end()) { if ((*this)[Ver].decision == Decision::MUSTNOT) out.push_back(std::string("not ") + Ver.ParentPkg().FullName() + "=" + Ver.VerStr()); diff --git a/apt-pkg/solver3.h b/apt-pkg/solver3.h index d460c95d9..96faaa605 100644 --- a/apt-pkg/solver3.h +++ b/apt-pkg/solver3.h @@ -219,6 +219,16 @@ struct APT::Solver::Reason { return IsVersion ? map_pointer<pkgCache::Version>{(uint32_t)MapPtr} : 0; } + // \brief Return the package iterator if storing a package, or an empty one + pkgCache::PkgIterator Pkg(pkgCache &cache) const + { + return IsVersion ? pkgCache::PkgIterator() : pkgCache::PkgIterator(cache, cache.PkgP + Pkg()); + } + // \brief Return the version iterator if storing a package, or an empty end. + pkgCache::VerIterator Ver(pkgCache &cache) const + { + return IsVersion ? pkgCache::VerIterator(cache, cache.VerP + Ver()) : pkgCache::VerIterator(); + } // \brief Check if there is no reason. bool empty() const { |
