[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#236270: apt-cache show could support package=version



Package: apt
Version: 0.5.23
Severity: wishlist
Tags: patch

It would be useful if apt-cache show allowed arguments of the form
package=version to display info on a particular version of a package.  Here
is a patch to do that: while I was at it I thought I may as well allow
package/release as well.  The code is mostly taken from cmdline/apt-get.cc.

diff -Naur apt-0.5.23.orig/cmdline/apt-cache.cc apt-0.5.23/cmdline/apt-cache.cc
--- apt-0.5.23.orig/cmdline/apt-cache.cc	2004-01-04 19:00:10.000000000 +0000
+++ apt-0.5.23/cmdline/apt-cache.cc	2004-03-01 15:44:26.000000000 +0000
@@ -1351,17 +1351,56 @@
    
    for (const char **I = CmdL.FileList + 1; *I != 0; I++)
    {
-      pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
+      // Duplicate the package name so we can insert a '\0'
+      unsigned int Length = strlen(*I);
+      char S[300];
+      if (Length >= sizeof(S))
+	 continue;
+      strcpy(S,*I);
+      
+      // Process a version end string
+      char *VerTag = 0;
+      char *Slash = strchr(S,'=');
+      bool VerIsRel = false;
+      if (Slash != 0)
+      {
+	 VerIsRel = false;
+	 *Slash = 0;
+	 VerTag = Slash + 1;
+      }
+      
+      Slash = strchr(S,'/');
+      if (Slash != 0)
+      {
+	 VerIsRel = true;
+	 *Slash = 0;
+	 VerTag = Slash + 1;
+      }
+      
+      pkgCache::PkgIterator Pkg = Cache.FindPkg(S);
+
       if (Pkg.end() == true)
       {
-	 _error->Warning(_("Unable to locate package %s"),*I);
+	 _error->Warning(_("Unable to locate package %s"),S);
 	 continue;
       }
 
       ++found;
 
       // Find the proper version to use.
-      if (_config->FindB("APT::Cache::AllVersions","true") == true)
+      if (VerTag != 0)
+      {
+	 pkgVersionMatch Match(VerTag,(VerIsRel == true?pkgVersionMatch::Release : 
+				       pkgVersionMatch::Version));
+	 pkgCache::VerIterator V = Match.Find(Pkg);
+	 if (V.end() == true || V.FileList().end() == true) {
+	    _error->Warning(_("Unable to locate package %s version %s"),S,VerTag);
+	    continue;
+	 }
+	 if (DisplayRecord(V) == false)
+	    return false;
+      }
+      else if (_config->FindB("APT::Cache::AllVersions","true") == true)
       {
 	 pkgCache::VerIterator V;
 	 for (V = Pkg.VersionList(); V.end() == false; V++)
diff -Naur apt-0.5.23.orig/doc/apt-cache.8 apt-0.5.23/doc/apt-cache.8
--- apt-0.5.23.orig/doc/apt-cache.8	2004-02-27 01:08:53.000000000 +0000
+++ apt-0.5.23/doc/apt-cache.8	2004-03-02 18:46:03.000000000 +0000
@@ -118,7 +118,9 @@
 
 .TP
 show \fIpkg(s)\fR
-show performs a function similar to \fBdpkg \-\-print\-avail\fRi; it displays the package records for the named packages\&.
+show performs a function similar to \fBdpkg \-\-print\-avail\fR; it displays the package records for the named packages\&.
+
+You can select a particular version of the package to display by using \fIpkg\fR=\fIversion\fR or \fIpkg\fR/\fIrelease\fR.
 
 .TP
 search \fIregex [ regex \&.\&.\&. ]\fR
@@ -181,6 +183,7 @@
 
 .TP
 \fB\-a\fR, \fB\-\-all\-versions\fR
+Print full records for all available versions\&. This is the default; to turn it off, use \fB\-\-no\-all\-versions\fR\&. If \fB\-\-no\-all\-versions\fR is specified, only the candidate version will be displayed (the one which would be selected for installation)\&. This option is only applicable to the show command\&. It is ignored if you specify an explicit version with \fIpkg\fR=\fIversion\fR or \fIpkg\fR/\fIrelease\fR\&. Configuration Item: APT::Cache::AllVersions\&.
 Print full records for all available versions\&. This is the default; to turn it off, use \fB\-\-no\-all\-versions\fR\&. If \fB\-\-no\-all\-versions\fR is specified, only the candidate version will displayed (the one which would be selected for installation)\&. This option is only applicable to the show command\&. Configuration Item: APT::Cache::AllVersions\&.
 
 .TP


-- System Information:
Debian Release: testing/unstable
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.4.25
Locale: LANG=C, LC_CTYPE=C

Versions of packages apt depends on:
ii  libc6                       2.3.2.ds1-11 GNU C Library: Shared libraries an
ii  libgcc1                     1:3.3.3-1    GCC support library
ii  libstdc++5                  1:3.3.3-1    The GNU Standard C++ Library v3

-- no debconf information

-- 
Martin Orr
Linux Administrator,
Methodist College Belfast




Reply to: