Add a rdepends command to apt-cache.
authorArch Librarian <arch@canonical.com>
Mon, 20 Sep 2004 17:01:18 +0000 (17:01 +0000)
committerArch Librarian <arch@canonical.com>
Mon, 20 Sep 2004 17:01:18 +0000 (17:01 +0000)
Author: doogie
Date: 2003-04-27 02:47:44 GMT
Add a rdepends command to apt-cache.

cmdline/apt-cache.cc
debian/changelog
doc/apt-cache.8.sgml

index 326bef1b8c80157543725c4db631143ce93ca57b..ed3c31531e6fa0156f9c5b1e3b7a8dd4dcc5528e 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: apt-cache.cc,v 1.62 2003/04/27 01:32:48 doogie Exp $
+// $Id: apt-cache.cc,v 1.63 2003/04/27 02:47:44 doogie Exp $
 /* ######################################################################
    
    apt-cache - Manages the cache files
@@ -529,6 +529,7 @@ bool Depends(CommandLine &CmdL)
    }
    
    bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false);
+   bool Installed = _config->FindB("APT::Cache::Installed",false);
    bool DidSomething;
    do
    {
@@ -551,20 +552,27 @@ bool Depends(CommandLine &CmdL)
         
         for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
         {
-           if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
-              cout << " |";
-           else
-              cout << "  ";
-           
-           // Show the package
+
            pkgCache::PkgIterator Trg = D.TargetPkg();
-           if (Trg->VersionList == 0)
-              cout << D.DepType() << ": <" << Trg.Name() << ">" << endl;
-           else
-              cout << D.DepType() << ": " << Trg.Name() << endl;
+
+           if((Installed && Trg->CurrentVer != 0) || !Installed)
+             {
+
+               if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
+                 cout << " |";
+               else
+                 cout << "  ";
            
-           if (Recurse == true)
-              Colours[D.TargetPkg()->ID]++;
+               // Show the package
+               if (Trg->VersionList == 0)
+                 cout << D.DepType() << ": <" << Trg.Name() << ">" << endl;
+               else
+                 cout << D.DepType() << ": " << Trg.Name() << endl;
+           
+               if (Recurse == true)
+                 Colours[D.TargetPkg()->ID]++;
+
+             }
            
            // Display all solutions
            SPtrArray<pkgCache::Version *> List = D.AllTargets();
@@ -587,6 +595,95 @@ bool Depends(CommandLine &CmdL)
    
    return true;
 }
+
+// RDepends - Print out a reverse dependency tree - mbc                        /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool RDepends(CommandLine &CmdL)
+{
+   pkgCache &Cache = *GCache;
+   SPtrArray<unsigned> Colours = new unsigned[Cache.Head().PackageCount];
+   memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount);
+   
+   for (const char **I = CmdL.FileList + 1; *I != 0; I++)
+   {
+      pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
+      if (Pkg.end() == true)
+      {
+        _error->Warning(_("Unable to locate package %s"),*I);
+        continue;
+      }
+      Colours[Pkg->ID] = 1;
+   }
+   
+   bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false);
+   bool Installed = _config->FindB("APT::Cache::Installed",false);
+   bool DidSomething;
+   do
+   {
+      DidSomething = false;
+      for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
+      {
+        if (Colours[Pkg->ID] != 1)
+           continue;
+        Colours[Pkg->ID] = 2;
+        DidSomething = true;
+        
+        pkgCache::VerIterator Ver = Pkg.VersionList();
+        if (Ver.end() == true)
+        {
+           cout << '<' << Pkg.Name() << '>' << endl;
+           continue;
+        }
+        
+        cout << Pkg.Name() << endl;
+        
+        cout << "Reverse Depends:" << endl;
+        for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false; D++)
+        {          
+           // Show the package
+           pkgCache::PkgIterator Trg = D.ParentPkg();
+
+           if((Installed && Trg->CurrentVer != 0) || !Installed)
+             {
+
+               if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
+                 cout << " |";
+               else
+                 cout << "  ";
+
+               if (Trg->VersionList == 0)
+                 cout << D.DepType() << ": <" << Trg.Name() << ">" << endl;
+               else
+                 cout << Trg.Name() << endl;
+
+               if (Recurse == true)
+                 Colours[D.ParentPkg()->ID]++;
+
+             }
+           
+           // Display all solutions
+           SPtrArray<pkgCache::Version *> List = D.AllTargets();
+           pkgPrioSortList(Cache,List);
+           for (pkgCache::Version **I = List; *I != 0; I++)
+           {
+              pkgCache::VerIterator V(Cache,*I);
+              if (V != Cache.VerP + V.ParentPkg()->VersionList ||
+                  V->ParentPkg == D->Package)
+                 continue;
+              cout << "    " << V.ParentPkg().Name() << endl;
+              
+              if (Recurse == true)
+                 Colours[D.ParentPkg()->ID]++;
+           }
+        }
+      }      
+   }   
+   while (DidSomething == true);
+   
+   return true;
+}
+
                                                                        /*}}}*/
 
 
