From: Michael Schroeder Date: Wed, 4 Mar 2015 12:23:50 +0000 (+0100) Subject: add solver_alternative2str X-Git-Tag: 0.6.9~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a88f9fc4297c707801d6488898daa0420ee234aa;p=thirdparty%2Flibsolv.git add solver_alternative2str --- diff --git a/src/libsolv.ver b/src/libsolv.ver index c8601714..c795b7ac 100644 --- a/src/libsolv.ver +++ b/src/libsolv.ver @@ -314,6 +314,7 @@ SOLV_1.0 { solvable_trivial_installable_repo; solvable_unset; solver_allruleinfos; + solver_alternative2str; solver_alternatives_count; solver_calc_duchanges; solver_calc_installsizechange; diff --git a/src/solver.c b/src/solver.c index 842bf167..d3260e43 100644 --- a/src/solver.c +++ b/src/solver.c @@ -5072,3 +5072,37 @@ pool_job2str(Pool *pool, Id how, Id what, Id flagmask) return pool_tmpappend(pool, s, "]", 0); } +const char * +solver_alternative2str(Solver *solv, int type, Id id, Id from) +{ + Pool *pool = solv->pool; + if (type == SOLVER_ALTERNATIVE_TYPE_RECOMMENDS) + { + 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]; + if (solver_ruleclass(solv, id) == SOLVER_RULE_CHOICE) + id = solver_rule2pkgrule(solv, id); + rtype = solver_ruleinfo(solv, id, &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)); + } + sprintf(buf, "Rule #%d", id); + return pool_tmpjoin(pool, buf, 0, 0); + } + return "unknown alternative type"; +} + diff --git a/src/solver.h b/src/solver.h index 9904bd9c..1cb9f15d 100644 --- a/src/solver.h +++ b/src/solver.h @@ -340,6 +340,8 @@ extern int pool_isemptyupdatejob(Pool *pool, Id how, Id what); extern const char *solver_select2str(Pool *pool, Id select, Id what); extern const char *pool_job2str(Pool *pool, Id how, Id what, Id flagmask); +extern const char *solver_alternative2str(Solver *solv, int type, Id id, Id from); + /* iterate over all literals of a rule */ #define FOR_RULELITERALS(l, pp, r) \