From 53d18fe48618c9864de021cc5862685faac7c752 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 14 Dec 2020 14:28:35 +0100 Subject: patterns: Add dependency patterns ?depends, ?conflicts, etc. These match the target package, not target versions which is slightly unfortunate but might make sense. Maybe we should add a version that matches Versions instead. --- apt-pkg/cachefilter-patterns.cc | 29 +++++++++++++++++++++++++++++ apt-pkg/cachefilter-patterns.h | 22 ++++++++++++++++++++++ doc/apt-patterns.7.xml | 19 +++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index fded7d92f..4a99635db 100644 --- a/apt-pkg/cachefilter-patterns.cc +++ b/apt-pkg/cachefilter-patterns.cc @@ -28,6 +28,17 @@ static const constexpr struct {"M"_sv, "?automatic"_sv, false}, {"b"_sv, "?broken"_sv, false}, {"c"_sv, "?config-files"_sv, false}, + // FIXME: The words after ~D should be case-insensitive + {"DDepends:"_sv, "?depends"_sv, true}, + {"DPre-Depends:"_sv, "?pre-depends"_sv, true}, + {"DSuggests:"_sv, "?suggests"_sv, true}, + {"DRecommends:"_sv, "?recommends"_sv, true}, + {"DConflicts:"_sv, "?conflicts"_sv, true}, + {"DReplaces:"_sv, "?replaces"_sv, true}, + {"DObsoletes:"_sv, "?obsoletes"_sv, true}, + {"DBreaks:"_sv, "?breaks"_sv, true}, + {"DEnhances:"_sv, "?enhances"_sv, true}, + {"D"_sv, "?depends"_sv, true}, {"E"_sv, "?essential"_sv, false}, {"F"_sv, "?false"_sv, false}, {"g"_sv, "?garbage"_sv, false}, @@ -418,6 +429,24 @@ std::unique_ptr PatternParser::aPattern(std::unique_p return std::make_unique(file); if (node->matches("?config-files", 0, 0)) return std::make_unique(); + if (node->matches("?depends", 1, 1)) + return std::make_unique(aPattern(node->arguments[0])); + if (node->matches("?predepends", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::PreDepends); + if (node->matches("?suggests", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::Suggests); + if (node->matches("?recommends", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::Recommends); + if (node->matches("?conflicts", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::Conflicts); + if (node->matches("?replaces", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::Replaces); + if (node->matches("?obsoletes", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::Obsoletes); + if (node->matches("?breaks", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::DpkgBreaks); + if (node->matches("?enhances", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::Enhances); if (node->matches("?essential", 0, 0)) return std::make_unique(); if (node->matches("?exact-name", 1, 1)) diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index d64bc4ccf..048c7041f 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -295,6 +295,28 @@ struct APT_HIDDEN VersionIsAllVersions : public Matcher } }; +struct APT_HIDDEN VersionDepends : public VersionAnyMatcher +{ + std::unique_ptr base; + pkgCache::Dep::DepType type; + VersionDepends(std::unique_ptr base, pkgCache::Dep::DepType type = pkgCache::Dep::Depends) : base(std::move(base)), type(type) {} + bool operator()(pkgCache::GrpIterator const &) override { return false; } + bool operator()(pkgCache::VerIterator const &Ver) override + { + for (auto D = Ver.DependsList(); not D.end(); D++) + { + if (D.IsImplicit()) + continue; + if (D->Type != type) + continue; + if ((*base)(D.TargetPkg())) + return true; + } + + return false; + } +}; + struct APT_HIDDEN VersionIsAnyVersion : public VersionAnyMatcher { std::unique_ptr base; diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml index 168ba3c59..161d8ded3 100644 --- a/doc/apt-patterns.7.xml +++ b/doc/apt-patterns.7.xml @@ -153,7 +153,23 @@ + Package relationship patterns + These patterns match specific package versions that depend/conflict with some other packages. + + + ?depends(PATTERN)~DPATTERN + ?pre-depends(PATTERN)~DPre-Depends:PATTERN + ?suggests(PATTERN)~DSuggests:PATTERN + ?conflicts(PATTERN)~DConflicts:PATTERN + ?replaces(PATTERN)~DReplaces:PATTERN + ?obsoletes(PATTERN)~DObsoletes:PATTERN + ?breaks(PATTERN)~DBreaks:PATTERN + ?enhances(PATTERN)~DEnhances:PATTERN + Selects packages depending/pre-depending/suggesting/conflicting/etc on/with/ packages matching PATTERN. + + + Examples apt remove ?garbage @@ -206,6 +222,9 @@ Grouping patterns with (...) or writing ?or(A,B) as A|B are not supported. We do not believe that the use of | is that common, and the grouping is not necessary without it. + + Dependency types for ~D and related operators need to be specified in the canonical case. + -- cgit v1.2.3 From 2015e0c5eec5750d4f4094d9689cd680608e714f Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 27 Dec 2020 13:49:20 +0100 Subject: woof --- doc/apt-patterns.7.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml index 161d8ded3..06a60285b 100644 --- a/doc/apt-patterns.7.xml +++ b/doc/apt-patterns.7.xml @@ -165,7 +165,7 @@ ?obsoletes(PATTERN)~DObsoletes:PATTERN ?breaks(PATTERN)~DBreaks:PATTERN ?enhances(PATTERN)~DEnhances:PATTERN - Selects packages depending/pre-depending/suggesting/conflicting/etc on/with/ packages matching PATTERN. + Selects versions depending/pre-depending/suggesting/conflicting/etc on/with/ packages matching PATTERN. -- cgit v1.2.3 From 7bec6d3d7008dcfde1d999776102bf5ab2e86381 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 27 Dec 2020 13:56:22 +0100 Subject: Implement ?reverse-depends/~R and friends This was easy. --- apt-pkg/cachefilter-patterns.cc | 28 ++++++++++++++++++++++++++++ apt-pkg/cachefilter-patterns.h | 21 +++++++++++++++++++++ doc/apt-patterns.7.xml | 8 ++++++++ 3 files changed, 57 insertions(+) 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 PatternParser::aPattern(std::unique_p return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::DpkgBreaks); if (node->matches("?enhances", 1, 1)) return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::Enhances); + if (node->matches("?reverse-depends", 1, 1)) + return std::make_unique(aPattern(node->arguments[0])); + if (node->matches("?reverse-predepends", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::PreDepends); + if (node->matches("?reverse-suggests", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::Suggests); + if (node->matches("?reverse-recommends", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::Recommends); + if (node->matches("?reverse-conflicts", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::Conflicts); + if (node->matches("?reverse-replaces", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::Replaces); + if (node->matches("?reverse-obsoletes", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::Obsoletes); + if (node->matches("?reverse-breaks", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::DpkgBreaks); + if (node->matches("?reverse-enhances", 1, 1)) + return std::make_unique(aPattern(node->arguments[0]), pkgCache::Dep::Enhances); if (node->matches("?essential", 0, 0)) return std::make_unique(); 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 base; + pkgCache::Dep::DepType type; + PackageReverseDepends(std::unique_ptr 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 base; diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml index 06a60285b..0d2e79f88 100644 --- a/doc/apt-patterns.7.xml +++ b/doc/apt-patterns.7.xml @@ -167,6 +167,14 @@ ?enhances(PATTERN)~DEnhances:PATTERN Selects versions depending/pre-depending/suggesting/conflicting/etc on/with/ packages matching PATTERN. + + ?reverse-depType(PATTERN) + ~RDepType:PATTERN + Opposite of ?depends and friends - selects all packages that have reverse-dependencies (versions) matching PATTERN. + depType is one of the dependency types such as depends, so that we don't have to repeat the entire list from the first paragraph here. + + + -- cgit v1.2.3