summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-12-27 13:56:22 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2020-12-27 13:56:22 +0100
commit7bec6d3d7008dcfde1d999776102bf5ab2e86381 (patch)
treef9def1f6b4d248b22c219dcad431315f024d437c /apt-pkg
parent2015e0c5eec5750d4f4094d9689cd680608e714f (diff)
Implement ?reverse-depends/~R and friends
This was easy.
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/cachefilter-patterns.cc28
-rw-r--r--apt-pkg/cachefilter-patterns.h21
2 files changed, 49 insertions, 0 deletions
diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc
index 4a99635db..471e698d6 100644
--- a/apt-pkg/cachefilter-patterns.cc
+++ b/apt-pkg/cachefilter-patterns.cc
@@ -39,6 +39,16 @@ static const constexpr struct
{"DBreaks:"_sv, "?breaks"_sv, true},
{"DEnhances:"_sv, "?enhances"_sv, true},
{"D"_sv, "?depends"_sv, true},
+ {"RDepends:"_sv, "?reverse-depends"_sv, true},
+ {"RPre-Depends:"_sv, "?reverse-pre-depends"_sv, true},
+ {"RSuggests:"_sv, "?reverse-suggests"_sv, true},
+ {"RRecommends:"_sv, "?reverse-recommends"_sv, true},
+ {"RConflicts:"_sv, "?reverse-conflicts"_sv, true},
+ {"RReplaces:"_sv, "?reverse-replaces"_sv, true},
+ {"RObsoletes:"_sv, "?reverse-obsoletes"_sv, true},
+ {"RBreaks:"_sv, "?reverse-breaks"_sv, true},
+ {"REnhances:"_sv, "?reverse-enhances"_sv, true},
+ {"R"_sv, "?reverse-depends"_sv, true},
{"E"_sv, "?essential"_sv, false},
{"F"_sv, "?false"_sv, false},
{"g"_sv, "?garbage"_sv, false},
@@ -447,6 +457,24 @@ std::unique_ptr<APT::CacheFilter::Matcher> PatternParser::aPattern(std::unique_p
return std::make_unique<Patterns::VersionDepends>(aPattern(node->arguments[0]), pkgCache::Dep::DpkgBreaks);
if (node->matches("?enhances", 1, 1))
return std::make_unique<Patterns::VersionDepends>(aPattern(node->arguments[0]), pkgCache::Dep::Enhances);
+ if (node->matches("?reverse-depends", 1, 1))
+ return std::make_unique<Patterns::PackageReverseDepends>(aPattern(node->arguments[0]));
+ if (node->matches("?reverse-predepends", 1, 1))
+ return std::make_unique<Patterns::PackageReverseDepends>(aPattern(node->arguments[0]), pkgCache::Dep::PreDepends);
+ if (node->matches("?reverse-suggests", 1, 1))
+ return std::make_unique<Patterns::PackageReverseDepends>(aPattern(node->arguments[0]), pkgCache::Dep::Suggests);
+ if (node->matches("?reverse-recommends", 1, 1))
+ return std::make_unique<Patterns::PackageReverseDepends>(aPattern(node->arguments[0]), pkgCache::Dep::Recommends);
+ if (node->matches("?reverse-conflicts", 1, 1))
+ return std::make_unique<Patterns::PackageReverseDepends>(aPattern(node->arguments[0]), pkgCache::Dep::Conflicts);
+ if (node->matches("?reverse-replaces", 1, 1))
+ return std::make_unique<Patterns::PackageReverseDepends>(aPattern(node->arguments[0]), pkgCache::Dep::Replaces);
+ if (node->matches("?reverse-obsoletes", 1, 1))
+ return std::make_unique<Patterns::PackageReverseDepends>(aPattern(node->arguments[0]), pkgCache::Dep::Obsoletes);
+ if (node->matches("?reverse-breaks", 1, 1))
+ return std::make_unique<Patterns::PackageReverseDepends>(aPattern(node->arguments[0]), pkgCache::Dep::DpkgBreaks);
+ if (node->matches("?reverse-enhances", 1, 1))
+ return std::make_unique<Patterns::PackageReverseDepends>(aPattern(node->arguments[0]), pkgCache::Dep::Enhances);
if (node->matches("?essential", 0, 0))
return std::make_unique<Patterns::PackageIsEssential>();
if (node->matches("?exact-name", 1, 1))
diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h
index 048c7041f..e0c48dd12 100644
--- a/apt-pkg/cachefilter-patterns.h
+++ b/apt-pkg/cachefilter-patterns.h
@@ -317,6 +317,27 @@ struct APT_HIDDEN VersionDepends : public VersionAnyMatcher
}
};
+struct APT_HIDDEN PackageReverseDepends : public PackageMatcher
+{
+ std::unique_ptr<APT::CacheFilter::Matcher> base;
+ pkgCache::Dep::DepType type;
+ PackageReverseDepends(std::unique_ptr<APT::CacheFilter::Matcher> base, pkgCache::Dep::DepType type = pkgCache::Dep::Depends) : base(std::move(base)), type(type) {}
+ bool operator()(pkgCache::PkgIterator const &Pkg) override
+ {
+ for (auto D = Pkg.RevDependsList(); not D.end(); D++)
+ {
+ if (D.IsImplicit())
+ continue;
+ if (D->Type != type)
+ continue;
+ if ((*base)(D.ParentVer()))
+ return true;
+ }
+
+ return false;
+ }
+};
+
struct APT_HIDDEN VersionIsAnyVersion : public VersionAnyMatcher
{
std::unique_ptr<APT::CacheFilter::Matcher> base;