Commit 47570f80 authored by Timo Teräs's avatar Timo Teräs

prefer selecting packages by their primary name

parent a86c8ed0
......@@ -101,6 +101,7 @@ struct apk_name {
struct apk_name_array *rinstall_if;
unsigned is_dependency : 1;
unsigned auto_select_virtual: 1;
unsigned priority : 2;
unsigned int foreach_genid;
union {
struct apk_solver_name_state ss;
......
......@@ -1439,9 +1439,11 @@ static int apk_db_name_rdepends(apk_hash_item item, void *pctx)
struct apk_provider *p;
struct apk_dependency *dep;
struct apk_name_array *touched;
unsigned num_virtual = 0;
apk_name_array_init(&touched);
foreach_array_item(p, name->providers) {
num_virtual += (p->pkg->name != name);
foreach_array_item(dep, p->pkg->depends) {
rname = dep->name;
rname->is_dependency |= !dep->conflict;
......@@ -1460,6 +1462,12 @@ static int apk_db_name_rdepends(apk_hash_item item, void *pctx)
}
}
}
if (num_virtual == 0)
name->priority = 0;
else if (num_virtual != name->providers->num)
name->priority = 1;
else
name->priority = 2;
foreach_array_item(n0, touched)
(*n0)->state_int = 0;
apk_name_array_free(&touched);
......
......@@ -972,6 +972,20 @@ static int cmp_pkgname(const void *p1, const void *p2)
return strcmp(d1->name->name, d2->name->name);
}
static int compare_name_dequeue(const struct apk_name *a, const struct apk_name *b)
{
int r;
r = (!!a->ss.requirers) - (!!b->ss.requirers);
if (r) return -r;
r = (int)a->priority - (int)b->priority;
if (r) return r;
r = a->ss.max_dep_chain - b->ss.max_dep_chain;
return -r;
}
int apk_solver_solve(struct apk_database *db,
unsigned short solver_flags,
struct apk_dependency_array *world,
......@@ -1022,14 +1036,8 @@ restart:
name = name0;
break;
}
if (name == NULL)
goto prefer;
if ((!!name0->ss.requirers) - (!!name->ss.requirers) < 0)
continue;
if (name0->ss.max_dep_chain - name->ss.max_dep_chain < 0)
continue;
prefer:
name = name0;
if (!name || compare_name_dequeue(name0, name) < 0)
name = name0;
}
if (name == NULL)
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment