summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schauer Marin Rodrigues <josch@mister-muffin.de>2021-12-26 16:29:59 +0100
committerJohannes Schauer Marin Rodrigues <josch@mister-muffin.de>2021-12-26 22:04:21 +0100
commited282548bc4b8f96ac531c9f73b42d968eadea98 (patch)
tree136608db9a6f62b13cb39f0ad872e9e56cbfe985
parent2662f6f255a2f1fee25632dc7666d4153bf5248c (diff)
add pattern to select packages by codename (closes: #1002646)
-rw-r--r--apt-pkg/cachefilter-patterns.cc2
-rw-r--r--apt-pkg/cachefilter-patterns.h15
-rw-r--r--doc/apt-patterns.7.xml3
-rwxr-xr-xtest/integration/test-apt-patterns5
4 files changed, 25 insertions, 0 deletions
diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc
index 12d8ae748..faf5735b8 100644
--- a/apt-pkg/cachefilter-patterns.cc
+++ b/apt-pkg/cachefilter-patterns.cc
@@ -430,6 +430,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("?codename", 1, 1))
+ return std::make_unique<Patterns::VersionIsCodename>(aWord(node->arguments[0]));
if (node->matches("?all-versions", 1, 1))
return std::make_unique<Patterns::VersionIsAllVersions>(aPattern(node->arguments[0]));
if (node->matches("?any-version", 1, 1))
diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h
index d55cb6335..e6ea16c68 100644
--- a/apt-pkg/cachefilter-patterns.h
+++ b/apt-pkg/cachefilter-patterns.h
@@ -363,6 +363,21 @@ struct APT_HIDDEN VersionIsArchive : public VersionAnyMatcher
}
};
+struct APT_HIDDEN VersionIsCodename : public VersionAnyMatcher
+{
+ BaseRegexMatcher matcher;
+ VersionIsCodename(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().Codename() && matcher(VF.File().Codename()))
+ return true;
+ }
+ return false;
+ }
+};
+
struct APT_HIDDEN VersionIsOrigin : public VersionAnyMatcher
{
BaseRegexMatcher matcher;
diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml
index 6b1c0f20b..0c786ce15 100644
--- a/doc/apt-patterns.7.xml
+++ b/doc/apt-patterns.7.xml
@@ -135,6 +135,9 @@
<varlistentry><term><code>?archive(REGEX)</code></term><term><code>~AREGEX</code></term>
<listitem><para>Selects versions that come from the archive that matches the specified regular expression. Archive, here, means the values after <code>a=</code> in <command>apt-cache policy</command>.</para></listitem>
</varlistentry>
+ <varlistentry><term><code>?codename(REGEX)</code></term>
+ <listitem><para>Selects versions that come from the codename that matches the specified regular expression. Codename, here, means the values after <code>n=</code> in <command>apt-cache policy</command>.</para></listitem>
+ </varlistentry>
<varlistentry><term><code>?origin(REGEX)</code></term><term><code>~OREGEX</code></term>
<listitem><para>Selects versions that come from the origin that matches the specified regular expression. Origin, here, means the values after <code>o=</code> in <command>apt-cache policy</command>.</para></listitem>
</varlistentry>
diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns
index 5355becff..b015655d9 100755
--- a/test/integration/test-apt-patterns
+++ b/test/integration/test-apt-patterns
@@ -149,6 +149,11 @@ foreign/unstable 2.0 amd64
not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?archive(^unstable$)'
testsuccessequal "Listing...
+available/unstable 1.0 all
+foreign/unstable 2.0 amd64
+not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?codename(^sid$)'
+
+testsuccessequal "Listing...
automatic1/now 1.0 i386 [installed,local]
automatic2/now 1.0 i386 [installed,local]" apt list '?automatic'