summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2019-11-26 11:34:34 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2019-11-26 11:34:34 +0100
commit6801e6d2c63d4ff087024fc84a0feb8aef86886b (patch)
tree2be0ce13c2500b4113c3ba721ec6cfaca3706287
parent02b0afd5098534eff34a8fa1d44454c7a3e1ff09 (diff)
patterns: Add ?any-version
-rw-r--r--apt-pkg/cachefilter-patterns.cc2
-rw-r--r--apt-pkg/cachefilter-patterns.h11
-rw-r--r--doc/apt-patterns.7.xml11
-rwxr-xr-xtest/integration/test-apt-patterns14
4 files changed, 38 insertions, 0 deletions
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<APT::CacheFilter::Matcher> PatternParser::aPattern(std::unique_p
return std::make_unique<APT::CacheFilter::PackageArchitectureMatchesSpecification>(aWord(node->arguments[0]));
if (node->matches("?archive", 1, 1))
return std::make_unique<Patterns::VersionIsArchive>(aWord(node->arguments[0]));
+ if (node->matches("?any-version", 1, 1))
+ return std::make_unique<Patterns::VersionIsAnyVersion>(aPattern(node->arguments[0]));
if (node->matches("?automatic", 0, 0))
return std::make_unique<Patterns::PackageIsAutomatic>(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<APT::CacheFilter::Matcher> base;
+ VersionIsAnyVersion(std::unique_ptr<APT::CacheFilter::Matcher> 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
@@ -61,6 +61,17 @@
</variablelist>
</refsect1>
<refsect1>
+ <title>Narrowing patterns</title>
+ <para>
+ </para>
+ <variablelist>
+ <varlistentry><term><code>?any-version(PATTERN)</code></term>
+ <listitem><para>Selects any version where the pattern matches on the version.</para>
+ <para>For example, while <code>?and(?version(1),?version(2))</code> matches a package which has one version containing 1 and one version containing 2, <code>?any-version(?and(?version(1),?version(2)))</code> restricts the <code>?and</code> to act on the same version.</para></listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+ <refsect1>
<title>Package patterns</title>
<para>
These patterns select specific packages.
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...