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 --- doc/apt-patterns.7.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'doc') 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 -- cgit v1.2.3-70-g09d2 From 7fa292edbe924923cc689721fe58244ca0a40bcd Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 21 Aug 2019 22:21:30 +0200 Subject: patterns: Add ?source-name and ?source-version --- apt-pkg/cachefilter-patterns.cc | 4 ++++ apt-pkg/cachefilter-patterns.h | 20 ++++++++++++++++++++ doc/apt-patterns.7.xml | 6 ++++++ test/integration/test-apt-patterns | 11 +++++++++-- 4 files changed, 39 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index ba341df60..4414792cf 100644 --- a/apt-pkg/cachefilter-patterns.cc +++ b/apt-pkg/cachefilter-patterns.cc @@ -236,6 +236,10 @@ std::unique_ptr PatternParser::aPattern(std::unique_p return std::make_unique(aPattern(node->arguments[0]).release()); if (node->matches("?obsolete", 0, 0)) return std::make_unique(); + if (node->matches("?source-package", 1, 1)) + return std::make_unique(aWord(node->arguments[0])); + if (node->matches("?source-version", 1, 1)) + return std::make_unique(aWord(node->arguments[0])); if (node->matches("?true", 0, 0)) return std::make_unique(); if (node->matches("?upgradable", 0, 0)) diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index 4959b0f14..46a54cf81 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -260,6 +260,26 @@ struct VersionAnyMatcher : public Matcher } }; +struct VersionIsSourcePackage : public VersionAnyMatcher +{ + BaseRegexMatcher matcher; + VersionIsSourcePackage(std::string const &pattern) : matcher(pattern) {} + bool operator()(pkgCache::VerIterator const &Ver) override + { + return matcher(Ver.SourcePkgName()); + } +}; + +struct VersionIsSourceVersion : public VersionAnyMatcher +{ + BaseRegexMatcher matcher; + VersionIsSourceVersion(std::string const &pattern) : matcher(pattern) {} + bool operator()(pkgCache::VerIterator const &Ver) override + { + return matcher(Ver.SourceVerStr()); + } +}; + struct VersionIsVersion : public VersionAnyMatcher { BaseRegexMatcher matcher; diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml index 780d13d2e..09ebedeab 100644 --- a/doc/apt-patterns.7.xml +++ b/doc/apt-patterns.7.xml @@ -112,6 +112,12 @@ These patterns select specific versions of a package. + ?source-package(REGEX) + Selects versions where the source package name matches the specified regular expression. + + ?source-version(REGEX) + Selects versions where the source package version matches the specified regular expression. + ?version(REGEX) Selects versions where the version string matching the specified regular expression. diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns index a78413011..c030e37ec 100755 --- a/test/integration/test-apt-patterns +++ b/test/integration/test-apt-patterns @@ -10,8 +10,8 @@ insertpackage 'unstable' 'available' 'all' '1.0' insertinstalledpackage 'manual1' 'i386' '1.0' 'Depends: automatic1' insertinstalledpackage 'manual2' 'i386' '1.0' -insertinstalledpackage 'automatic1' 'i386' '1.0' -insertinstalledpackage 'automatic2' 'i386' '1.0' +insertinstalledpackage 'automatic1' 'i386' '1.0' 'Source: automatic (0)' +insertinstalledpackage 'automatic2' 'i386' '1.0' 'Source: automatic (1)' insertinstalledpackage 'essential' 'i386' '1.0' 'Essential: yes' insertinstalledpackage 'conf-only' 'i386' '1.0' '' '' 'deinstall ok config-files' @@ -157,6 +157,13 @@ conf-only/now 1.0 i386 [residual-config] foreign/unstable 2.0 amd64 not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?not(?obsolete)' +testsuccessequal "Listing... +automatic1/now 1.0 i386 [installed,local] +automatic2/now 1.0 i386 [installed,local]" apt list '?source-package(^automatic$)' + +testsuccessequal "Listing... +automatic2/now 1.0 i386 [installed,local]" apt list '?source-version(^1$)' + 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' -- cgit v1.2.3-70-g09d2 From 391c9f20208584bf429c7717047a0637d0d670fb Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 21 Aug 2019 22:31:01 +0200 Subject: patterns: Add ?archive --- apt-pkg/cachefilter-patterns.cc | 2 ++ apt-pkg/cachefilter-patterns.h | 15 +++++++++++++++ doc/apt-patterns.7.xml | 3 +++ test/integration/test-apt-patterns | 5 +++++ 4 files changed, 25 insertions(+) (limited to 'doc') diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index 4414792cf..aeed31263 100644 --- a/apt-pkg/cachefilter-patterns.cc +++ b/apt-pkg/cachefilter-patterns.cc @@ -214,6 +214,8 @@ std::unique_ptr PatternParser::aPattern(std::unique_p if (node->matches("?architecture", 1, 1)) 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("?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 46a54cf81..c92a152d6 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -260,6 +260,21 @@ struct VersionAnyMatcher : public Matcher } }; +struct VersionIsArchive : public VersionAnyMatcher +{ + BaseRegexMatcher matcher; + VersionIsArchive(std::string const &pattern) : matcher(pattern) {} + bool operator()(pkgCache::VerIterator const &Ver) override + { + for (auto VF = Ver.FileList(); not VF.end(); VF++) + { + if (VF.File().Archive() && matcher(VF.File().Archive())) + return true; + } + return false; + } +}; + struct VersionIsSourcePackage : public VersionAnyMatcher { BaseRegexMatcher matcher; diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml index 09ebedeab..fe82ca1b8 100644 --- a/doc/apt-patterns.7.xml +++ b/doc/apt-patterns.7.xml @@ -112,6 +112,9 @@ These patterns select specific versions of a package. + ?archive(REGEX) + Selects versions that come from the archive that matches the specified regular expression. Archive, here, means the values after a= in apt-cache policy. + ?source-package(REGEX) Selects versions where the source package name matches the specified regular expression. diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns index c030e37ec..2fa5d336d 100755 --- a/test/integration/test-apt-patterns +++ b/test/integration/test-apt-patterns @@ -112,6 +112,11 @@ foreign/unstable 2.0 amd64" apt list '?architecture(amd64)' testsuccessequal "Listing..." apt list '?architecture(foreign)' testsuccessequal "Listing..." apt list '?architecture(native)' +testsuccessequal "Listing... +available/unstable 1.0 all +foreign/unstable 2.0 amd64 +not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?archive(^unstable$)' + testsuccessequal "Listing... automatic1/now 1.0 i386 [installed,local] automatic2/now 1.0 i386 [installed,local]" apt list '?automatic' -- cgit v1.2.3-70-g09d2 From 02b0afd5098534eff34a8fa1d44454c7a3e1ff09 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 21 Aug 2019 22:53:25 +0200 Subject: patterns: Add ?origin --- apt-pkg/cachefilter-patterns.cc | 2 ++ apt-pkg/cachefilter-patterns.h | 15 +++++++++++++++ doc/apt-patterns.7.xml | 3 +++ test/integration/test-apt-patterns | 6 ++++++ 4 files changed, 26 insertions(+) (limited to 'doc') diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index aeed31263..2ba89e5d4 100644 --- a/apt-pkg/cachefilter-patterns.cc +++ b/apt-pkg/cachefilter-patterns.cc @@ -238,6 +238,8 @@ std::unique_ptr PatternParser::aPattern(std::unique_p return std::make_unique(aPattern(node->arguments[0]).release()); if (node->matches("?obsolete", 0, 0)) return std::make_unique(); + if (node->matches("?origin", 1, 1)) + return std::make_unique(aWord(node->arguments[0])); if (node->matches("?source-package", 1, 1)) return std::make_unique(aWord(node->arguments[0])); if (node->matches("?source-version", 1, 1)) diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index c92a152d6..3d1735442 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -275,6 +275,21 @@ struct VersionIsArchive : public VersionAnyMatcher } }; +struct VersionIsOrigin : public VersionAnyMatcher +{ + BaseRegexMatcher matcher; + VersionIsOrigin(std::string const &pattern) : matcher(pattern) {} + bool operator()(pkgCache::VerIterator const &Ver) override + { + for (auto VF = Ver.FileList(); not VF.end(); VF++) + { + if (VF.File().Origin() && matcher(VF.File().Origin())) + return true; + } + return false; + } +}; + struct VersionIsSourcePackage : public VersionAnyMatcher { BaseRegexMatcher matcher; diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml index fe82ca1b8..5f0298f17 100644 --- a/doc/apt-patterns.7.xml +++ b/doc/apt-patterns.7.xml @@ -115,6 +115,9 @@ ?archive(REGEX) Selects versions that come from the archive that matches the specified regular expression. Archive, here, means the values after a= in apt-cache policy. + ?origin(REGEX) + Selects versions that come from the origin that matches the specified regular expression. Origin, here, means the values after o= in apt-cache policy. + ?source-package(REGEX) Selects versions where the source package name matches the specified regular expression. diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns index 2fa5d336d..c0b0c18d0 100755 --- a/test/integration/test-apt-patterns +++ b/test/integration/test-apt-patterns @@ -22,6 +22,7 @@ insertpackage 'unstable' 'not-obsolete' 'all' '2.0' insertpackage 'unstable' 'foreign' 'amd64' '2.0' +getoriginfromsuite() { echo -n 'meow'; } setupaptarchive testsuccess aptmark auto automatic1 automatic2 @@ -162,6 +163,11 @@ conf-only/now 1.0 i386 [residual-config] foreign/unstable 2.0 amd64 not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?not(?obsolete)' +testsuccessequal "Listing... +available/unstable 1.0 all +foreign/unstable 2.0 amd64 +not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?origin(^meow$)' + testsuccessequal "Listing... automatic1/now 1.0 i386 [installed,local] automatic2/now 1.0 i386 [installed,local]" apt list '?source-package(^automatic$)' -- cgit v1.2.3-70-g09d2 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(+) (limited to 'doc') 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 From 94b185bb738e063bcc387e31b39dcd041f283766 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 26 Nov 2019 11:45:44 +0100 Subject: patterns: Implement ?narrow(...), as ?any-version(?and(...)) This is pure syntactic sugar - ?narrow does not exist in the abstract syntax. --- apt-pkg/cachefilter-patterns.cc | 4 +++- doc/apt-patterns.7.xml | 6 ++++++ test/integration/test-apt-patterns | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'doc') diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index 8b8695f71..f202df796 100644 --- a/apt-pkg/cachefilter-patterns.cc +++ b/apt-pkg/cachefilter-patterns.cc @@ -258,11 +258,13 @@ std::unique_ptr PatternParser::aPattern(std::unique_p return std::make_unique(aWord(node->arguments[0])); // Variable argument patterns - if (node->matches("?and", 0, -1)) + if (node->matches("?and", 0, -1) || node->matches("?narrow", 0, -1)) { auto pattern = std::make_unique(); for (auto &arg : node->arguments) pattern->AND(aPattern(arg).release()); + if (node->term == "?narrow") + return std::make_unique(std::move(pattern)); return pattern; } if (node->matches("?or", 0, -1)) diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml index 102ed3901..c2549f620 100644 --- a/doc/apt-patterns.7.xml +++ b/doc/apt-patterns.7.xml @@ -69,6 +69,9 @@ 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. + ?narrow(PATTERN...) + Selects any version matching all PATTERNs, short for?any-version(?and(PATTERN...)). + @@ -181,6 +184,9 @@ A trailing comma is allowed in argument lists + + ?narrow accepts infinite arguments + diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns index 767fd22b1..291aad1d4 100755 --- a/test/integration/test-apt-patterns +++ b/test/integration/test-apt-patterns @@ -110,11 +110,15 @@ 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$)))' +testsuccessequal "Listing..." apt list '?narrow(?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)))' +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 '?narrow(?version(^1\.0$),?name(not-obsolete))' -- cgit v1.2.3-70-g09d2 From 96f795bce665a1907b885bd2d57d6ab22b0a4199 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 26 Nov 2019 11:56:28 +0100 Subject: patterns: Add ?all-versions --- apt-pkg/cachefilter-patterns.cc | 2 ++ apt-pkg/cachefilter-patterns.h | 19 +++++++++++++++++++ doc/apt-patterns.7.xml | 3 +++ test/integration/test-apt-patterns | 3 +++ 4 files changed, 27 insertions(+) (limited to 'doc') diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index f202df796..8214c388a 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("?all-versions", 1, 1)) + return std::make_unique(aPattern(node->arguments[0])); if (node->matches("?any-version", 1, 1)) return std::make_unique(aPattern(node->arguments[0])); if (node->matches("?automatic", 0, 0)) diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index 26b42d04b..8c5561c82 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -260,6 +260,25 @@ struct VersionAnyMatcher : public Matcher } }; +struct VersionIsAllVersions : public Matcher +{ + std::unique_ptr base; + VersionIsAllVersions(std::unique_ptr base) : base(std::move(base)) {} + bool operator()(pkgCache::GrpIterator const &) override { return false; } + bool operator()(pkgCache::VerIterator const &Ver) override + { + return (*base)(Ver); + } + bool operator()(pkgCache::PkgIterator const &Pkg) override + { + for (auto Ver = Pkg.VersionList(); not Ver.end(); Ver++) + { + if (not(*this)(Ver)) + return false; + } + return true; + } +}; struct VersionIsAnyVersion : public VersionAnyMatcher { diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml index c2549f620..04f97e878 100644 --- a/doc/apt-patterns.7.xml +++ b/doc/apt-patterns.7.xml @@ -65,6 +65,9 @@ + ?all-versions(PATTERN) + Selects packages where all versions match PATTERN. When matching versions instead, same as PATTERN. + ?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. diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns index 291aad1d4..f726d0576 100755 --- a/test/integration/test-apt-patterns +++ b/test/integration/test-apt-patterns @@ -121,6 +121,9 @@ 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 '?narrow(?version(^1\.0$),?name(not-obsolete))' +testsuccessequal "Listing... +foreign/unstable 2.0 amd64 +not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?not(?all-versions(?version(^1)))' msgmsg "Package patterns" -- cgit v1.2.3-70-g09d2 From a93b4443c18ee211691f7b336b161fea7d1df699 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 26 Nov 2019 12:01:42 +0100 Subject: patterns: Add ?section --- apt-pkg/cachefilter-patterns.cc | 2 ++ apt-pkg/cachefilter-patterns.h | 10 ++++++++++ doc/apt-patterns.7.xml | 3 +++ test/integration/test-apt-patterns | 9 +++++++-- 4 files changed, 22 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index 8214c388a..a9f76ff1d 100644 --- a/apt-pkg/cachefilter-patterns.cc +++ b/apt-pkg/cachefilter-patterns.cc @@ -244,6 +244,8 @@ std::unique_ptr PatternParser::aPattern(std::unique_p return std::make_unique(); if (node->matches("?origin", 1, 1)) return std::make_unique(aWord(node->arguments[0])); + if (node->matches("?section", 1, 1)) + return std::make_unique(aWord(node->arguments[0])); if (node->matches("?source-package", 1, 1)) return std::make_unique(aWord(node->arguments[0])); if (node->matches("?source-version", 1, 1)) diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index 8c5561c82..bd8ce7e7e 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -320,6 +320,16 @@ struct VersionIsOrigin : public VersionAnyMatcher } }; +struct VersionIsSection : public VersionAnyMatcher +{ + BaseRegexMatcher matcher; + VersionIsSection(std::string const &pattern) : matcher(pattern) {} + bool operator()(pkgCache::VerIterator const &Ver) override + { + return matcher(Ver.Section()); + } +}; + struct VersionIsSourcePackage : public VersionAnyMatcher { BaseRegexMatcher matcher; diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml index 04f97e878..219d2c209 100644 --- a/doc/apt-patterns.7.xml +++ b/doc/apt-patterns.7.xml @@ -135,6 +135,9 @@ ?origin(REGEX) Selects versions that come from the origin that matches the specified regular expression. Origin, here, means the values after o= in apt-cache policy. + ?section(REGEX) + Selects versions where the section matches the specified regular expression. + ?source-package(REGEX) Selects versions where the source package name matches the specified regular expression. diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns index f726d0576..06c552479 100755 --- a/test/integration/test-apt-patterns +++ b/test/integration/test-apt-patterns @@ -5,7 +5,7 @@ TESTDIR="$(readlink -f "$(dirname "$0")")" setupenvironment configarchitecture 'i386' 'amd64' -insertpackage 'unstable' 'available' 'all' '1.0' +insertpackage 'unstable' 'available' 'all' '1.0' 'Section: asection' insertinstalledpackage 'manual1' 'i386' '1.0' 'Depends: automatic1' insertinstalledpackage 'manual2' 'i386' '1.0' @@ -13,7 +13,8 @@ insertinstalledpackage 'manual2' 'i386' '1.0' insertinstalledpackage 'automatic1' 'i386' '1.0' 'Source: automatic (0)' insertinstalledpackage 'automatic2' 'i386' '1.0' 'Source: automatic (1)' -insertinstalledpackage 'essential' 'i386' '1.0' 'Essential: yes' +insertinstalledpackage 'essential' 'i386' '1.0' 'Essential: yes +Section: asection' insertinstalledpackage 'conf-only' 'i386' '1.0' '' '' 'deinstall ok config-files' insertinstalledpackage 'broken' 'i386' '1.0' 'Depends: does-not-exist' @@ -189,6 +190,10 @@ available/unstable 1.0 all foreign/unstable 2.0 amd64 not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?origin(^meow$)' +testsuccessequal "Listing... +available/unstable 1.0 all +essential/now 1.0 i386 [installed,local]" apt list '?section(asection)' + testsuccessequal "Listing... automatic1/now 1.0 i386 [installed,local] automatic2/now 1.0 i386 [installed,local]" apt list '?source-package(^automatic$)' -- cgit v1.2.3-70-g09d2