From 8428114608627fe0a08dcf1589931f6db025f0b4 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 21 Aug 2019 22:13:27 +0200 Subject: patterns: Add ?version --- apt-pkg/cachefilter-patterns.cc | 2 ++ apt-pkg/cachefilter-patterns.h | 25 +++++++++++++++++++++++++ doc/apt-patterns.7.xml | 11 +++++++++++ test/integration/test-apt-patterns | 4 ++++ 4 files changed, 42 insertions(+) diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index 42bc2babb..ba341df60 100644 --- a/apt-pkg/cachefilter-patterns.cc +++ b/apt-pkg/cachefilter-patterns.cc @@ -240,6 +240,8 @@ std::unique_ptr PatternParser::aPattern(std::unique_p return std::make_unique(); if (node->matches("?upgradable", 0, 0)) return std::make_unique(file); + if (node->matches("?version", 1, 1)) + return std::make_unique(aWord(node->arguments[0])); if (node->matches("?virtual", 0, 0)) return std::make_unique(); if (node->matches("?x-name-fnmatch", 1, 1)) diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index f13edbbc2..4959b0f14 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -244,6 +244,31 @@ struct PackageIsVirtual : public PackageMatcher return Pkg->VersionList == 0; } }; + +struct VersionAnyMatcher : public Matcher +{ + bool operator()(pkgCache::GrpIterator const &Grp) override { return false; } + bool operator()(pkgCache::VerIterator const &Ver) override = 0; + bool operator()(pkgCache::PkgIterator const &Pkg) override + { + for (auto Ver = Pkg.VersionList(); not Ver.end(); Ver++) + { + if ((*this)(Ver)) + return true; + } + return false; + } +}; + +struct VersionIsVersion : public VersionAnyMatcher +{ + BaseRegexMatcher matcher; + VersionIsVersion(std::string const &pattern) : matcher(pattern) {} + bool operator()(pkgCache::VerIterator const &Ver) override + { + return matcher(Ver.VerStr()); + } +}; } // namespace Patterns } // namespace Internal } // namespace APT diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml index efd4293dc..780d13d2e 100644 --- a/doc/apt-patterns.7.xml +++ b/doc/apt-patterns.7.xml @@ -106,6 +106,17 @@ + + Version patterns + + These patterns select specific versions of a package. + + + ?version(REGEX) + Selects versions where the version string matching the specified regular expression. + + + Examples diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns index 92c76edd1..a78413011 100755 --- a/test/integration/test-apt-patterns +++ b/test/integration/test-apt-patterns @@ -161,6 +161,10 @@ testsuccessequal "Listing... not-obsolete/unstable 2.0 i386 [upgradable from: 1.0] N: There is 1 additional version. Please use the '-a' switch to see it" apt list '?upgradable' +testsuccessequal "Listing... +foreign/unstable 2.0 amd64 +not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?version(2.0)' + testsuccessequal "Package: does-not-exist State: not a real package (virtual) N: Can't select candidate version from package does-not-exist as it has no candidate -- cgit v1.2.3-70-g09d2