Skip to content

Commit 841ea42

Browse files
committed
Make disfavoring recommended packages work if strong recommends is enabled
Unfortunately this needs a new rule type, which is just the original recommends rule minus the disfavored packages.
1 parent 3714c1a commit 841ea42

6 files changed

Lines changed: 102 additions & 22 deletions

File tree

ext/testcase.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,8 @@ testcase_solverresult(Solver *solv, int resultflags)
20252025
/* map choice rules back to pkg rules */
20262026
if (solver_ruleclass(solv, id) == SOLVER_RULE_CHOICE)
20272027
id = solver_rule2pkgrule(solv, id);
2028+
if (solver_ruleclass(solv, id) == SOLVER_RULE_RECOMMENDS)
2029+
id = solver_rule2pkgrule(solv, id);
20282030
solver_allruleinfos(solv, id, &rq);
20292031
for (i = 0; i < rq.count; i += 4)
20302032
{

src/rules.c

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,13 +2740,11 @@ solver_ruleinfo(Solver *solv, Id rid, Id *fromp, Id *top, Id *depp)
27402740
return SOLVER_RULE_YUMOBS;
27412741
}
27422742
if (rid >= solv->choicerules && rid < solv->choicerules_end)
2743-
{
2744-
return SOLVER_RULE_CHOICE;
2745-
}
2743+
return SOLVER_RULE_CHOICE;
2744+
if (rid >= solv->recommendsrules && rid < solv->recommendsrules_end)
2745+
return SOLVER_RULE_RECOMMENDS;
27462746
if (rid >= solv->learntrules)
2747-
{
2748-
return SOLVER_RULE_LEARNT;
2749-
}
2747+
return SOLVER_RULE_LEARNT;
27502748
return SOLVER_RULE_UNKNOWN;
27512749
}
27522750

@@ -2773,6 +2771,8 @@ solver_ruleclass(Solver *solv, Id rid)
27732771
return SOLVER_RULE_YUMOBS;
27742772
if (rid >= solv->choicerules && rid < solv->choicerules_end)
27752773
return SOLVER_RULE_CHOICE;
2774+
if (rid >= solv->recommendsrules && rid < solv->recommendsrules_end)
2775+
return SOLVER_RULE_RECOMMENDS;
27762776
if (rid >= solv->learntrules && rid < solv->nrules)
27772777
return SOLVER_RULE_LEARNT;
27782778
return SOLVER_RULE_UNKNOWN;
@@ -2835,6 +2835,8 @@ solver_rule2pkgrule(Solver *solv, Id rid)
28352835
{
28362836
if (rid >= solv->choicerules && rid < solv->choicerules_end)
28372837
return solv->choicerules_ref[rid - solv->choicerules];
2838+
if (rid >= solv->recommendsrules && rid < solv->recommendsrules_end)
2839+
return solv->recommendsrules_info[rid - solv->recommendsrules];
28382840
return 0;
28392841
}
28402842

@@ -3634,6 +3636,54 @@ for (j = 0; j < qq.count; j++)
36343636
POOL_DEBUG(SOLV_DEBUG_STATS, "yumobs rule creation took %d ms\n", solv_timems(now));
36353637
}
36363638

