From 9f3ecca2b32e4fe56a05811392e01416092f85fa Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 17 Feb 2026 10:28:17 +0100 Subject: solver3: Upgrade by source package Implement the "APT::Get::Upgrade-By-Source-Package" option as the classic solver does. Here this is equally straight forward now: We enqueue optional, but eager, clauses of the form foo=2 -> foo-data=2 for each sibling in the source version, assuming they are currently installed, and the selection is not the current version. This softly enforces upgrades of already installed siblings, but in non-strict-pinning mode it will not affect the selection of new packages to be installed. A more complete solution to version selection by source package also seems feasible, where we change the "priority" of versions in the solver dynamically - currently they are statically evaluated. Such that, when you select foo=2, and something installs foo-data, foo-data would be installed in version 2 even if version 3 were its candidate. --- apt-pkg/solver3.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'apt-pkg/solver3.cc') diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc index 6d818ed67..bfc187ea6 100644 --- a/apt-pkg/solver3.cc +++ b/apt-pkg/solver3.cc @@ -972,6 +972,25 @@ void DependencySolver::Discover(Var var) RegisterClause(std::move(clause)); } + if (UpgradeBySourcePackage && Ver != Ver.ParentPkg().CurrentVer()) + { + // For this version selection, if I have other binaries in the source package that are currently installed, + // mark them for upgrade using an eager optional dependency (which is executed soon, but can be skipped) + for (auto sibling = Ver.SourceVersion().Group().VersionsInSource(); not sibling.end(); sibling = sibling.NextInSource()) + { + // Package is the same; not installed or at right version, don't need to upgrade + if (sibling->ParentPkg == Ver->ParentPkg || not sibling.ParentPkg()->CurrentVer || sibling.ParentPkg().CurrentVer() == sibling) + continue; + // Package has a different source version than us, so it's not relevant + if (strcmp(sibling.SourceVersion().VerStr(), Ver.SourceVersion().VerStr()) != 0) + continue; + Clause clause{Var(Ver), Group::SelectVersion, true /* optional */}; + clause.eager = true; + clause.solutions = {Var(sibling)}; + RegisterClause(std::move(clause)); + } + } + for (auto dep = Ver.DependsList(); not dep.end();) { // Compute a single dependency element (glob or) -- cgit v1.2.3-70-g09d2