@@ -1498,6 +1595,7 @@ bool ShowHelp(CommandLine &Cmd)
       "   search - Search the package list for a regex pattern\n"
       "   show - Show a readable record for the package\n"
       "   depends - Show raw dependency information for a package\n"
+      "   rdepends - Show reverse dependency information for a package\n"
       "   pkgnames - List the names of all packages\n"
       "   dotty - Generate package graphs for GraphVis\n"
       "   xvcg - Generate package graphs for xvcg\n"
@@ -1542,6 +1640,7 @@ int main(int argc,const char *argv[])
       {0,"recurse","APT::Cache::RecurseDepends",0},
       {'c',"config-file",0,CommandLine::ConfigFile},
       {'o',"option",0,CommandLine::ArbItem},
+      {'n',"installed","APT::Cache::Installed",0},
       {0,0,0,0}};
    CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp},
                                     {"add",&DoAdd},
@@ -1555,6 +1654,7 @@ int main(int argc,const char *argv[])
                                     {"unmet",&UnMet},
                                     {"search",&Search},
                                     {"depends",&Depends},
+                                    {"rdepends",&RDepends},
                                     {"dotty",&Dotty},
                                     {"xvcg",&XVcg},
                                     {"show",&ShowPackage},
index 91e8a730884e0225a817250165b92b4afaf82b90..e8dd8854381d0d819a2dedd10c23cc0501e58088 100644 (file)
@@ -115,6 +115,7 @@ apt (0.5.4.9) unstable; urgency=low
     #54982.
   * Insert some newlines in the cdrom change media message.  Closes:
     #154601.
+  * Add a rdepends command to apt-cache.  Closes: #159864.
 
  -- Adam Heath <doogie@debian.org>  Sun, 02 Feb 2003 02:54:45 -0600
 
index a3263bda0c5a2acb7a40c5247c4712b9283c2abe..a52e21222d3dc553628e3a82010db5597ffa72e6 100644 (file)
@@ -40,6 +40,7 @@
          <arg>show <arg choice="plain" rep="repeat"><replaceable>pkg</replaceable></arg></arg>
          <arg>showpkg <arg choice="plain" rep="repeat"><replaceable>pkg</replaceable></arg></arg>
          <arg>depends <arg choice="plain" rep="repeat"><replaceable>pkg</replaceable></arg></arg>
+         <arg>rdepends <arg choice="plain" rep="repeat"><replaceable>pkg</replaceable></arg></arg>
          <arg>pkgnames <arg choice="plain"><replaceable>prefix</replaceable></arg></arg>
          <arg>dotty <arg choice="plain" rep="repeat"><replaceable>pkg</replaceable></arg></arg>
          <arg>policy <arg choice="plain" rep="repeat"><replaceable>pkgs</replaceable></arg></arg>
@@ -224,6 +225,12 @@ Reverse Provides:
      and all the possible other packages that can fulfill that dependency.
      </VarListEntry>
 
+     <VarListEntry><Term>rdepends <replaceable/pkg(s)/</Term>
+     <ListItem><Para>
+     <literal/rdepends/ shows a listing of each reverse dependency a package
+     has.
+     </VarListEntry>
+
      <VarListEntry><Term>pkgnames <replaceable/[ prefix ]/</Term>
      <ListItem><Para>
      This command prints the name of each package in the system. The optional