summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2024-04-29 14:56:41 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2024-04-29 14:56:41 +0200
commit9a29aa8f61530aca8a46d0c6de08ea78c6e57f9e (patch)
treefaad88f9efe8093727d9fe2e7b2e7aa183d64c17
parentedfbc3869361f709d70794a794199ac2076ea9f1 (diff)
showsrc: Support querying src:name
This has the same meaning as --only-source name
-rw-r--r--apt-private/private-show.cc14
-rwxr-xr-xtest/integration/test-apt-cache-showsrc6
2 files changed, 17 insertions, 3 deletions
diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc
index 4ae043071..ceef6707e 100644
--- a/apt-private/private-show.cc
+++ b/apt-private/private-show.cc
@@ -446,14 +446,22 @@ bool ShowSrcPackage(CommandLine &CmdL) /*{{{*/
std::set<std::string> seen;
for (const char **I = CmdL.FileList + 1; *I != 0; I++)
{
+ const char *pkgname = *I;
SrcRecs.Restart();
pkgSrcRecords::Parser *Parse;
bool found_this = false;
- while ((Parse = SrcRecs.Find(*I,false)) != 0) {
+ bool only_source = _config->FindB("APT::Cache::Only-Source", false);
+ if (APT::String::Startswith(pkgname, "src:"))
+ {
+ only_source = true;
+ pkgname += 4;
+ }
+ while ((Parse = SrcRecs.Find(pkgname, false)) != 0)
+ {
// SrcRecs.Find() will find both binary and source names
- if (_config->FindB("APT::Cache::Only-Source", false) == true)
- if (Parse->Package() != *I)
+ if (only_source)
+ if (Parse->Package() != pkgname)
continue;
std::string sha1str = Sha1FromString(Parse->AsStr());
if (std::find(seen.begin(), seen.end(), sha1str) == seen.end())
diff --git a/test/integration/test-apt-cache-showsrc b/test/integration/test-apt-cache-showsrc
index d3f61d972..0f0e21d35 100755
--- a/test/integration/test-apt-cache-showsrc
+++ b/test/integration/test-apt-cache-showsrc
@@ -29,3 +29,9 @@ testsuccess grep "Package: unrelated" output.txt
aptcache showsrc --only-source foo > output.txt
testsuccess grep "Package: foo" output.txt
testfailure grep "Package: unrelated" output.txt
+
+# by default apt-cache showsrc will look into "binary" and "source" names
+# and show all matches
+aptcache showsrc src:foo > output.txt
+testsuccess grep "Package: foo" output.txt
+testfailure grep "Package: unrelated" output.txt