diff options
-rw-r--r-- | src/apk_database.h | 1 | ||||
-rw-r--r-- | src/database.c | 8 | ||||
-rw-r--r-- | src/solver.c | 24 |
3 files changed, 25 insertions, 8 deletions
diff --git a/src/apk_database.h b/src/apk_database.h index 2a7cb3b..2c8bdda 100644 --- a/src/apk_database.h +++ b/src/apk_database.h @@ -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; diff --git a/src/database.c b/src/database.c index 91fcedd..33cd32a 100644 --- a/src/database.c +++ b/src/database.c @@ -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); diff --git a/src/solver.c b/src/solver.c index 5522707..e1d8e2b 100644 --- a/src/solver.c +++ b/src/solver.c @@ -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; |