summaryrefslogtreecommitdiff
path: root/apt-pkg/solver3.h
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2025-05-27 14:24:09 +0200
committerJulian Andres Klode <jak@debian.org>2025-05-27 15:56:55 +0200
commiteafc52e942d4daec30fb80e70c035ed935f31afb (patch)
tree31212d8b67e0f15ff2475f836157376caa262a87 /apt-pkg/solver3.h
parent88adaff17023b0c916fc3227dc25d0b95128d7f0 (diff)
solver3: Merge intersecting dependencies
If a package declares multiple dependencies that can be solved by the same packages we should use the common set of packages to solve them. A common example is requiring the same Debian source version, or the same upstream version as in our test case: git-ng Depends: git (>> 1:2.26.2), git (<< 1:2.26.2-.) The solver expands this to the concrete objects: git-ng Depends: "real git" (= 1:2.26.2-1) | chaos-actor, "real git" (= 1:2.26.2-1) | "real git" (= 1:2.25.1-1) When given an upgrade request, the solver would now choose chaos-actor to satisfy git (>> 1:2.26.2) "real git" (= 1:2.25.1-1) to satisfy git (<< 1:2.26.2-.) To satisfy the two constraints, which is not the intended outcome. Address this problem by introducing a concept of merged clauses: If two dependencies of a package have overlapping solutions, replace the dependency by the intersection, and record the merged clause instead, this leads to a single clause: Depends: git (>> 1:2.26.2) and git (<< 1:2.26.2-.) which expands to just the real git binary. The implementation is a bit finicky in that it removes the variables from the original clause which may not be helpful for debugging, but it records the clauses merged with, as seen in the test case, so the reasoning is clear. LP: #2111792
Diffstat (limited to 'apt-pkg/solver3.h')
-rw-r--r--apt-pkg/solver3.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/apt-pkg/solver3.h b/apt-pkg/solver3.h
index 590b187cc..a333d684a 100644
--- a/apt-pkg/solver3.h
+++ b/apt-pkg/solver3.h
@@ -404,9 +404,12 @@ struct APT::Solver::Clause
// \brief A negative clause negates the solutions, that is X->A|B you get X->!(A|B), aka X->!A&!B
bool negative;
+ // Clauses merged with this clause
+ std::forward_list<Clause> merged;
+
inline Clause(Var reason, Group group, bool optional = false, bool negative = false) : reason(reason), group(group), optional(optional), negative(negative) {}
- std::string toString(pkgCache &cache, bool pretty = false) const;
+ std::string toString(pkgCache &cache, bool pretty = false, bool showMerged = true) const;
};
/**