2 * Copyright (c) 2007-2009, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * Transaction handling
20 #include "transaction.h"
28 obsq_sortcmp(const void *ap, const void *bp, void *dp)
32 Solvable *s, *oas, *obs;
43 s = pool->solvables + a;
44 oas = pool->solvables + oa;
45 obs = pool->solvables + ob;
46 if (oas->name != obs->name)
48 if (oas->name == s->name)
50 if (obs->name == s->name)
52 return strcmp(id2str(pool, oas->name), id2str(pool, obs->name));
54 r = evrcmp(pool, oas->evr, obs->evr, EVRCMP_COMPARE);
56 return -r; /* highest version first */
61 solver_transaction_all_pkgs(Transaction *trans, Id p, Queue *pkgs)
63 Pool *pool = trans->pool;
64 Solvable *s = pool->solvables + p;
65 Queue *ti = &trans->transaction_info;
70 if (p <= 0 || !s->repo)
72 if (s->repo == pool->installed)
74 q = trans->transaction_installed[p - pool->installed->start];
82 /* find which packages obsolete us */
83 for (i = 0; i < ti->count; i += 2)
84 if (ti->elements[i + 1] == p)
87 queue_push(pkgs, ti->elements[i]);
91 sat_sort(pkgs->elements, pkgs->count / 2, 2 * sizeof(Id), obsq_sortcmp, pool);
92 for (i = 0; i < pkgs->count; i += 2)
93 pkgs->elements[i / 2] = pkgs->elements[i + 1];
98 /* find the packages we obsolete */
99 for (i = 0; i < ti->count; i += 2)
101 if (ti->elements[i] == p)
102 queue_push(pkgs, ti->elements[i + 1]);
103 else if (pkgs->count)
110 solver_transaction_pkg(Transaction *trans, Id p)
112 Pool *pool = trans->pool;
113 Solvable *s = pool->solvables + p;
117 if (p <= 0 || !s->repo)
119 if (s->repo == pool->installed)
121 p = trans->transaction_installed[p - pool->installed->start];
122 return p < 0 ? -p : p;
124 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
125 solver_transaction_all_pkgs(trans, p, &ti);
126 p = ti.count ? ti.elements[0] : 0;
131 /* type filtering, needed if either not all packages are shown
132 * or replaces are not shown, as otherwise parts of the
133 * transaction might not be shown to the user */
136 solver_transaction_show(Transaction *trans, Id type, Id p, int flags)
138 Pool *pool = trans->pool;
139 Solvable *s = pool->solvables + p;
144 if (type == SOLVER_TRANSACTION_ERASE || type == SOLVER_TRANSACTION_INSTALL || type == SOLVER_TRANSACTION_MULTIINSTALL)
147 if (s->repo == pool->installed && (flags & SOLVER_TRANSACTION_SHOW_ACTIVE) == 0)
150 if ((flags & SOLVER_TRANSACTION_SHOW_REPLACES) == 0 && type == SOLVER_TRANSACTION_REPLACED)
151 type = SOLVER_TRANSACTION_ERASE;
154 if (s->repo != pool->installed && (flags & SOLVER_TRANSACTION_SHOW_ACTIVE) != 0)
156 if ((flags & SOLVER_TRANSACTION_SHOW_REPLACES) == 0 && type == SOLVER_TRANSACTION_REPLACE)
157 type = SOLVER_TRANSACTION_INSTALL;
161 /* most of the time there's only one reference, so check it first */
162 q = solver_transaction_pkg(trans, p);
163 if ((flags & SOLVER_TRANSACTION_SHOW_REPLACES) == 0)
165 Solvable *sq = pool->solvables + q;
166 if (sq->name != s->name)
168 if (s->repo == pool->installed)
169 return SOLVER_TRANSACTION_ERASE;
170 else if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
171 return SOLVER_TRANSACTION_MULTIINSTALL;
173 return SOLVER_TRANSACTION_INSTALL;
176 if (solver_transaction_pkg(trans, q) == p)
179 /* too bad, a miss. check em all */
182 solver_transaction_all_pkgs(trans, p, &oq);
183 for (i = 0; i < oq.count; i++)
186 if ((flags & SOLVER_TRANSACTION_SHOW_REPLACES) == 0)
188 Solvable *sq = pool->solvables + q;
189 if (sq->name != s->name)
192 /* check if we are referenced? */
193 if ((flags & SOLVER_TRANSACTION_SHOW_ALL) != 0)
195 solver_transaction_all_pkgs(trans, q, &rq);
196 for (j = 0; j < rq.count; j++)
197 if (rq.elements[j] == p)
205 else if (solver_transaction_pkg(trans, q) == p)
216 if (s->repo == pool->installed)
217 type = SOLVER_TRANSACTION_ERASE;
218 else if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
219 type = SOLVER_TRANSACTION_MULTIINSTALL;
221 type = SOLVER_TRANSACTION_INSTALL;
227 create_transaction_info(Transaction *trans, Queue *decisionq, Map *noobsmap)
229 Pool *pool = trans->pool;
230 Queue *ti = &trans->transaction_info;
231 Repo *installed = pool->installed;
238 return; /* no info needed */
239 for (i = 0; i < decisionq->count; i++)
241 p = decisionq->elements[i];
242 if (p <= 0 || p == SYSTEMSOLVABLE)
244 s = pool->solvables + p;
245 if (s->repo == installed)
247 noobs = noobsmap && MAPTST(noobsmap, p);
248 FOR_PROVIDES(p2, pp2, s->name)
250 if (!MAPTST(&trans->transactsmap, p2))
252 s2 = pool->solvables + p2;
253 if (s2->repo != installed)
255 if (noobs && (s->name != s2->name || s->evr != s2->evr || s->arch != s2->arch))
257 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
262 if (s->obsoletes && !noobs)
264 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
265 while ((obs = *obsp++) != 0)
267 FOR_PROVIDES(p2, pp2, obs)
269 s2 = pool->solvables + p2;
270 if (s2->repo != installed)
272 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
280 sat_sort(ti->elements, ti->count / 2, 2 * sizeof(Id), obsq_sortcmp, pool);
282 for (i = j = 0; i < ti->count; i += 2)
284 if (j && ti->elements[i] == ti->elements[j - 2] && ti->elements[i + 1] == ti->elements[j - 1])
286 ti->elements[j++] = ti->elements[i];
287 ti->elements[j++] = ti->elements[i + 1];
291 /* create transaction_installed helper */
292 trans->transaction_installed = sat_calloc(installed->end - installed->start, sizeof(Id));
293 for (i = 0; i < ti->count; i += 2)
295 j = ti->elements[i + 1] - installed->start;
296 if (!trans->transaction_installed[j])
297 trans->transaction_installed[j] = ti->elements[i];
300 /* more than one package obsoletes us. compare */
302 if (trans->transaction_installed[j] > 0)
303 trans->transaction_installed[j] = -trans->transaction_installed[j];
304 q[0] = q[2] = ti->elements[i + 1];
305 q[1] = ti->elements[i];
306 q[3] = -trans->transaction_installed[j];
307 if (obsq_sortcmp(q, q + 2, pool) < 0)
308 trans->transaction_installed[j] = -ti->elements[i];
314 transaction_init(Transaction *trans, Pool *pool)
316 memset(trans, 0, sizeof(*trans));
321 transaction_free(Transaction *trans)
323 queue_free(&trans->steps);
324 queue_free(&trans->transaction_info);
325 trans->transaction_installed = sat_free(trans->transaction_installed);
326 map_free(&trans->transactsmap);
330 transaction_calculate(Transaction *trans, Queue *decisionq, Map *noobsmap)
332 Pool *pool = trans->pool;
333 Repo *installed = pool->installed;
338 if (noobsmap && !noobsmap->size)
339 noobsmap = 0; /* ignore empty map */
340 queue_empty(&trans->steps);
341 map_init(&trans->transactsmap, pool->nsolvables);
342 for (i = 0; i < decisionq->count; i++)
344 p = decisionq->elements[i];
345 s = pool->solvables + (p > 0 ? p : -p);
348 if (installed && s->repo == installed && p < 0)
349 MAPSET(&trans->transactsmap, -p);
350 if ((!installed || s->repo != installed) && p > 0)
351 MAPSET(&trans->transactsmap, p);
353 create_transaction_info(trans, decisionq, noobsmap);
357 FOR_REPO_SOLVABLES(installed, p, s)
359 if (!MAPTST(&trans->transactsmap, p))
361 p2 = solver_transaction_pkg(trans, p);
363 queue_push(&trans->steps, SOLVER_TRANSACTION_ERASE);
366 s2 = pool->solvables + p2;
367 if (s->name == s2->name)
369 if (s->evr == s2->evr && solvable_identical(s, s2))
370 queue_push(&trans->steps, SOLVER_TRANSACTION_REINSTALLED);
373 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
375 queue_push(&trans->steps, SOLVER_TRANSACTION_UPGRADED);
377 queue_push(&trans->steps, SOLVER_TRANSACTION_DOWNGRADED);
379 queue_push(&trans->steps, SOLVER_TRANSACTION_CHANGED);
383 queue_push(&trans->steps, SOLVER_TRANSACTION_REPLACED);
385 queue_push(&trans->steps, p);
388 for (i = 0; i < decisionq->count; i++)
390 p = decisionq->elements[i];
391 if (p < 0 || p == SYSTEMSOLVABLE)
393 s = pool->solvables + p;
394 if (installed && s->repo == installed)
396 noobs = noobsmap && MAPTST(noobsmap, p);
397 p2 = solver_transaction_pkg(trans, p);
399 queue_push(&trans->steps, p2 ? SOLVER_TRANSACTION_MULTIREINSTALL : SOLVER_TRANSACTION_MULTIINSTALL);
401 queue_push(&trans->steps, SOLVER_TRANSACTION_INSTALL);
404 s2 = pool->solvables + p2;
405 if (s->name == s2->name)
407 if (s->evr == s2->evr && solvable_identical(s, s2))
408 queue_push(&trans->steps, SOLVER_TRANSACTION_REINSTALL);
411 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
413 queue_push(&trans->steps, SOLVER_TRANSACTION_UPGRADE);
415 queue_push(&trans->steps, SOLVER_TRANSACTION_DOWNGRADE);
417 queue_push(&trans->steps, SOLVER_TRANSACTION_CHANGE);
421 queue_push(&trans->steps, SOLVER_TRANSACTION_REPLACE);
423 queue_push(&trans->steps, p);
427 #define TYPE_BROKEN (1<<0)
428 #define TYPE_CON (1<<1)
430 #define TYPE_REQ_P (1<<2)
431 #define TYPE_PREREQ_P (1<<3)
433 #define TYPE_REQ (1<<4)
434 #define TYPE_PREREQ (1<<5)
436 #define EDGEDATA_BLOCK 127
445 Id ddeg; /* unused */
459 addedge(struct orderdata *od, Id from, Id to, int type)
461 Transaction *trans = od->trans;
462 Pool *pool = trans->pool;
467 // printf("addedge %d %d type %d\n", from, to, type);
468 s = pool->solvables + from;
469 if (s->repo == pool->installed && trans->transaction_installed[from - pool->installed->start])
471 /* passive, map to active */
472 if (trans->transaction_installed[from - pool->installed->start] > 0)
473 from = trans->transaction_installed[from - pool->installed->start];
480 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
481 solver_transaction_all_pkgs(trans, from, &ti);
482 for (i = 0; i < ti.count; i++)
483 ret |= addedge(od, ti.elements[i], to, type);
488 s = pool->solvables + to;
489 if (s->repo == pool->installed && trans->transaction_installed[to - pool->installed->start])
491 /* passive, map to active */
492 if (trans->transaction_installed[to - pool->installed->start] > 0)
493 to = trans->transaction_installed[to - pool->installed->start];
500 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
501 solver_transaction_all_pkgs(trans, to, &ti);
502 for (i = 0; i < ti.count; i++)
503 ret |= addedge(od, from, ti.elements[i], type);
509 /* map target to te num */
510 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
517 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
524 return 0; /* no edges to ourselfes */
526 /* printf("edge %d(%s) -> %d(%s) type %x\n", i, solvid2str(pool, od->tes[i].p), to, solvid2str(pool, od->tes[to].p), type); */
528 for (i = te->edges; od->edgedata[i]; i += 2)
529 if (od->edgedata[i] == to)
531 /* test of brokenness */
532 if (type == TYPE_BROKEN)
533 return od->edgedata[i] && (od->edgedata[i + 1] & TYPE_BROKEN) != 0 ? 1 : 0;
536 od->edgedata[i + 1] |= type;
539 if (i + 1 == od->nedgedata)
541 /* printf("tail add %d\n", i - te->edges); */
544 od->edgedata = sat_extend(od->edgedata, od->nedgedata, 3, sizeof(Id), EDGEDATA_BLOCK);
548 /* printf("extend %d\n", i - te->edges); */
549 od->edgedata = sat_extend(od->edgedata, od->nedgedata, 3 + (i - te->edges), sizeof(Id), EDGEDATA_BLOCK);
551 memcpy(od->edgedata + od->nedgedata, od->edgedata + te->edges, sizeof(Id) * (i - te->edges));
552 i = od->nedgedata + (i - te->edges);
553 te->edges = od->nedgedata;
555 od->edgedata[i] = to;
556 od->edgedata[i + 1] = type;
557 od->edgedata[i + 2] = 0;
558 od->nedgedata = i + 3;
565 havechoice(struct orderdata *od, Id p, Id q1, Id q2)
567 Transaction *trans = od->trans;
568 Pool *pool = trans->pool;
569 Id ti1buf[5], ti2buf[5];
573 /* both q1 and q2 are uninstalls. check if their TEs intersect */
574 /* common case: just one TE for both packages */
575 printf("havechoice %d %d %d\n", p, q1, q2);
576 if (trans->transaction_installed[q1 - pool->installed->start] == 0)
578 if (trans->transaction_installed[q2 - pool->installed->start] == 0)
580 if (trans->transaction_installed[q1 - pool->installed->start] == trans->transaction_installed[q2 - pool->installed->start])
582 if (trans->transaction_installed[q1 - pool->installed->start] > 0 && trans->transaction_installed[q2 - pool->installed->start] > 0)
584 queue_init_buffer(&ti1, ti1buf, sizeof(ti1buf)/sizeof(*ti1buf));
585 solver_transaction_all_pkgs(trans, q1, &ti1);
586 queue_init_buffer(&ti2, ti2buf, sizeof(ti2buf)/sizeof(*ti2buf));
587 solver_transaction_all_pkgs(trans, q2, &ti2);
588 for (i = 0; i < ti1.count; i++)
589 for (j = 0; j < ti2.count; j++)
590 if (ti1.elements[i] == ti2.elements[j])
592 /* found a common edge */
603 addsolvableedges(struct orderdata *od, Solvable *s)
605 Transaction *trans = od->trans;
606 Pool *pool = trans->pool;
607 Id req, *reqp, con, *conp;
609 int i, j, pre, numins;
610 Repo *installed = pool->installed;
614 p = s - pool->solvables;
618 reqp = s->repo->idarraydata + s->requires;
620 while ((req = *reqp++) != 0)
622 if (req == SOLVABLE_PREREQMARKER)
628 numins = 0; /* number of packages to be installed providing it */
629 FOR_PROVIDES(p2, pp2, req)
631 s2 = pool->solvables + p2;
634 reqq.count = 0; /* self provides */
637 if (s2->repo == installed && !MAPTST(&trans->transactsmap, p2))
639 reqq.count = 0; /* provided by package that stays installed */
642 if (s2->repo != installed && !MAPTST(&trans->transactsmap, p2))
643 continue; /* package stays uninstalled */
645 if (s->repo == installed)
647 /* s gets uninstalled */
648 queue_pushunique(&reqq, p2);
649 if (s2->repo != installed)
654 if (s2->repo == installed)
655 continue; /* s2 gets uninstalled */
656 queue_pushunique(&reqq, p2);
657 /* EDGE s(A) -> s2(A) */
660 if (numins && reqq.count)
662 /* no mixed types, remove all deps on uninstalls */
663 for (i = j = 0; i < reqq.count; i++)
664 if (pool->solvables[reqq.elements[i]].repo != installed)
665 reqq.elements[j++] = reqq.elements[i];
670 for (i = 0; i < reqq.count; i++)
673 p2 = reqq.elements[i];
674 if (pool->solvables[p2].repo != installed)
676 /* all elements of reqq are installs, thus have different TEs */
677 choice = reqq.count - 1;
678 if (pool->solvables[p].repo != installed)
681 printf("add inst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
683 addedge(od, p, p2, pre);
688 printf("add uninst->inst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
690 addedge(od, p, p2, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
697 for (j = 0; j < reqq.count; j++)
701 if (havechoice(od, p, reqq.elements[i], reqq.elements[j]))
706 printf("add uninst->uninst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
708 addedge(od, p2, p, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
715 conp = s->repo->idarraydata + s->conflicts;
716 while ((con = *conp++) != 0)
718 FOR_PROVIDES(p2, pp2, con)
722 s2 = pool->solvables + p2;
725 if (s->repo == installed)
727 if (s2->repo != installed && MAPTST(&trans->transactsmap, p2))
729 /* deinstall p before installing p2 */
730 addedge(od, p2, p, TYPE_CON);
735 if (s2->repo == installed && MAPTST(&trans->transactsmap, p2))
737 /* deinstall p2 before installing p */
738 addedge(od, p, p2, TYPE_CON);
749 haveprereq(Pool *pool, Id solvid)
751 Solvable *s = pool->solvables + solvid;
756 reqp = s->repo->idarraydata + s->requires;
757 while ((req = *reqp++) != 0)
759 if (req == SOLVABLE_PREREQMARKER)
764 if (inpre && strncmp(id2str(pool, req), "rpmlib(", 7) != 0)
772 breakcycle(struct orderdata *od, Id *cycle)
774 Pool *pool = od->trans->pool;
775 Id ddegmin, ddegmax, ddeg;
780 ddegmin = ddegmax = 0;
781 for (k = 0; cycle[k + 1]; k += 2)
783 MAPSET(&od->cycletes, cycle[k]); /* this te is involved in a cycle */
784 ddeg = od->edgedata[cycle[k + 1] + 1];
787 if (!k || ddeg < ddegmin)
795 if (haveprereq(pool, od->tes[cycle[l]].p) && !haveprereq(pool, od->tes[cycle[k]].p))
797 /* prefer k, as l comes from a package with contains scriptlets */
802 /* same edge value, check for prereq */
806 od->edgedata[cycle[l + 1] + 1] |= TYPE_BROKEN;
809 if (ddegmin < TYPE_REQ)
814 /* cycle recorded, print it */
815 if ((ddegmax & TYPE_PREREQ) != 0)
817 printf("cycle: --> ");
818 for (k = 0; cycle[k + 1]; k += 2)
820 te = od->tes + cycle[k];
821 if ((od->edgedata[cycle[k + 1] + 1] & TYPE_BROKEN) != 0)
822 printf("%s ##%x##> ", solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
824 printf("%s --%x--> ", solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
830 transaction_order(Transaction *trans)
832 Pool *pool = trans->pool;
833 Queue *tr = &trans->steps;
834 Repo *installed = pool->installed;
837 int i, j, k, numte, numedge;
841 int cycstart, cycel, broken;
842 Id *cycle, *obstypes;
846 POOL_DEBUG(SAT_DEBUG_STATS, "ordering transaction\n");
848 /* create a transaction element for every active component */
850 for (i = 0; i < tr->count; i += 2)
852 p = tr->elements[i + 1];
853 s = pool->solvables + p;
854 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
859 return; /* nothing to do... */
861 POOL_DEBUG(SAT_DEBUG_STATS, "transaction elements: %d\n", numte);
862 numte++; /* leave first one zero */
863 memset(&od, 0, sizeof(od));
866 od.tes = sat_calloc(numte, sizeof(*od.tes));
867 od.edgedata = sat_extend(0, 0, 1, sizeof(Id), EDGEDATA_BLOCK);
870 map_init(&od.cycletes, numte);
872 for (i = 0, te = od.tes + 1; i < tr->count; i += 2)
874 p = tr->elements[i + 1];
875 s = pool->solvables + p;
876 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
879 te->type = tr->elements[i];
880 te->medianr = solvable_lookup_num(s, SOLVABLE_MEDIANR, 0);
884 /* create dependency graph */
885 for (i = 0; i < tr->count; i += 2)
887 type = tr->elements[i];
888 p = tr->elements[i + 1];
889 addsolvableedges(&od, pool->solvables + p);
894 for (i = 1, te = od.tes + i; i < numte; i++, te++)
895 for (j = te->edges; od.edgedata[j]; j += 2)
897 POOL_DEBUG(SAT_DEBUG_STATS, "edges: %d, edge space: %d\n", numedge, od.nedgedata / 2);
898 POOL_DEBUG(SAT_DEBUG_STATS, "edge creation took %d ms\n", sat_timems(now));
900 /* kill all cycles */
904 for (i = numte - 1; i > 0; i--)
905 queue_push(&todo, i);
909 i = queue_pop(&todo);
910 /* printf("- look at TE %d\n", i); */
914 od.tes[i].mark = 2; /* done with that one */
919 continue; /* already finished before */
922 int edgestovisit = 0;
923 /* new node, visit edges */
924 for (j = te->edges; (k = od.edgedata[j]) != 0; j += 2)
926 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
928 if (od.tes[k].mark == 2)
929 continue; /* no need to visit again */
931 queue_push(&todo, -i); /* end of edges marker */
932 queue_push(&todo, k);
935 te->mark = 2; /* no edges, done with that one */
937 te->mark = 1; /* under investigation */
940 /* oh no, we found a cycle */
941 /* find start of cycle node (<0) */
942 for (j = todo.count - 1; j >= 0; j--)
943 if (todo.elements[j] == -i)
947 /* build te/edge chain */
949 for (j = k; j < todo.count; j++)
950 if (todo.elements[j] < 0)
951 todo.elements[k++] = -todo.elements[j];
952 cycel = k - cycstart;
954 /* make room for edges, two extra element for cycle loop + terminating 0 */
955 while (todo.count < cycstart + 2 * cycel + 2)
956 queue_push(&todo, 0);
957 cycle = todo.elements + cycstart;
958 cycle[cycel] = i; /* close the loop */
959 cycle[2 * cycel + 1] = 0; /* terminator */
960 for (k = cycel; k > 0; k--)
962 cycle[k * 2] = cycle[k];
963 te = od.tes + cycle[k - 1];
965 te->mark = 0; /* reset investigation marker */
966 /* printf("searching for edge from %d to %d\n", cycle[k - 1], cycle[k]); */
967 for (j = te->edges; od.edgedata[j]; j += 2)
968 if (od.edgedata[j] == cycle[k])
970 assert(od.edgedata[j]);
971 cycle[k * 2 - 1] = j;
973 /* now cycle looks like this: */
974 /* te1 edge te2 edge te3 ... teN edge te1 0 */
975 breakcycle(&od, cycle);
977 /* restart with start of cycle */
978 todo.count = cycstart + 1;
980 POOL_DEBUG(SAT_DEBUG_STATS, "cycles broken: %d\n", broken);
982 /* invert all edges */
983 for (i = 1, te = od.tes + i; i < numte; i++, te++)
985 te->invedges = 1; /* term 0 */
986 te->mark = 0; /* backref count */
989 for (i = 1, te = od.tes + i; i < numte; i++, te++)
991 for (j = te->edges; od.edgedata[j]; j += 2)
993 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
995 struct transel *te2 = od.tes + od.edgedata[j];
1000 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1005 POOL_DEBUG(SAT_DEBUG_STATS, "invedge space: %d\n", j + 1);
1006 od.invedgedata = sat_calloc(j + 1, sizeof(Id));
1007 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1009 for (j = te->edges; od.edgedata[j]; j += 2)
1011 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1013 struct transel *te2 = od.tes + od.edgedata[j];
1014 od.invedgedata[--te2->invedges] = i;
1018 /* now the final ordering */
1019 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1021 queue_push(&todo, i);
1022 assert(todo.count > 0);
1025 obstypes = sat_calloc(installed->end - installed->start, sizeof(Id));
1026 for (i = 0; i < tr->count; i += 2)
1028 p = tr->elements[i + 1];
1029 s = pool->solvables + p;
1030 if (s->repo == installed && trans->transaction_installed[p - installed->start])
1031 obstypes[p - installed->start] = tr->elements[i];
1036 oldcount = tr->count;
1046 for (i = 0; i < todo.count; i++)
1048 j = todo.elements[i];
1049 if (pool->solvables[od.tes[j].p].repo == installed)
1053 if (i == todo.count)
1055 for (i = 0; i < todo.count; i++)
1057 j = todo.elements[i];
1058 if (MAPTST(&od.cycletes, j))
1062 if (i == todo.count)
1064 te = od.tes + todo.elements[i];
1065 queue_push(tr, te->type);
1066 queue_push(tr, te->p);
1067 s = pool->solvables + te->p;
1068 if (installed && s->repo != installed)
1071 solver_transaction_all_pkgs(trans, te->p, &obsq);
1072 for (j = 0; j < obsq.count; j++)
1074 p = obsq.elements[j];
1075 assert(p >= installed->start && p < installed->end);
1076 if (obstypes[p - installed->start])
1078 queue_push(tr, obstypes[p - installed->start]);
1080 obstypes[p - installed->start] = 0;
1084 if (i < todo.count - 1)
1085 memmove(todo.elements + i, todo.elements + i + 1, (todo.count - 1 - i) * sizeof(Id));
1087 for (j = te->invedges; od.invedgedata[j]; j++)
1089 struct transel *te2 = od.tes + od.invedgedata[j];
1090 assert(te2->mark > 0);
1091 if (--te2->mark == 0)
1093 queue_push(&todo, od.invedgedata[j]);
1099 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1100 assert(te->mark == 0);
1101 assert(tr->count == oldcount);
1102 POOL_DEBUG(SAT_DEBUG_STATS, "transaction ordering took %d ms\n", sat_timems(now));