From: Michael Schroeder Date: Thu, 19 Mar 2015 15:42:16 +0000 (+0100) Subject: refactor complex deps code a bit X-Git-Tag: 0.6.11~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fe0a250c73b6ee6dc86107f8e715ae9ca7d0efe;p=thirdparty%2Flibsolv.git refactor complex deps code a bit --- diff --git a/src/cplxdeps.c b/src/cplxdeps.c index 9e421942..ad9457e6 100644 --- a/src/cplxdeps.c +++ b/src/cplxdeps.c @@ -68,6 +68,33 @@ expand_simpledeps(Pool *pool, Queue *bq, int start, int split) return newsplit; } +#ifdef CPLXDEBUG +static void +print_depblocks(Pool *pool, Queue *bq, int start) +{ + int i; + + for (i = start; i < bq->count; i++) + { + if (bq->elements[i] == pool->nsolvables) + { + Id *dp = pool->whatprovidesdata + bq->elements[++i]; + printf(" ("); + while (*dp) + printf(" %s", pool_solvid2str(pool, *dp++)); + printf(" )"); + } + else if (bq->elements[i] > 0) + printf(" %s", pool_solvid2str(pool, bq->elements[i])); + else if (bq->elements[i] < 0) + printf(" -%s", pool_solvid2str(pool, -bq->elements[i])); + else + printf(" ||"); + } + printf("\n"); +} +#endif + /* invert all literals in the blocks. note that this also turns DNF into CNF and vice versa */ static void invert_depblocks(Pool *pool, Queue *bq, int start) @@ -82,7 +109,7 @@ invert_depblocks(Pool *pool, Queue *bq, int start) bq->elements[i] = -bq->elements[i]; continue; } - /* end of block reached, reorder */ + /* end of block reached, reverse */ if (i - 1 > j) { int k; @@ -151,7 +178,7 @@ normalize_dep(Pool *pool, Id dep, Queue *bq, int todnf) /* get blocks of second argument */ bqcnt2 = bq->count; - /* COND is OR with NEG on evr block, so we invert the todnf flag in that case*/ + /* COND is OR with NEG on evr block, so we invert the todnf flag in that case */ r = normalize_dep(pool, rd->evr, bq, flags == REL_COND ? todnf ^ 1 : todnf); if (r == 0) { @@ -284,27 +311,7 @@ pool_normalize_complex_dep(Pool *pool, Id dep, Queue *bq, int flags) else if (i == 1) printf("ALL\n"); else - { - for (i = bqcnt; i < bq->count; i++) - { - if (bq->elements[i] == pool->nsolvables) - { - Id *dp = pool->whatprovidesdata + bq->elements[++i]; - printf(" ("); - while (*dp) - printf(" %s", pool_solvid2str(pool, *dp++)); - printf(" )"); - } - else if (bq->elements[i] > 0) - printf(" %s", pool_solvid2str(pool, bq->elements[i])); - else if (bq->elements[i] < 0) - printf(" -%s", pool_solvid2str(pool, -bq->elements[i])); - else - printf(" ||"); - } - printf("\n"); - i = -1; - } + print_depblocks(pool, bq, bqcnt); #endif return i; } diff --git a/src/rules.c b/src/rules.c index 88c6d5b4..039eb867 100644 --- a/src/rules.c +++ b/src/rules.c @@ -528,6 +528,17 @@ add_package_link(Solver *solv, Solvable *s, Map *m, Queue *workq) #ifdef ENABLE_COMPLEX_DEPS +static inline Id +pool_idstowhatprovides(Pool *pool, int count, Id *elements) +{ + /* hack: create fake queue 'q' so that we can call pool_queuetowhatprovides */ + Queue q; + memset(&q, 0, sizeof(q)); + q.count = count; + q.elements = elements; + return pool_queuetowhatprovides(pool, &q); +} + static void add_complex_deprules(Solver *solv, Id p, Id dep, int type, int dontfix, Queue *workq, Map *m) { @@ -667,12 +678,7 @@ add_complex_deprules(Solver *solv, Id p, Id dep, int type, int dontfix, Queue *w break; if (j == qcnt) { - /* hack: create fake queue 'q' so that we can call pool_queuetowhatprovides */ - Queue q; - memset(&q, 0, sizeof(q)); - q.count = qcnt - 1; - q.elements = qele + 1; - addpkgrule(solv, qele[0], pool_queuetowhatprovides(pool, &q), type, dep); + addpkgrule(solv, qele[0], pool_idstowhatprovides(pool, qcnt - 1, qele + 1), type, dep); if (m) for (j = 0; j < qcnt; j++) if (qele[j] > 0 && !MAPTST(m, qele[j]))