From: Michael Schroeder Date: Tue, 13 Dec 2022 09:45:55 +0000 (+0100) Subject: Add solver_alternativeinfo() function X-Git-Tag: 0.7.23~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a615b2f97b26050de61f498a8e043f25c98c14af;p=thirdparty%2Flibsolv.git Add solver_alternativeinfo() function This code is split off from the solver_alternative2str() function so that library users can offer translated messages. --- diff --git a/src/libsolv.ver b/src/libsolv.ver index a9cefa6d..402c2567 100644 --- a/src/libsolv.ver +++ b/src/libsolv.ver @@ -345,6 +345,7 @@ SOLV_1.0 { solver_allruleinfos; solver_allweakdepinfos; solver_alternative2str; + solver_alternativeinfo; solver_alternatives_count; solver_calc_decisioninfo_bits; solver_calc_duchanges; diff --git a/src/solver.c b/src/solver.c index 541917e1..fef27fdb 100644 --- a/src/solver.c +++ b/src/solver.c @@ -4708,6 +4708,50 @@ solver_get_alternative(Solver *solv, Id alternative, Id *idp, Id *fromp, Id *cho return elements[-4] ? SOLVER_ALTERNATIVE_TYPE_RECOMMENDS : SOLVER_ALTERNATIVE_TYPE_RULE; } +int +solver_alternativeinfo(Solver *solv, int type, Id id, Id from, Id *fromp, Id *top, Id *depp) +{ + if (fromp) + *fromp = 0; + if (top) + *top = 0; + if (depp) + *depp = 0; + if (type == SOLVER_ALTERNATIVE_TYPE_RECOMMENDS) + { + if (fromp) + *fromp = from; + if (depp) + *depp = id; + return SOLVER_RULE_PKG_RECOMMENDS; + } + else if (type == SOLVER_ALTERNATIVE_TYPE_RULE) + { + int rclass = solver_ruleclass(solv, id); + if (rclass == SOLVER_RULE_CHOICE || rclass == SOLVER_RULE_RECOMMENDS) + id = solver_rule2pkgrule(solv, id); + else if (rclass == SOLVER_RULE_BEST) + { + Id info = solv->bestrules_info[id - solv->bestrules]; + if (info > 0) + { + /* best update */ + if (fromp) + *fromp = info; + return SOLVER_RULE_UPDATE; + } + id = -info; /* best job, delegate to job rule */ + } + else if (rclass == SOLVER_RULE_LEARNT) + { + /* XXX: deconstruct learnt rules */ + return SOLVER_RULE_LEARNT; + } + return solver_ruleinfo(solv, id, fromp, top, depp); + } + return 0; +} + const char * solver_select2str(Pool *pool, Id select, Id what) { @@ -4862,43 +4906,32 @@ pool_job2str(Pool *pool, Id how, Id what, Id flagmask) const char * solver_alternative2str(Solver *solv, int type, Id id, Id from) { + const char *s; Pool *pool = solv->pool; - if (type == SOLVER_ALTERNATIVE_TYPE_RECOMMENDS) + Id to, dep; + type = solver_alternativeinfo(solv, type, id, from, &from, &to, &dep); + switch (type) { - const char *s = pool_dep2str(pool, id); - return pool_tmpappend(pool, s, ", recommended by ", pool_solvid2str(pool, from)); - } - if (type == SOLVER_ALTERNATIVE_TYPE_RULE) - { - int rtype; - Id depfrom, depto, dep; - char buf[64]; - int rclass = solver_ruleclass(solv, id); - if (rclass == SOLVER_RULE_CHOICE || rclass == SOLVER_RULE_RECOMMENDS) - id = solver_rule2pkgrule(solv, id); - rtype = solver_ruleinfo(solv, id, &depfrom, &depto, &dep); - if (rtype == SOLVER_RULE_BEST && depto > 0) - rtype = solver_ruleinfo(solv, depto, &depfrom, &depto, &dep); - if ((rtype & SOLVER_RULE_TYPEMASK) == SOLVER_RULE_JOB) - { - if ((depto & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_PROVIDES) - return pool_dep2str(pool, dep); - return solver_select2str(pool, depto & SOLVER_SELECTMASK, dep); - } - if (rtype == SOLVER_RULE_PKG_REQUIRES) - { - const char *s = pool_dep2str(pool, dep); - return pool_tmpappend(pool, s, ", required by ", pool_solvid2str(pool, depfrom)); - } - if (rtype == SOLVER_RULE_PKG_RECOMMENDS) - { - const char *s = pool_dep2str(pool, dep); - return pool_tmpappend(pool, s, ", recommended by ", pool_solvid2str(pool, depfrom)); - } - /* XXX: add deconstruction of learnt rules */ - sprintf(buf, "Rule #%d", id); - return pool_tmpjoin(pool, buf, 0, 0); + case SOLVER_RULE_PKG_RECOMMENDS: + s = pool_dep2str(pool, dep); + if (from) + s = pool_tmpappend(pool, s, ", recommended by ", pool_solvid2str(pool, from)); + return s; + case SOLVER_RULE_PKG_REQUIRES: + s = pool_dep2str(pool, dep); + if (from) + s = pool_tmpappend(pool, s, ", required by ", pool_solvid2str(pool, from)); + return s; + case SOLVER_RULE_JOB: + if ((to & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_PROVIDES) + return pool_dep2str(pool, dep); + return solver_select2str(pool, to & SOLVER_SELECTMASK, dep); + case SOLVER_RULE_UPDATE: + case SOLVER_RULE_FEATURE: + return pool_solvid2str(pool, from); + default: + break; } - return "unknown alternative type"; + return solver_ruleinfo2str(solv, type, from, to, dep); } diff --git a/src/solver.h b/src/solver.h index f89e1209..34c045e1 100644 --- a/src/solver.h +++ b/src/solver.h @@ -385,6 +385,7 @@ extern int solver_decisionlist_merged(Solver *solv, Queue *decisionlistq, int po extern int solver_alternatives_count(Solver *solv); extern int solver_get_alternative(Solver *solv, Id alternative, Id *idp, Id *fromp, Id *chosenp, Queue *choices, int *levelp); +extern int solver_alternativeinfo(Solver *solv, int type, Id id, Id from, Id *fromp, Id *top, Id *depp); extern void solver_calculate_multiversionmap(Pool *pool, Queue *job, Map *multiversionmap); extern void solver_calculate_noobsmap(Pool *pool, Queue *job, Map *multiversionmap); /* obsolete */