Sfoglia il codice sorgente

convert a lot of places to use IsNegative instead of checking by hand
for the three different dependencies

David Kalnischkies 15 anni fa
parent
commit
359e46db58
5 ha cambiato i file con 26 aggiunte e 72 eliminazioni
  1. 8 23
      apt-pkg/algorithms.cc
  2. 7 18
      apt-pkg/depcache.cc
  3. 4 12
      apt-pkg/orderlist.cc
  4. 3 9
      apt-pkg/pkgcache.cc
  5. 4 10
      cmdline/apt-cache.cc

+ 8 - 23
apt-pkg/algorithms.cc

@@ -101,9 +101,7 @@ bool pkgSimulate::Install(PkgIterator iPkg,string /*File*/)
 	 DepIterator Start;
 	 DepIterator Start;
 	 DepIterator End;
 	 DepIterator End;
 	 D.GlobOr(Start,End);
 	 D.GlobOr(Start,End);
-	 if (Start->Type == pkgCache::Dep::Conflicts ||
-	     Start->Type == pkgCache::Dep::DpkgBreaks ||
-	     Start->Type == pkgCache::Dep::Obsoletes ||
+	 if (Start.IsNegative() == true ||
 	     End->Type == pkgCache::Dep::PreDepends)
 	     End->Type == pkgCache::Dep::PreDepends)
          {
          {
 	    if ((Sim[End] & pkgDepCache::DepGInstall) == 0)
 	    if ((Sim[End] & pkgDepCache::DepGInstall) == 0)
@@ -695,9 +693,7 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
 	    {
 	    {
 	       /* We let the algorithm deal with conflicts on its next iteration,
 	       /* We let the algorithm deal with conflicts on its next iteration,
 		it is much smarter than us */
 		it is much smarter than us */
-	       if (Start->Type == pkgCache::Dep::Conflicts || 
-		   Start->Type == pkgCache::Dep::DpkgBreaks || 
-		   Start->Type == pkgCache::Dep::Obsoletes)
+	       if (Start.IsNegative() == true)
 		   break;
 		   break;
 	       
 	       
 	       if (Debug == true)
 	       if (Debug == true)
@@ -926,9 +922,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
 	       if a package has a dep on another package that cant be found */
 	       if a package has a dep on another package that cant be found */
 	    SPtrArray<pkgCache::Version *> VList = Start.AllTargets();
 	    SPtrArray<pkgCache::Version *> VList = Start.AllTargets();
 	    if (*VList == 0 && (Flags[I->ID] & Protected) != Protected &&
 	    if (*VList == 0 && (Flags[I->ID] & Protected) != Protected &&
-		Start->Type != pkgCache::Dep::Conflicts &&
-		Start->Type != pkgCache::Dep::DpkgBreaks &&
-		Start->Type != pkgCache::Dep::Obsoletes &&
+		Start.IsNegative() == false &&
 		Cache[I].NowBroken() == false)
 		Cache[I].NowBroken() == false)
 	    {	       
 	    {	       
 	       if (InOr == true)
 	       if (InOr == true)
@@ -953,10 +947,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
                   at is not the currently selected version of the 
                   at is not the currently selected version of the 
                   package, which means it is not necessary to 
                   package, which means it is not necessary to 
                   remove/keep */
                   remove/keep */
-               if (Cache[Pkg].InstallVer != Ver &&
-                   (Start->Type == pkgCache::Dep::Conflicts ||
-                    Start->Type == pkgCache::Dep::DpkgBreaks ||
-                    Start->Type == pkgCache::Dep::Obsoletes)) 
+               if (Cache[Pkg].InstallVer != Ver && Start.IsNegative() == true)
                {
                {
                   if (Debug) 
                   if (Debug) 
                      clog << "  Conflicts//Breaks against version " 
                      clog << "  Conflicts//Breaks against version " 
@@ -974,9 +965,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
 	          fiddle with the VList package */
 	          fiddle with the VList package */
 	       if (Scores[I->ID] <= Scores[Pkg->ID] ||
 	       if (Scores[I->ID] <= Scores[Pkg->ID] ||
 		   ((Cache[Start] & pkgDepCache::DepNow) == 0 &&
 		   ((Cache[Start] & pkgDepCache::DepNow) == 0 &&
-		    End->Type != pkgCache::Dep::Conflicts &&
-		    End->Type != pkgCache::Dep::DpkgBreaks &&
-		    End->Type != pkgCache::Dep::Obsoletes))
+		    End.IsNegative() == false))
 	       {
 	       {
 		  // Try a little harder to fix protected packages..
 		  // Try a little harder to fix protected packages..
 		  if ((Flags[I->ID] & Protected) == Protected)
 		  if ((Flags[I->ID] & Protected) == Protected)
@@ -1083,10 +1072,8 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
 	    }
 	    }
 
 
 	    // Hm, nothing can possibly satisify this dep. Nuke it.
 	    // Hm, nothing can possibly satisify this dep. Nuke it.
-	    if (VList[0] == 0 && 
-		Start->Type != pkgCache::Dep::Conflicts &&
-		Start->Type != pkgCache::Dep::DpkgBreaks &&
-		Start->Type != pkgCache::Dep::Obsoletes &&
+	    if (VList[0] == 0 &&
+		Start.IsNegative() == false &&
 		(Flags[I->ID] & Protected) != Protected)
 		(Flags[I->ID] & Protected) != Protected)
 	    {
 	    {
 	       bool Installed = Cache[I].Install();
 	       bool Installed = Cache[I].Install();
@@ -1132,9 +1119,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
 	       Change = true;
 	       Change = true;
 	       if ((Cache[J->Dep] & pkgDepCache::DepGNow) == 0)
 	       if ((Cache[J->Dep] & pkgDepCache::DepGNow) == 0)
 	       {
 	       {
-		  if (J->Dep->Type == pkgCache::Dep::Conflicts || 
-		      J->Dep->Type == pkgCache::Dep::DpkgBreaks ||
-		      J->Dep->Type == pkgCache::Dep::Obsoletes)
+		  if (J->Dep.IsNegative() == true)
 		  {
 		  {
 		     if (Debug == true)
 		     if (Debug == true)
 			clog << "  Fixing " << I.FullName(false) << " via remove of " << J->Pkg.FullName(false) << endl;
 			clog << "  Fixing " << I.FullName(false) << " via remove of " << J->Pkg.FullName(false) << endl;

+ 7 - 18
apt-pkg/depcache.cc

@@ -339,8 +339,7 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res)
    /* Check simple depends. A depends -should- never self match but 
    /* Check simple depends. A depends -should- never self match but 
       we allow it anyhow because dpkg does. Technically it is a packaging
       we allow it anyhow because dpkg does. Technically it is a packaging
       bug. Conflicts may never self match */
       bug. Conflicts may never self match */
-   if (Dep.TargetPkg() != Dep.ParentPkg() ||
-       (Dep->Type != Dep::Conflicts && Dep->Type != Dep::DpkgBreaks && Dep->Type != Dep::Obsoletes))
+   if (Dep.TargetPkg() != Dep.ParentPkg() || Dep.IsNegative() == false)
    {
    {
       PkgIterator Pkg = Dep.TargetPkg();
       PkgIterator Pkg = Dep.TargetPkg();
       // Check the base package
       // Check the base package
@@ -370,8 +369,7 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res)
    {
    {
       /* Provides may never be applied against the same package (or group)
       /* Provides may never be applied against the same package (or group)
          if it is a conflicts. See the comment above. */
          if it is a conflicts. See the comment above. */
-      if (P.OwnerPkg()->Group == Pkg->Group &&
-	  (Dep->Type == Dep::Conflicts || Dep->Type == Dep::DpkgBreaks))
+      if (P.OwnerPkg()->Group == Pkg->Group && Dep.IsNegative() == true)
 	 continue;
 	 continue;
       
       
       // Check if the provides is a hit
       // Check if the provides is a hit
@@ -594,9 +592,7 @@ void pkgDepCache::BuildGroupOrs(VerIterator const &V)
 
 
       /* Invert for Conflicts. We have to do this twice to get the
       /* Invert for Conflicts. We have to do this twice to get the
          right sense for a conflicts group */
          right sense for a conflicts group */
-      if (D->Type == Dep::Conflicts ||
-	  D->Type == Dep::DpkgBreaks ||
-	  D->Type == Dep::Obsoletes)
+      if (D.IsNegative() == true)
 	 State = ~State;
 	 State = ~State;
       
       
       // Add to the group if we are within an or..
       // Add to the group if we are within an or..
@@ -607,9 +603,7 @@ void pkgDepCache::BuildGroupOrs(VerIterator const &V)
 	 Group = 0;
 	 Group = 0;
       
       
       // Invert for Conflicts
       // Invert for Conflicts
-      if (D->Type == Dep::Conflicts ||
-	  D->Type == Dep::DpkgBreaks ||
-	  D->Type == Dep::Obsoletes)
+      if (D.IsNegative() == true)
 	 State = ~State;
 	 State = ~State;
    }	 
    }	 
 }
 }
@@ -742,9 +736,7 @@ void pkgDepCache::Update(OpProgress *Prog)
 	       Group = 0;
 	       Group = 0;
 
 
 	    // Invert for Conflicts
 	    // Invert for Conflicts
-	    if (D->Type == Dep::Conflicts ||
-		D->Type == Dep::DpkgBreaks ||
-		D->Type == Dep::Obsoletes)
+	    if (D.IsNegative() == true)
 	       State = ~State;
 	       State = ~State;
 	 }
 	 }
       }
       }
@@ -774,9 +766,7 @@ void pkgDepCache::Update(DepIterator D)
       State = DependencyState(D);
       State = DependencyState(D);
     
     
       // Invert for Conflicts
       // Invert for Conflicts
-      if (D->Type == Dep::Conflicts ||
-	  D->Type == Dep::DpkgBreaks ||
-	  D->Type == Dep::Obsoletes)
+      if (D.IsNegative() == true)
 	 State = ~State;
 	 State = ~State;
 
 
       RemoveStates(D.ParentPkg());
       RemoveStates(D.ParentPkg());
@@ -1222,8 +1212,7 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
       /* For conflicts we just de-install the package and mark as auto,
       /* For conflicts we just de-install the package and mark as auto,
          Conflicts may not have or groups.  For dpkg's Breaks we try to
          Conflicts may not have or groups.  For dpkg's Breaks we try to
          upgrade the package. */
          upgrade the package. */
-      if (Start->Type == Dep::Conflicts || Start->Type == Dep::Obsoletes ||
-	  Start->Type == Dep::DpkgBreaks)
+      if (Start.IsNegative() == true)
       {
       {
 	 for (Version **I = List; *I != 0; I++)
 	 for (Version **I = List; *I != 0; I++)
 	 {
 	 {

+ 4 - 12
apt-pkg/orderlist.cc

@@ -507,15 +507,11 @@ bool pkgOrderList::VisitProvides(DepIterator D,bool Critical)
       if (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)
       if (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)
 	 continue;
 	 continue;
       
       
-      if (D->Type != pkgCache::Dep::Conflicts &&
-	  D->Type != pkgCache::Dep::DpkgBreaks &&
-	  D->Type != pkgCache::Dep::Obsoletes &&
+      if (D.IsNegative() == false &&
 	  Cache[Pkg].InstallVer != *I)
 	  Cache[Pkg].InstallVer != *I)
 	 continue;
 	 continue;
       
       
-      if ((D->Type == pkgCache::Dep::Conflicts ||
-	   D->Type == pkgCache::Dep::DpkgBreaks ||
-	   D->Type == pkgCache::Dep::Obsoletes) &&
+      if (D.IsNegative() == true &&
 	  (Version *)Pkg.CurrentVer() != *I)
 	  (Version *)Pkg.CurrentVer() != *I)
 	 continue;
 	 continue;
       
       
@@ -647,9 +643,7 @@ bool pkgOrderList::DepUnPackCrit(DepIterator D)
       {
       {
 	 /* Forward critical dependencies MUST be correct before the 
 	 /* Forward critical dependencies MUST be correct before the 
 	    package can be unpacked. */
 	    package can be unpacked. */
-	 if (D->Type != pkgCache::Dep::Conflicts &&
-	     D->Type != pkgCache::Dep::DpkgBreaks &&
-	     D->Type != pkgCache::Dep::Obsoletes &&
+	 if (D.IsNegative() == false &&
 	     D->Type != pkgCache::Dep::PreDepends)
 	     D->Type != pkgCache::Dep::PreDepends)
 	    continue;
 	    continue;
 	 	 	 	 
 	 	 	 	 
@@ -1077,9 +1071,7 @@ bool pkgOrderList::CheckDep(DepIterator D)
       
       
       /* Conflicts requires that all versions are not present, depends
       /* Conflicts requires that all versions are not present, depends
          just needs one */
          just needs one */
-      if (D->Type != pkgCache::Dep::Conflicts && 
-	  D->Type != pkgCache::Dep::DpkgBreaks && 
-	  D->Type != pkgCache::Dep::Obsoletes)
+      if (D.IsNegative() == false)
       {
       {
 	 /* Try to find something that does not have the after flag set
 	 /* Try to find something that does not have the after flag set
 	    if at all possible */
 	    if at all possible */

+ 3 - 9
apt-pkg/pkgcache.cc

@@ -521,9 +521,7 @@ std::string pkgCache::PkgIterator::FullName(bool const &Pretty) const
    conflicts (including dpkg's Breaks fields). */
    conflicts (including dpkg's Breaks fields). */
 bool pkgCache::DepIterator::IsCritical() const
 bool pkgCache::DepIterator::IsCritical() const
 {
 {
-   if (S->Type == pkgCache::Dep::Conflicts ||
-       S->Type == pkgCache::Dep::DpkgBreaks ||
-       S->Type == pkgCache::Dep::Obsoletes ||
+   if (IsNegative() == true ||
        S->Type == pkgCache::Dep::Depends ||
        S->Type == pkgCache::Dep::Depends ||
        S->Type == pkgCache::Dep::PreDepends)
        S->Type == pkgCache::Dep::PreDepends)
       return true;
       return true;
@@ -618,9 +616,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() const
 	 if (Owner->VS->CheckDep(I.VerStr(),S->CompareOp,TargetVer()) == false)
 	 if (Owner->VS->CheckDep(I.VerStr(),S->CompareOp,TargetVer()) == false)
 	    continue;
 	    continue;
 
 
-	 if ((S->Type == pkgCache::Dep::Conflicts ||
-	      S->Type == pkgCache::Dep::DpkgBreaks ||
-	      S->Type == pkgCache::Dep::Obsoletes) &&
+	 if (IsNegative() == true &&
 	     ParentPkg() == I.ParentPkg())
 	     ParentPkg() == I.ParentPkg())
 	    continue;
 	    continue;
 	 
 	 
@@ -635,9 +631,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() const
 	 if (Owner->VS->CheckDep(I.ProvideVersion(),S->CompareOp,TargetVer()) == false)
 	 if (Owner->VS->CheckDep(I.ProvideVersion(),S->CompareOp,TargetVer()) == false)
 	    continue;
 	    continue;
 	 
 	 
-	 if ((S->Type == pkgCache::Dep::Conflicts ||
-	      S->Type == pkgCache::Dep::DpkgBreaks ||
-	      S->Type == pkgCache::Dep::Obsoletes) &&
+	 if (IsNegative() == true &&
 	     ParentPkg() == I.OwnerPkg())
 	     ParentPkg() == I.OwnerPkg())
 	    continue;
 	    continue;
 	 
 	 

+ 4 - 10
cmdline/apt-cache.cc

@@ -121,9 +121,7 @@ bool ShowUnMet(pkgCache::VerIterator const &V, bool const &Important)
 		  continue;
 		  continue;
 
 
 	    // Skip conflicts and replaces
 	    // Skip conflicts and replaces
-	    if (End->Type == pkgCache::Dep::DpkgBreaks ||
-		End->Type == pkgCache::Dep::Replaces ||
-		End->Type == pkgCache::Dep::Conflicts)
+	    if (End.IsNegative() == true)
 	       continue;
 	       continue;
 
 
 	    // Verify the or group
 	    // Verify the or group
@@ -848,10 +846,7 @@ bool XVcg(CommandLine &CmdL)
 	       {
 	       {
 		  /* If a conflicts does not meet anything in the database
 		  /* If a conflicts does not meet anything in the database
 		     then show the relation but do not recurse */
 		     then show the relation but do not recurse */
-		  if (Hit == false && 
-		      (D->Type == pkgCache::Dep::Conflicts ||
-		       D->Type == pkgCache::Dep::DpkgBreaks ||
-		       D->Type == pkgCache::Dep::Obsoletes))
+		  if (Hit == false && D.IsNegative() == true)
 		  {
 		  {
 		     if (Show[D.TargetPkg()->ID] == None && 
 		     if (Show[D.TargetPkg()->ID] == None && 
 			 Show[D.TargetPkg()->ID] != ToShow)
 			 Show[D.TargetPkg()->ID] != ToShow)
@@ -1060,9 +1055,7 @@ bool Dotty(CommandLine &CmdL)
 	       {
 	       {
 		  /* If a conflicts does not meet anything in the database
 		  /* If a conflicts does not meet anything in the database
 		     then show the relation but do not recurse */
 		     then show the relation but do not recurse */
-		  if (Hit == false && 
-		      (D->Type == pkgCache::Dep::Conflicts ||
-		       D->Type == pkgCache::Dep::Obsoletes))
+		  if (Hit == false && D.IsNegative() == true)
 		  {
 		  {
 		     if (Show[D.TargetPkg()->ID] == None && 
 		     if (Show[D.TargetPkg()->ID] == None && 
 			 Show[D.TargetPkg()->ID] != ToShow)
 			 Show[D.TargetPkg()->ID] != ToShow)
@@ -1082,6 +1075,7 @@ bool Dotty(CommandLine &CmdL)
 	       {
 	       {
 		  case pkgCache::Dep::Conflicts:
 		  case pkgCache::Dep::Conflicts:
 		  case pkgCache::Dep::Obsoletes:
 		  case pkgCache::Dep::Obsoletes:
+		  case pkgCache::Dep::DpkgBreaks:
 		  printf("[color=springgreen];\n");
 		  printf("[color=springgreen];\n");
 		  break;
 		  break;