From 6801e6d2c63d4ff087024fc84a0feb8aef86886b Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 26 Nov 2019 11:34:34 +0100 Subject: patterns: Add ?any-version --- apt-pkg/cachefilter-patterns.cc | 2 ++ apt-pkg/cachefilter-patterns.h | 11 +++++++++++ doc/apt-patterns.7.xml | 11 +++++++++++ test/integration/test-apt-patterns | 14 ++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index 2ba89e5d4..8b8695f71 100644 --- a/apt-pkg/cachefilter-patterns.cc +++ b/apt-pkg/cachefilter-patterns.cc @@ -216,6 +216,8 @@ std::unique_ptr PatternParser::aPattern(std::unique_p return std::make_unique(aWord(node->arguments[0])); if (node->matches("?archive", 1, 1)) return std::make_unique(aWord(node->arguments[0])); + if (node->matches("?any-version", 1, 1)) + return std::make_unique(aPattern(node->arguments[0])); if (node->matches("?automatic", 0, 0)) return std::make_unique(file); if (node->matches("?broken", 0, 0)) diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index 3d1735442..26b42d04b 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -260,6 +260,17 @@ struct VersionAnyMatcher : public Matcher } }; + +struct VersionIsAnyVersion : public VersionAnyMatcher +{ + std::unique_ptr base; + VersionIsAnyVersion(std::unique_ptr base) : base(std::move(base)) {} + bool operator()(pkgCache::VerIterator const &Ver) override + { + return (*base)(Ver); + } +}; + struct VersionIsArchive : public VersionAnyMatcher { BaseRegexMatcher matcher; diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml index 5f0298f17..102ed3901 100644 --- a/doc/apt-patterns.7.xml +++ b/doc/apt-patterns.7.xml @@ -60,6 +60,17 @@ + + Narrowing patterns + + + + ?any-version(PATTERN) + Selects any version where the pattern matches on the version. + For example, while ?and(?version(1),?version(2)) matches a package which has one version containing 1 and one version containing 2, ?any-version(?and(?version(1),?version(2))) restricts the ?and to act on the same version. + + + Package patterns diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns index c0b0c18d0..767fd22b1 100755 --- a/test/integration/test-apt-patterns +++ b/test/integration/test-apt-patterns @@ -104,6 +104,20 @@ testsuccessequal "Listing... automatic1/now 1.0 i386 [installed,local]" apt list '?and(?name(^automatic),?name(1$))' +msgmsg "Narrow and friends" +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 '?and(?version(^1\.0$),?version(^2\.0$))' + +testsuccessequal "Listing..." apt list '?any-version(?and(?version(^1\.0$),?version(^2\.0$)))' + +# XXX FIXME: I guess we do want this to only show version 1.0? +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 '?any-version(?and(?version(^1\.0$),?name(not-obsolete)))' + + + msgmsg "Package patterns" testsuccessequal "Listing... -- cgit v1.2.3-70-g09d2