Merge pull request #646 from vcunat/master

nix-env --upgrade improvements
This commit is contained in:
Eelco Dolstra 2015-09-17 12:45:35 +02:00
commit 3d91bfc8f8
2 changed files with 14 additions and 10 deletions

View file

@ -378,7 +378,7 @@ number of possible ways:
<variablelist> <variablelist>
<varlistentry><term><option>--prebuild-only</option> / <option>-b</option></term> <varlistentry><term><option>--prebuilt-only</option> / <option>-b</option></term>
<listitem><para>Use only derivations for which a substitute is <listitem><para>Use only derivations for which a substitute is
registered, i.e., there is a pre-built binary available that can registered, i.e., there is a pre-built binary available that can
@ -1012,7 +1012,7 @@ user environment elements, etc. -->
</varlistentry> </varlistentry>
<varlistentry><term><option>--prebuild-only</option> / <option>-b</option></term> <varlistentry><term><option>--prebuilt-only</option> / <option>-b</option></term>
<listitem><para>Show only derivations for which a substitute is <listitem><para>Show only derivations for which a substitute is
registered, i.e., there is a pre-built binary available that can registered, i.e., there is a pre-built binary available that can

View file

@ -570,14 +570,16 @@ static void upgradeDerivations(Globals & globals,
constraints specified by upgradeType. If there are constraints specified by upgradeType. If there are
multiple matches, take the one with the highest multiple matches, take the one with the highest
priority. If there are still multiple matches, priority. If there are still multiple matches,
take the one with the highest version. */ take the one with the highest version.
Do not upgrade if it would decrease the priority. */
DrvInfos::iterator bestElem = availElems.end(); DrvInfos::iterator bestElem = availElems.end();
DrvName bestName; string bestVersion;
for (auto j = availElems.begin(); j != availElems.end(); ++j) { for (auto j = availElems.begin(); j != availElems.end(); ++j) {
if (comparePriorities(*globals.state, i, *j) > 0)
continue;
DrvName newName(j->name); DrvName newName(j->name);
if (newName.name == drvName.name) { if (newName.name == drvName.name) {
int d = comparePriorities(*globals.state, i, *j); int d = compareVersions(drvName.version, newName.version);
if (d == 0) d = compareVersions(drvName.version, newName.version);
if ((upgradeType == utLt && d < 0) || if ((upgradeType == utLt && d < 0) ||
(upgradeType == utLeq && d <= 0) || (upgradeType == utLeq && d <= 0) ||
(upgradeType == utEq && d == 0) || (upgradeType == utEq && d == 0) ||
@ -586,11 +588,11 @@ static void upgradeDerivations(Globals & globals,
int d2 = -1; int d2 = -1;
if (bestElem != availElems.end()) { if (bestElem != availElems.end()) {
d2 = comparePriorities(*globals.state, *bestElem, *j); d2 = comparePriorities(*globals.state, *bestElem, *j);
if (d2 == 0) d2 = compareVersions(bestName.version, newName.version); if (d2 == 0) d2 = compareVersions(bestVersion, newName.version);
} }
if (d2 < 0 && (!globals.prebuiltOnly || isPrebuilt(*globals.state, *j))) { if (d2 < 0 && (!globals.prebuiltOnly || isPrebuilt(*globals.state, *j))) {
bestElem = j; bestElem = j;
bestName = newName; bestVersion = newName.version;
} }
} }
} }
@ -600,9 +602,11 @@ static void upgradeDerivations(Globals & globals,
i.queryOutPath() != i.queryOutPath() !=
bestElem->queryOutPath()) bestElem->queryOutPath())
{ {
const char * action = compareVersions(drvName.version, bestVersion) <= 0
? "upgrading" : "downgrading";
printMsg(lvlInfo, printMsg(lvlInfo,
format("upgrading %1% to %2%") format("%1% %2% to %3%")
% i.name % bestElem->name); % action % i.name % bestElem->name);
newElems.push_back(*bestElem); newElems.push_back(*bestElem);
} else newElems.push_back(i); } else newElems.push_back(i);