]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
add solver_alternative2str
authorMichael Schroeder <mls@suse.de>
Wed, 4 Mar 2015 12:23:50 +0000 (13:23 +0100)
committerMichael Schroeder <mls@suse.de>
Wed, 4 Mar 2015 12:23:50 +0000 (13:23 +0100)
src/libsolv.ver
src/solver.c
src/solver.h

index c8601714c0181c094b96b18998e52ad5d086f5ce..c795b7acc3460505a5b56a3986d61875bd982173 100644 (file)
@@ -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;
index 842bf167d214fc316f83299919039b39b87328e8..d3260e43920acee6647871e09fe5a13a9a431826 100644 (file)
@@ -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";
+}
+
index 9904bd9ce51ee8b23e100679a8d3de5804ef0a44..1cb9f15d1c98bff7f54ecfeef05c486829d1477f 100644 (file)
@@ -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)                             \