3639+
/* recommendsrules are a copy of some recommends package rule but
3640+
* with some disfavored literals removed */
3641+
void
3642+
solver_addrecommendsrules(Solver *solv)
3643+
{
3644+
Pool *pool = solv->pool;
3645+
int i, havedis, havepos;
3646+
Id p, pp;
3647+
Queue q, infoq;
3648+
3649+
solv->recommendsrules = solv->nrules;
3650+
queue_init(&q);
3651+
queue_init(&infoq);
3652+
for (i = 0; i < solv->recommendsruleq->count; i++)
3653+
{
3654+
int rid = solv->recommendsruleq->elements[i];
3655+
Rule *r = solv->rules + rid;
3656+
queue_empty(&q);
3657+
havedis = havepos = 0;
3658+
FOR_RULELITERALS(p, pp, r)
3659+
{
3660+
if (p > 0 && solv->favormap[p] < 0)
3661+
havedis = 1;
3662+
else
3663+
{
3664+
if (p > 0)
3665+
havepos = 1;
3666+
queue_push(&q, p);
3667+
}
3668+
}
3669+
if (!havedis)
3670+
continue;
3671+
solver_disablerule(solv, r);
3672+
if (!havepos || q.count < 2)
3673+
continue;
3674+
if (q.count == 2)
3675+
solver_addrule(solv, q.elements[0], q.elements[1], 0);
3676+
else
3677+
solver_addrule(solv, q.elements[0], 0, pool_ids2whatprovides(pool, q.elements + 1, q.count - 1));
3678+
queue_push(&infoq, rid);
3679+
}
3680+
if (infoq.count)
3681+
solv->recommendsrules_info = solv_memdup2(infoq.elements, infoq.count, sizeof(Id));
3682+
queue_free(&infoq);
3683+
queue_free(&q);
3684+
solv->recommendsrules_end = solv->nrules;
3685+
}
3686+
36373687
void
36383688
solver_breakorphans(Solver *solv)
36393689
{

src/rules.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ typedef enum {
7171
SOLVER_RULE_CHOICE = 0x700,
7272
SOLVER_RULE_LEARNT = 0x800,
7373
SOLVER_RULE_BEST = 0x900,
74-
SOLVER_RULE_YUMOBS = 0xa00
74+
SOLVER_RULE_YUMOBS = 0xa00,
75+
SOLVER_RULE_RECOMMENDS = 0xb00
7576
} SolverRuleinfo;
7677

7778
#define SOLVER_RULE_TYPEMASK 0xff00
@@ -133,6 +134,9 @@ extern void solver_addbestrules(struct s_Solver *solv, int havebestinstalljobs);
133134
/* yumobs rules */
134135
extern void solver_addyumobsrules(struct s_Solver *solv);
135136

137+
/* recommends rules */
138+
extern void solver_addrecommendsrules(struct s_Solver *solv);
139+
136140
/* policy rule disabling/reenabling */
137141
extern void solver_disablepolicyrules(struct s_Solver *solv);
138142
extern void solver_reenablepolicyrules(struct s_Solver *solv, int jobidx);

src/solver.c

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -845,18 +845,19 @@ static void
845845
disable_recommendsrules(Solver *solv, Queue *weakq)
846846
{
847847
Pool *pool = solv->pool;
848-
int i;
848+
int i, rid;
849849
for (i = 0; i < weakq->count; i++)
850850
{
851-
Rule *r;
852-
if (!queue_contains(solv->recommendsruleq, weakq->elements[i]))
853-
continue;
854-
r = solv->rules + weakq->elements[i];
855-
if (r->d >= 0)
851+
rid = weakq->elements[i];
852+
if ((rid >= solv->recommendsrules && rid < solv->recommendsrules_end) || queue_contains(solv->recommendsruleq, rid))
856853
{
857-
POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "disabling ");
858-
solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, r);
859-
solver_disablerule(solv, r);
854+
Rule *r = solv->rules + rid;
855+
if (r->d >= 0)
856+
{
857+
POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "disabling ");
858+
solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, r);
859+
solver_disablerule(solv, r);
860+
}
860861
}
861862
}
862863
}
@@ -904,6 +905,18 @@ disable_weakrules(Solver *solv, Queue *weakq)
904905
for (i = 0; i < weakq->count; i++)
905906
if (weakq->elements[i] > lastweak)
906907
lastweak = weakq->elements[i];
908+
if (lastweak >= solv->recommendsrules && lastweak < solv->recommendsrules_end)
909+
{
910+
lastweak = 0;
911+
for (i = 0; i < weakq->count; i++)
912+
if (weakq->elements[i] < solv->recommendsrules && weakq->elements[i] > lastweak)
913+
lastweak = weakq->elements[i];
914+
if (lastweak < solv->pkgrules_end)
915+
{
916+
disable_recommendsrules(solv, weakq);
917+
return;
918+
}
919+
}
907920
if (lastweak < solv->pkgrules_end && solv->strongrecommends && solv->recommendsruleq && queue_contains(solv->recommendsruleq, lastweak))
908921
{
909922
disable_recommendsrules(solv, weakq);
@@ -1397,6 +1410,7 @@ solver_free(Solver *solv)
13971410
solv_free(solv->choicerules_ref);
13981411
solv_free(solv->bestrules_pkg);
13991412
solv_free(solv->yumobsrules_info);
1413+
solv_free(solv->recommendsrules_info);
14001414
solv_free(solv->instbuddy);
14011415
solv_free(solv);
14021416
}
@@ -3129,10 +3143,6 @@ addedmap2deduceq(Solver *solv, Map *addedmap)
31293143
for (; i < pool->nsolvables; i++)
31303144
if (MAPTST(addedmap, i))
31313145
queue_push(&solv->addedmap_deduceq, i);
3132-
j = 0;
3133-
for (i = 2; i < pool->nsolvables; i++)
3134-
if (MAPTST(addedmap, i))
3135-
j++;
31363146
}
31373147

