Merge remote-tracking branch 'donkult/feature/generalize-gzipindex' into debian/sid
[ntk/apt.git] / apt-pkg / algorithms.cc
index db1ebd7..608ec7f 100644 (file)
 #include <apt-pkg/algorithms.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/configuration.h>
-#include <apt-pkg/version.h>
 #include <apt-pkg/sptr.h>
-#include <apt-pkg/acquire-item.h>
 #include <apt-pkg/edsp.h>
-#include <apt-pkg/sourcelist.h>
-#include <apt-pkg/fileutl.h>
 #include <apt-pkg/progress.h>
+#include <apt-pkg/depcache.h>
+#include <apt-pkg/packagemanager.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
 
-#include <sys/types.h>
+#include <string.h>
+#include <string>
 #include <cstdlib>
-#include <algorithm>
 #include <iostream>
-#include <stdio.h>
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -446,26 +445,34 @@ void pkgProblemResolver::MakeScores()
          || (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important)
         Score += PrioEssentials;
 
-      // We transform the priority
-      if (Cache[I].InstVerIter(Cache)->Priority <= 5)
-        Score += PrioMap[Cache[I].InstVerIter(Cache)->Priority];
-      
+      pkgCache::VerIterator const InstVer = Cache[I].InstVerIter(Cache);
+      // We apply priorities only to downloadable packages, all others are prio:extra
+      // as an obsolete prio:standard package can't be that standard anymore…
+      if (InstVer->Priority <= pkgCache::State::Extra && InstVer.Downloadable() == true)
+        Score += PrioMap[InstVer->Priority];
+      else
+        Score += PrioMap[pkgCache::State::Extra];
+
       /* This helps to fix oddball problems with conflicting packages
-         on the same level. We enhance the score of installed packages 
-        if those are not obsolete
-      */
+        on the same level. We enhance the score of installed packages
+        if those are not obsolete */
       if (I->CurrentVer != 0 && Cache[I].CandidateVer != 0 && Cache[I].CandidateVerIter(Cache).Downloadable())
         Score += PrioInstalledAndNotObsolete;
-   }
 
-   // Now that we have the base scores we go and propagate dependencies
-   for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
-   {
-      if (Cache[I].InstallVer == 0)
-        continue;
-
-      for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; ++D)
-        Scores[D.TargetPkg()->ID] += DepMap[D->Type];
+      // propagate score points along dependencies
+      for (pkgCache::DepIterator D = InstVer.DependsList(); D.end() == false; ++D)
+      {
+        if (DepMap[D->Type] == 0)
+           continue;
+        pkgCache::PkgIterator const T = D.TargetPkg();
+        if (D->Version != 0)
+        {
+           pkgCache::VerIterator const IV = Cache[T].InstVerIter(Cache);
+           if (IV.end() == true || D.IsSatisfied(IV) != D.IsNegative())
+              continue;
+        }
+        Scores[T->ID] += DepMap[D->Type];
+      }
    }
 
    // Copy the scores to advoid additive looping
@@ -880,8 +887,8 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
                }
 
               if (Debug == true)
-                 clog << "  Considering " << Pkg.FullName(false) << ' ' << (int)Scores[Pkg->ID] <<
-                 " as a solution to " << I.FullName(false) << ' ' << (int)Scores[I->ID] << endl;
+                 clog << "  Considering " << Pkg.FullName(false) << ' ' << Scores[Pkg->ID] <<
+                 " as a solution to " << I.FullName(false) << ' ' << Scores[I->ID] << endl;
 
               /* Try to fix the package under consideration rather than
                  fiddle with the VList package */