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

apt-cache should have a reverse depends and a reverse build depends
action. it should include the functionality of apt-rdepends. 

attached is a patch which adds a reverse depends action as well as an
installed flag, so you can check reverse depends and depends within
the context of your own machine. 

i plan to add the build depends and build rdepends in the near
future. 

michael

-- System Information
Debian Release: 3.0
Architecture: i386
Kernel: Linux rilke 2.4.19 #3 SMP Fri Aug 9 23:00:09 PDT 2002 i686
Locale: LANG=C, LC_CTYPE=

Versions of packages apt depends on:
ii  libc6                         2.2.5-14   GNU C Library: Shared libraries an
ii  libstdc++2.10-glibc2.2        1:2.95.4-7 The GNU stdc++ library

-- 
michael cardenas | lead software engineer | lindows.com | hyperpoem.net

"And if the earth no longer knows your name, 
 whisper to the silent earth: I'm flowing. 
 To the flashing water say: I am."
- Rainer Maria Rilke
--- apt-0.5.4/cmdline/apt-cache.cc      Sun Jul  1 17:10:32 2001
+++ apt-0.5.4/cmdline/apt-cache.cc.mbc  Thu Aug 22 07:44:09 2002
@@ -525,6 +525,7 @@
    }
    
    bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false);
+   bool Installed = _config->FindB("APT::Cache::Installed",false);
    bool DidSomething;
    do
    {
@@ -547,20 +548,115 @@
         
         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 << "  ";
+           
+               // 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]++;
+
+             }
            
-           if (Recurse == true)
-              Colours[D.TargetPkg()->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;
+}
+
+// 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();
@@ -583,6 +679,7 @@
    
    return true;
 }
+
                                                                        /*}}}*/
 // Dotty - Generate a graph for Dotty                                  /*{{{*/
 // ---------------------------------------------------------------------
@@ -1273,6 +1370,7 @@
       "   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"
       "   policy - Show policy settings\n"
@@ -1316,6 +1414,7 @@
       {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},
@@ -1329,6 +1428,7 @@
                                     {"unmet",&UnMet},
                                     {"search",&Search},
                                     {"depends",&Depends},
+                                    {"rdepends",&RDepends},
                                     {"dotty",&Dotty},
                                     {"show",&ShowPackage},
                                     {"pkgnames",&ShowPkgNames},

Reply via email to