31383148
static void
@@ -3284,6 +3294,7 @@ solver_solve(Solver *solv, Queue *job)
32843294
queue_empty(&solv->ruleassertions);
32853295
solv->bestrules_pkg = solv_free(solv->bestrules_pkg);
32863296
solv->yumobsrules_info = solv_free(solv->yumobsrules_info);
3297+
solv->recommendsrules_info = solv_free(solv->recommendsrules_info);
32873298
solv->choicerules_ref = solv_free(solv->choicerules_ref);
32883299
if (solv->noupdate.size)
32893300
map_empty(&solv->noupdate);
@@ -3354,9 +3365,9 @@ solver_solve(Solver *solv, Queue *job)
33543365
*/
33553366
initialnrules = solv->pkgrules_end ? solv->pkgrules_end : 1;
33563367
if (initialnrules > 1)
3357-
deduceq2addedmap(solv, &addedmap);
3368+
deduceq2addedmap(solv, &addedmap); /* also enables all pkg rules */
33583369
if (solv->nrules != initialnrules)
3359-
solver_shrinkrules(solv, initialnrules);
3370+
solver_shrinkrules(solv, initialnrules); /* shrink to just pkg rules */
33603371
solv->lastpkgrule = 0;
33613372
solv->pkgrules_end = 0;
33623373

@@ -3908,6 +3919,11 @@ solver_solve(Solver *solv, Queue *job)
39083919
else
39093920
solv->yumobsrules = solv->yumobsrules_end = solv->nrules;
39103921

3922+
if (solv->havedisfavored && solv->strongrecommends)
3923+
solver_addrecommendsrules(solv);
3924+
else
3925+
solv->recommendsrules = solv->recommendsrules_end = solv->nrules;
3926+
39113927
if (1)
39123928
solver_addchoicerules(solv);
39133929
else
@@ -4777,6 +4793,8 @@ solver_alternative2str(Solver *solv, int type, Id id, Id from)
47774793
char buf[64];
47784794
if (solver_ruleclass(solv, id) == SOLVER_RULE_CHOICE)
47794795
id = solver_rule2pkgrule(solv, id);
4796+
if (solver_ruleclass(solv, id) == SOLVER_RULE_RECOMMENDS)
4797+
id = solver_rule2pkgrule(solv, id);
47804798
rtype = solver_ruleinfo(solv, id, &depfrom, &depto, &dep);
47814799
if ((rtype & SOLVER_RULE_TYPEMASK) == SOLVER_RULE_JOB)
47824800
{

src/solver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ struct s_Solver {
8080
Id choicerules_end;
8181
Id *choicerules_ref;
8282

83+
Id recommendsrules; /* rules from recommends pkg rules with disfavored literals */
84+
Id recommendsrules_end;
85+
Id *recommendsrules_info; /* the original pkg rule rule */
86+
8387
Id learntrules; /* learnt rules, (end == nrules) */
8488

8589
Map noupdate; /* don't try to update these

src/solverdebug.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ solver_printruleclass(Solver *solv, int type, Rule *r)
128128
POOL_DEBUG(type, "FEATURE ");
129129
else if (p >= solv->yumobsrules && p < solv->yumobsrules_end)
130130
POOL_DEBUG(type, "YUMOBS ");
131+
else if (p >= solv->recommendsrules && p < solv->recommendsrules_end)
132+
POOL_DEBUG(type, "RECOMMENDS ");
131133
solver_printrule(solv, type, r);
132134
}
133135

0 commit comments

Comments
 (0)