Просмотр исходного кода

Add support for "apt-cache showsrc --only-source srcpkgname"

Thanks: Steve Slangasek for the suggestion
Closes: 695633
Michael Vogt лет назад: 11
Родитель
Сommit
a8275acf87

+ 5 - 1
apt-private/private-cmndline.cc

@@ -70,7 +70,11 @@ static bool addArgumentsAPTCache(std::vector<CommandLine::Args> &Args, char cons
    {
       addArg('i', "important", "APT::Cache::Important", 0);
    }
-   else if (CmdMatches("gencaches", "showsrc", "showpkg", "stats", "dump",
+   else if (CmdMatches("showsrc"))
+   {
+      addArg(0,"only-source","APT::Cache::Only-Source",0);
+   }
+   else if (CmdMatches("gencaches", "showpkg", "stats", "dump",
 	    "dumpavail", "showauto", "policy", "madison"))
       ;
    else

+ 4 - 0
cmdline/apt-cache.cc

@@ -1607,6 +1607,10 @@ static bool ShowSrcPackage(CommandLine &CmdL)
       pkgSrcRecords::Parser *Parse;
       unsigned found_this = 0;
       while ((Parse = SrcRecs.Find(*I,false)) != 0) {
+         // SrcRecs.Find() will find both binary and source names
+         if (_config->FindB("APT::Cache::Only-Source", false) == true)
+            if (Parse->Package() != *I)
+               continue;
         cout << Parse->AsStr() << endl;;
         found++;
         found_this++;

+ 6 - 3
doc/apt-cache.8.xml

@@ -135,9 +135,12 @@ Reverse Provides:
      </varlistentry>
      
      <varlistentry><term><option>showsrc</option> <option><replaceable>&synopsis-pkg;</replaceable>…</option></term>
-     <listitem><para><literal>showsrc</literal> displays all the source package records that match
-     the given package names. All versions are shown, as well as all 
-     records that declare the name to be a binary package.</para></listitem>
+     <listitem><para><literal>showsrc</literal> displays all the
+     source package records that match the given package names. All
+     versions are shown, as well as all records that declare the name
+     to be a binary package. Use <option>--only-source</option> to
+     display only source package names.
+     </para></listitem>
      </varlistentry>
      
      <varlistentry><term><option>dump</option></term>

+ 2 - 1
test/integration/framework

@@ -794,6 +794,7 @@ insertsource() {
 	local ARCH="$3"
 	local VERSION="$4"
 	local DEPENDENCIES="$5"
+        local BINARY="${6:-$NAME}"
 	local ARCHS=""
 	local SPATH="aptarchive/dists/${RELEASE}/main/source"
 	mkdir -p $SPATH
@@ -801,7 +802,7 @@ insertsource() {
 	local DSCFILE="${NAME}_${VERSION}.dsc"
 	local TARFILE="${NAME}_${VERSION}.tar.gz"
 	echo "Package: $NAME
-Binary: $NAME
+Binary: $BINARY
 Version: $VERSION
 Maintainer: Joe Sixpack <joe@example.org>
 Architecture: $ARCH" >> $FILE

+ 31 - 0
test/integration/test-apt-cache-showsrc

@@ -0,0 +1,31 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+
+setupenvironment
+configarchitecture "i386"
+
+# we have a foo source package
+insertsource 'unstable' 'foo' 'all' '1.0' '' 'foo-binary'
+
+# and a similar one that builds a foo binary package
+insertsource 'unstable' 'unreleated' 'all' '1.0' '' 'foo'
+
+# just here to workaround the need for a authenticated package
+insertpackage 'unstable' 'workaround' 'all' '1.0'
+
+setupaptarchive
+
+# by default apt-cache showsrc will look into "binary" and "source" names
+# and show all matches
+aptcache showsrc foo > output.txt
+testsuccess grep "Package: foo" output.txt
+testsuccess grep "Package: unreleated" output.txt
+
+# by default apt-cache showsrc will look into "binary" and "source" names
+# and show all matches
+aptcache showsrc --only-source foo > output.txt
+testsuccess grep "Package: foo" output.txt
+testfailure grep "Package: unreleated" output.txt