diff options
author | Julian Andres Klode <julian.klode@canonical.com> | 2019-08-21 22:21:30 +0200 |
---|---|---|
committer | Julian Andres Klode <julian.klode@canonical.com> | 2019-11-25 11:32:19 +0100 |
commit | 7fa292edbe924923cc689721fe58244ca0a40bcd (patch) | |
tree | fad811887e13057885056900431bdce9de62e487 | |
parent | 8428114608627fe0a08dcf1589931f6db025f0b4 (diff) |
patterns: Add ?source-name and ?source-version
-rw-r--r-- | apt-pkg/cachefilter-patterns.cc | 4 | ||||
-rw-r--r-- | apt-pkg/cachefilter-patterns.h | 20 | ||||
-rw-r--r-- | doc/apt-patterns.7.xml | 6 | ||||
-rwxr-xr-x | test/integration/test-apt-patterns | 11 |
4 files changed, 39 insertions, 2 deletions
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<APT::CacheFilter::Matcher> PatternParser::aPattern(std::unique_p return std::make_unique<APT::CacheFilter::NOTMatcher>(aPattern(node->arguments[0]).release()); if (node->matches("?obsolete", 0, 0)) return std::make_unique<Patterns::PackageIsObsolete>(); + if (node->matches("?source-package", 1, 1)) + return std::make_unique<Patterns::VersionIsSourcePackage>(aWord(node->arguments[0])); + if (node->matches("?source-version", 1, 1)) + return std::make_unique<Patterns::VersionIsSourceVersion>(aWord(node->arguments[0])); if (node->matches("?true", 0, 0)) return std::make_unique<APT::CacheFilter::TrueMatcher>(); 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. </para> <variablelist> + <varlistentry><term><code>?source-package(REGEX)</code></term> + <listitem><para>Selects versions where the source package name matches the specified regular expression.</para></listitem> + </varlistentry> + <varlistentry><term><code>?source-version(REGEX)</code></term> + <listitem><para>Selects versions where the source package version matches the specified regular expression.</para></listitem> + </varlistentry> <varlistentry><term><code>?version(REGEX)</code></term> <listitem><para>Selects versions where the version string matching the specified regular expression.</para></listitem> </varlistentry> 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' @@ -158,6 +158,13 @@ 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' |