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

Add a rdepends command to apt-cache.
Author: doogie
Date: 2003-04-27 02:47:44 GMT
Add a rdepends command to apt-cache.

Arch Librarian лет назад: 22
Родитель
Сommit
eba2b51d9e
3 измененных файлов с 121 добавлено и 13 удалено
  1. 113 13
      cmdline/apt-cache.cc
  2. 1 0
      debian/changelog
  3. 7 0
      doc/apt-cache.8.sgml

+ 113 - 13
cmdline/apt-cache.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // 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
    apt-cache - Manages the cache files
@@ -529,6 +529,7 @@ bool Depends(CommandLine &CmdL)
    }
    }
    
    
    bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false);
    bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false);
+   bool Installed = _config->FindB("APT::Cache::Installed",false);
    bool DidSomething;
    bool DidSomething;
    do
    do
    {
    {
@@ -551,20 +552,27 @@ bool Depends(CommandLine &CmdL)
 	 
 	 
 	 for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
 	 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();
 	    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
 	    // Display all solutions
 	    SPtrArray<pkgCache::Version *> List = D.AllTargets();
 	    SPtrArray<pkgCache::Version *> List = D.AllTargets();
@@ -587,6 +595,95 @@ bool Depends(CommandLine &CmdL)
    
    
    return 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();
+	    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"
       "   search - Search the package list for a regex pattern\n"
       "   show - Show a readable record for the package\n"
       "   show - Show a readable record for the package\n"
       "   depends - Show raw dependency information for a 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"
       "   pkgnames - List the names of all packages\n"
       "   dotty - Generate package graphs for GraphVis\n"
       "   dotty - Generate package graphs for GraphVis\n"
       "   xvcg - Generate package graphs for xvcg\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},
       {0,"recurse","APT::Cache::RecurseDepends",0},
       {'c',"config-file",0,CommandLine::ConfigFile},
       {'c',"config-file",0,CommandLine::ConfigFile},
       {'o',"option",0,CommandLine::ArbItem},
       {'o',"option",0,CommandLine::ArbItem},
+      {'n',"installed","APT::Cache::Installed",0},
       {0,0,0,0}};
       {0,0,0,0}};
    CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp},
    CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp},
                                     {"add",&DoAdd},
                                     {"add",&DoAdd},
@@ -1555,6 +1654,7 @@ int main(int argc,const char *argv[])
                                     {"unmet",&UnMet},
                                     {"unmet",&UnMet},
                                     {"search",&Search},
                                     {"search",&Search},
                                     {"depends",&Depends},
                                     {"depends",&Depends},
+                                    {"rdepends",&RDepends},
                                     {"dotty",&Dotty},
                                     {"dotty",&Dotty},
                                     {"xvcg",&XVcg},
                                     {"xvcg",&XVcg},
                                     {"show",&ShowPackage},
                                     {"show",&ShowPackage},

+ 1 - 0
debian/changelog

@@ -115,6 +115,7 @@ apt (0.5.4.9) unstable; urgency=low
     #54982.
     #54982.
   * Insert some newlines in the cdrom change media message.  Closes:
   * Insert some newlines in the cdrom change media message.  Closes:
     #154601.
     #154601.
+  * Add a rdepends command to apt-cache.  Closes: #159864.
 
 
  -- Adam Heath <doogie@debian.org>  Sun, 02 Feb 2003 02:54:45 -0600
  -- Adam Heath <doogie@debian.org>  Sun, 02 Feb 2003 02:54:45 -0600
 
 

+ 7 - 0
doc/apt-cache.8.sgml

@@ -40,6 +40,7 @@
          <arg>show <arg choice="plain" rep="repeat"><replaceable>pkg</replaceable></arg></arg>
          <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>showpkg <arg choice="plain" rep="repeat"><replaceable>pkg</replaceable></arg></arg>
          <arg>depends <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>pkgnames <arg choice="plain"><replaceable>prefix</replaceable></arg></arg>
          <arg>dotty <arg choice="plain" rep="repeat"><replaceable>pkg</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>
          <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.
      and all the possible other packages that can fulfill that dependency.
      </VarListEntry>
      </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>
      <VarListEntry><Term>pkgnames <replaceable/[ prefix ]/</Term>
      <ListItem><Para>
      <ListItem><Para>
      This command prints the name of each package in the system. The optional
      This command prints the name of each package in the system. The optional