浏览代码

Merge pull request #118 from naderman/priority-replace-any-version

Replaced packages have higher priority even if wrong version is replaced
Jordi Boggiano 13 年之前
父节点
当前提交
d020f2701d

+ 14 - 3
src/Composer/DependencyResolver/DefaultPolicy.php

@@ -148,12 +148,23 @@ class DefaultPolicy implements PolicyInterface
         return ($this->getPriority($pool, $a) > $this->getPriority($pool, $b)) ? -1 : 1;
     }
 
+    /**
+    * Checks if source replaces a package with the same name as target.
+    *
+    * Replace constraints are ignored. This method should only be used for
+    * prioritisation, not for actual constraint verification.
+    *
+    * @param PackageInterface $source
+    * @param PackageInterface $target
+    * @return bool
+    */
     protected function replaces(PackageInterface $source, PackageInterface $target)
     {
         foreach ($source->getReplaces() as $link) {
-            if ($link->getTarget() === $target->getName() &&
-                (null === $link->getConstraint() ||
-                $link->getConstraint()->matches(new VersionConstraint('==', $target->getVersion())))) {
+            if ($link->getTarget() === $target->getName()
+//                && (null === $link->getConstraint() ||
+//                $link->getConstraint()->matches(new VersionConstraint('==', $target->getVersion())))) {
+                ) {
                 return true;
             }
         }

+ 2 - 2
src/Composer/DependencyResolver/RuleSet.php

@@ -160,9 +160,9 @@ class RuleSet implements \IteratorAggregate, \Countable
         foreach ($this->rules as $type => $rules) {
             $string .= str_pad(self::$types[$type], 8, ' ') . ": ";
             foreach ($rules as $rule) {
-                $string .= $rule;
+                $string .= $rule."\n";
             }
-            $string .= "\n";
+            $string .= "\n\n";
         }
 
         return $string;

+ 13 - 10
src/Composer/DependencyResolver/Solver.php

@@ -1746,12 +1746,14 @@ class Solver
 
         while (true) {
 
-            $conflictRule = $this->propagate($level);
-            if ($conflictRule !== null) {
-                if ($this->analyzeUnsolvable($conflictRule, $disableRules)) {
-                    continue;
-                } else {
-                    return;
+            if (1 === $level) {
+                $conflictRule = $this->propagate($level);
+                if ($conflictRule !== null) {
+                    if ($this->analyzeUnsolvable($conflictRule, $disableRules)) {
+                        continue;
+                    } else {
+                        return;
+                    }
                 }
             }
 
@@ -1987,7 +1989,11 @@ class Solver
                     return;
                 }
 
-                if ($level < $systemLevel || $level == 1) {
+                // open suse sat-solver uses this, but why is $level == 1 trouble?
+                // SYSTEMSOLVABLE related? we don't have that, so should work
+                //if ($level < $systemLevel || $level == 1) {
+
+                if ($level < $systemLevel) {
                     break; // trouble
                 }
 
@@ -1995,9 +2001,6 @@ class Solver
                 $n = -1;
             }
 
-//            $this->printDecisionMap();
-//            $this->printDecisionQueue();
-
             // minimization step
             if (count($this->branches)) {