]> git.saurik.com Git - apt.git/commitdiff
Determine the candidate based on per-version pins, instead of old code
authorJulian Andres Klode <jak@debian.org>
Mon, 10 Aug 2015 10:20:51 +0000 (12:20 +0200)
committerJulian Andres Klode <jak@debian.org>
Mon, 10 Aug 2015 10:28:23 +0000 (12:28 +0200)
The new implementation assigns each version a pin, instead of assigning
the pin to a package. This enables us to give each version of a package
a different priority.

Closes: #770017
Closes: #622237
Closes: #620249
Closes: #685215
apt-pkg/policy.cc
apt-pkg/policy.h

index 2d1f2a5d4cd4bb5b9881e1a70844e74df6837420..e1dc3aef5b8fd04d36f1c5f8ba19422fd8427f5c 100644 (file)
@@ -26,6 +26,7 @@
 #include <apt-pkg/cacheiterators.h>
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/versionmatch.h>
+#include <apt-pkg/version.h>
 
 #include <ctype.h>
 #include <stddef.h>
@@ -131,6 +132,10 @@ bool pkgPolicy::InitDefaults()
    best package is. */
 pkgCache::VerIterator pkgPolicy::GetCandidateVer(pkgCache::PkgIterator const &Pkg)
 {
+   if (_config->FindI("APT::Policy", 1) >= 1) {
+      return GetCandidateVerNew(Pkg);
+   }
+
    // Look for a package pin and evaluate it.
    signed Max = GetPriority(Pkg);
    pkgCache::VerIterator Pref = GetMatch(Pkg);
@@ -217,6 +222,37 @@ pkgCache::VerIterator pkgPolicy::GetCandidateVer(pkgCache::PkgIterator const &Pk
 
    return Pref;
 }
+
+// Policy::GetCandidateVer - Get the candidate install version         /*{{{*/
+// ---------------------------------------------------------------------
+/* Evaluate the package pins and the default list to deteremine what the
+   best package is. */
+pkgCache::VerIterator pkgPolicy::GetCandidateVerNew(pkgCache::PkgIterator const &Pkg)
+{
+   // TODO: Replace GetCandidateVer()
+   pkgCache::VerIterator cand;
+   int candPriority = -1;
+   bool candInstalled = false;
+   pkgVersioningSystem *vs = Cache->VS;
+
+   for (pkgCache::VerIterator ver = Pkg.VersionList(); ver.end() == false; ver++) {
+      int priority = GetPriority(ver);
+      bool installed = ver->ID == Pkg.CurrentVer()->ID;
+
+      if (priority < candPriority)
+        continue;
+      if (priority < 1000
+         && (priority == candPriority || installed < candInstalled)
+         && (cand.IsGood() && vs->CmpVersion(ver.VerStr(), cand.VerStr()) < 0))
+         continue;
+
+      candPriority = priority;
+      candInstalled = installed;
+      cand = ver;
+   }
+
+   return cand;
+}
                                                                        /*}}}*/
 // Policy::CreatePin - Create an entry in the pin table..              /*{{{*/
 // ---------------------------------------------------------------------
index 9deeb9d0eea489994871f1d4a619268e49e223ba..4efe2ec504aa90ccf7c7a02f0b9446aeff4fc769 100644 (file)
@@ -88,6 +88,7 @@ class pkgPolicy : public pkgDepCache::Policy
    pkgPolicy(pkgCache *Owner);
    virtual ~pkgPolicy();
    private:
+   pkgCache::VerIterator GetCandidateVerNew(pkgCache::PkgIterator const &Pkg);
    void *d;
 };