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"
29 obsq_sortcmp(const void *ap, const void *bp, void *dp)
33 Solvable *s, *oas, *obs;
44 s = pool->solvables + a;
45 oas = pool->solvables + oa;
46 obs = pool->solvables + ob;
47 if (oas->name != obs->name)
49 if (oas->name == s->name)
51 if (obs->name == s->name)
53 return strcmp(pool_id2str(pool, oas->name), pool_id2str(pool, obs->name));
55 r = pool_evrcmp(pool, oas->evr, obs->evr, EVRCMP_COMPARE);
57 return -r; /* highest version first */
62 transaction_all_obs_pkgs(Transaction *trans, Id p, Queue *pkgs)
64 Pool *pool = trans->pool;
65 Solvable *s = pool->solvables + p;
66 Queue *ti = &trans->transaction_info;
71 if (p <= 0 || !s->repo)
73 if (s->repo == pool->installed)
75 q = trans->transaction_installed[p - pool->installed->start];
83 /* find which packages obsolete us */
84 for (i = 0; i < ti->count; i += 2)
85 if (ti->elements[i + 1] == p)
88 queue_push(pkgs, ti->elements[i]);
92 solv_sort(pkgs->elements, pkgs->count / 2, 2 * sizeof(Id), obsq_sortcmp, pool);
93 for (i = 0; i < pkgs->count; i += 2)
94 pkgs->elements[i / 2] = pkgs->elements[i + 1];
99 /* find the packages we obsolete */
100 for (i = 0; i < ti->count; i += 2)
102 if (ti->elements[i] == p)
103 queue_push(pkgs, ti->elements[i + 1]);
104 else if (pkgs->count)
111 transaction_obs_pkg(Transaction *trans, Id p)
113 Pool *pool = trans->pool;
114 Solvable *s = pool->solvables + p;
118 if (p <= 0 || !s->repo)
120 if (s->repo == pool->installed)
122 p = trans->transaction_installed[p - pool->installed->start];
123 return p < 0 ? -p : p;
125 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
126 transaction_all_obs_pkgs(trans, p, &ti);
127 p = ti.count ? ti.elements[0] : 0;
134 * calculate base type of transaction element
138 transaction_base_type(Transaction *trans, Id p)
140 Pool *pool = trans->pool;
145 if (!MAPTST(&trans->transactsmap, p))
146 return SOLVER_TRANSACTION_IGNORE;
147 p2 = transaction_obs_pkg(trans, p);
148 if (pool->installed && pool->solvables[p].repo == pool->installed)
152 return SOLVER_TRANSACTION_ERASE;
153 s = pool->solvables + p;
154 s2 = pool->solvables + p2;
155 if (s->name == s2->name)
157 if (s->evr == s2->evr && solvable_identical(s, s2))
158 return SOLVER_TRANSACTION_REINSTALLED;
159 r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
161 return SOLVER_TRANSACTION_UPGRADED;
163 return SOLVER_TRANSACTION_DOWNGRADED;
164 return SOLVER_TRANSACTION_CHANGED;
166 return SOLVER_TRANSACTION_OBSOLETED;
170 int noobs = trans->noobsmap.size && MAPTST(&trans->noobsmap, p);
172 return p2 ? SOLVER_TRANSACTION_MULTIREINSTALL : SOLVER_TRANSACTION_MULTIINSTALL;
174 return SOLVER_TRANSACTION_INSTALL;
175 s = pool->solvables + p;
176 s2 = pool->solvables + p2;
177 if (s->name == s2->name)
179 if (s->evr == s2->evr && solvable_identical(s, s2))
180 return SOLVER_TRANSACTION_REINSTALL;
181 r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
183 return SOLVER_TRANSACTION_UPGRADE;
185 return SOLVER_TRANSACTION_DOWNGRADE;
187 return SOLVER_TRANSACTION_CHANGE;
189 return SOLVER_TRANSACTION_OBSOLETES;
194 * return type of transaction element
196 * filtering is needed if either not all packages are shown
197 * or replaces are not shown, as otherwise parts of the
198 * transaction might not be shown to the user */
201 transaction_type(Transaction *trans, Id p, int mode)
203 Pool *pool = trans->pool;
204 Solvable *s = pool->solvables + p;
210 return SOLVER_TRANSACTION_IGNORE;
212 if (!(mode & SOLVER_TRANSACTION_KEEP_PSEUDO))
214 const char *n = pool_id2str(pool, s->name);
215 if (!strncmp(n, "patch:", 6))
216 return SOLVER_TRANSACTION_IGNORE;
217 if (!strncmp(n, "pattern:", 8))
218 return SOLVER_TRANSACTION_IGNORE;
221 type = transaction_base_type(trans, p);
223 if (type == SOLVER_TRANSACTION_IGNORE)
224 return SOLVER_TRANSACTION_IGNORE; /* not part of the transaction */
226 if ((mode & SOLVER_TRANSACTION_RPM_ONLY) != 0)
228 /* application wants to know what to feed to rpm */
229 if (type == SOLVER_TRANSACTION_ERASE || type == SOLVER_TRANSACTION_INSTALL || type == SOLVER_TRANSACTION_MULTIINSTALL)
231 if (s->repo == pool->installed)
232 return SOLVER_TRANSACTION_IGNORE; /* ignore as we're being obsoleted */
233 if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
234 return SOLVER_TRANSACTION_MULTIINSTALL;
235 return SOLVER_TRANSACTION_INSTALL;
238 if ((mode & SOLVER_TRANSACTION_SHOW_MULTIINSTALL) == 0)
240 /* application wants to make no difference between install
241 * and multiinstall */
242 if (type == SOLVER_TRANSACTION_MULTIINSTALL)
243 type = SOLVER_TRANSACTION_INSTALL;
244 if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
245 type = SOLVER_TRANSACTION_REINSTALL;
248 if ((mode & SOLVER_TRANSACTION_CHANGE_IS_REINSTALL))
250 /* application wants to make no difference between change
252 if (type == SOLVER_TRANSACTION_CHANGED)
253 type = SOLVER_TRANSACTION_REINSTALLED;
254 else if (type == SOLVER_TRANSACTION_CHANGE)
255 type = SOLVER_TRANSACTION_REINSTALL;
258 if (type == SOLVER_TRANSACTION_ERASE || type == SOLVER_TRANSACTION_INSTALL || type == SOLVER_TRANSACTION_MULTIINSTALL)
261 if (s->repo == pool->installed && (mode & SOLVER_TRANSACTION_SHOW_ACTIVE) == 0)
263 /* erase element and we're showing the passive side */
264 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0 && type == SOLVER_TRANSACTION_OBSOLETED)
265 type = SOLVER_TRANSACTION_ERASE;
268 if (s->repo != pool->installed && (mode & SOLVER_TRANSACTION_SHOW_ACTIVE) != 0)
270 /* install element and we're showing the active side */
271 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0 && type == SOLVER_TRANSACTION_OBSOLETES)
272 type = SOLVER_TRANSACTION_INSTALL;
276 /* the element doesn't match the show mode */
278 /* if we're showing all references, we can ignore this package */
279 if ((mode & (SOLVER_TRANSACTION_SHOW_ALL|SOLVER_TRANSACTION_SHOW_OBSOLETES)) == (SOLVER_TRANSACTION_SHOW_ALL|SOLVER_TRANSACTION_SHOW_OBSOLETES))
280 return SOLVER_TRANSACTION_IGNORE;
282 /* we're not showing all refs. check if some other package
283 * references us. If yes, it's safe to ignore this package,
284 * otherwise we need to map the type */
286 /* most of the time there's only one reference, so check it first */
287 q = transaction_obs_pkg(trans, p);
289 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
291 Solvable *sq = pool->solvables + q;
292 if (sq->name != s->name)
294 /* it's a replace but we're not showing replaces. map type. */
295 if (s->repo == pool->installed)
296 return SOLVER_TRANSACTION_ERASE;
297 else if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
298 return SOLVER_TRANSACTION_MULTIINSTALL;
300 return SOLVER_TRANSACTION_INSTALL;
304 /* if there's a match, p will be shown when q
306 if (transaction_obs_pkg(trans, q) == p)
307 return SOLVER_TRANSACTION_IGNORE;
309 /* too bad, a miss. check em all */
312 transaction_all_obs_pkgs(trans, p, &oq);
313 for (i = 0; i < oq.count; i++)
316 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
318 Solvable *sq = pool->solvables + q;
319 if (sq->name != s->name)
322 /* check if we are referenced? */
323 if ((mode & SOLVER_TRANSACTION_SHOW_ALL) != 0)
325 transaction_all_obs_pkgs(trans, q, &rq);
326 for (j = 0; j < rq.count; j++)
327 if (rq.elements[j] == p)
335 else if (transaction_obs_pkg(trans, q) == p)
346 /* we're not referenced. map type */
347 if (s->repo == pool->installed)
348 return SOLVER_TRANSACTION_ERASE;
349 else if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
350 return SOLVER_TRANSACTION_MULTIINSTALL;
352 return SOLVER_TRANSACTION_INSTALL;
354 /* there was a ref, so p is shown with some other package */
355 return SOLVER_TRANSACTION_IGNORE;
361 classify_cmp(const void *ap, const void *bp, void *dp)
363 Transaction *trans = dp;
364 Pool *pool = trans->pool;
374 return a[2] && b[2] ? strcmp(pool_id2str(pool, a[2]), pool_id2str(pool, b[2])) : r;
377 return a[3] && b[3] ? strcmp(pool_id2str(pool, a[3]), pool_id2str(pool, b[3])) : r;
382 classify_cmp_pkgs(const void *ap, const void *bp, void *dp)
384 Transaction *trans = dp;
385 Pool *pool = trans->pool;
390 sa = pool->solvables + a;
391 sb = pool->solvables + b;
392 if (sa->name != sb->name)
393 return strcmp(pool_id2str(pool, sa->name), pool_id2str(pool, sb->name));
394 if (sa->evr != sb->evr)
396 int r = pool_evrcmp(pool, sa->evr, sb->evr, EVRCMP_COMPARE);
404 transaction_classify(Transaction *trans, int mode, Queue *classes)
406 Pool *pool = trans->pool;
407 int ntypes[SOLVER_TRANSACTION_MAXTYPE + 1];
409 Id v, vq, type, p, q;
412 queue_empty(classes);
413 memset(ntypes, 0, sizeof(ntypes));
414 /* go through transaction and classify each step */
415 for (i = 0; i < trans->steps.count; i++)
417 p = trans->steps.elements[i];
418 s = pool->solvables + p;
419 type = transaction_type(trans, p, mode);
421 if (!pool->installed || s->repo != pool->installed)
423 /* don't report vendor/arch changes if we were mapped to erase. */
424 if (type == SOLVER_TRANSACTION_ERASE)
426 /* look at arch/vendor changes */
427 q = transaction_obs_pkg(trans, p);
430 sq = pool->solvables + q;
436 if ((mode & SOLVER_TRANSACTION_MERGE_ARCHCHANGES) != 0)
438 for (j = 0; j < classes->count; j += 4)
439 if (classes->elements[j] == SOLVER_TRANSACTION_ARCHCHANGE && classes->elements[j + 2] == v && classes->elements[j + 3] == vq)
441 if (j == classes->count)
443 queue_push(classes, SOLVER_TRANSACTION_ARCHCHANGE);
444 queue_push(classes, 1);
445 queue_push(classes, v);
446 queue_push(classes, vq);
449 classes->elements[j + 1]++;
452 v = s->vendor ? s->vendor : 1;
453 vq = sq->vendor ? sq->vendor : 1;
456 if ((mode & SOLVER_TRANSACTION_MERGE_VENDORCHANGES) != 0)
458 for (j = 0; j < classes->count; j += 4)
459 if (classes->elements[j] == SOLVER_TRANSACTION_VENDORCHANGE && classes->elements[j + 2] == v && classes->elements[j + 3] == vq)
461 if (j == classes->count)
463 queue_push(classes, SOLVER_TRANSACTION_VENDORCHANGE);
464 queue_push(classes, 1);
465 queue_push(classes, v);
466 queue_push(classes, vq);
469 classes->elements[j + 1]++;
472 /* now sort all vendor/arch changes */
473 if (classes->count > 4)
474 solv_sort(classes->elements, classes->count / 4, 4 * sizeof(Id), classify_cmp, trans);
475 /* finally add all classes. put erases last */
476 i = SOLVER_TRANSACTION_ERASE;
479 queue_unshift(classes, 0);
480 queue_unshift(classes, 0);
481 queue_unshift(classes, ntypes[i]);
482 queue_unshift(classes, i);
484 for (i = SOLVER_TRANSACTION_MAXTYPE; i > 0; i--)
488 if (i == SOLVER_TRANSACTION_ERASE)
490 queue_unshift(classes, 0);
491 queue_unshift(classes, 0);
492 queue_unshift(classes, ntypes[i]);
493 queue_unshift(classes, i);
498 transaction_classify_pkgs(Transaction *trans, int mode, Id class, Id from, Id to, Queue *pkgs)
500 Pool *pool = trans->pool;
506 for (i = 0; i < trans->steps.count; i++)
508 p = trans->steps.elements[i];
509 s = pool->solvables + p;
510 if (class <= SOLVER_TRANSACTION_MAXTYPE)
512 type = transaction_type(trans, p, mode);
517 if (!pool->installed || s->repo != pool->installed)
519 q = transaction_obs_pkg(trans, p);
522 sq = pool->solvables + q;
523 if (class == SOLVER_TRANSACTION_ARCHCHANGE)
525 if ((!from && !to) || (s->arch == from && sq->arch == to))
529 if (class == SOLVER_TRANSACTION_VENDORCHANGE)
531 Id v = s->vendor ? s->vendor : 1;
532 Id vq = sq->vendor ? sq->vendor : 1;
533 if ((!from && !to) || (v == from && vq == to))
539 solv_sort(pkgs->elements, pkgs->count, sizeof(Id), classify_cmp_pkgs, trans);
543 create_transaction_info(Transaction *trans, Queue *decisionq)
545 Pool *pool = trans->pool;
546 Queue *ti = &trans->transaction_info;
547 Repo *installed = pool->installed;
553 trans->transaction_installed = solv_free(trans->transaction_installed);
555 return; /* no info needed */
556 for (i = 0; i < decisionq->count; i++)
558 p = decisionq->elements[i];
559 if (p <= 0 || p == SYSTEMSOLVABLE)
561 s = pool->solvables + p;
562 if (!s->repo || s->repo == installed)
564 noobs = trans->noobsmap.size && MAPTST(&trans->noobsmap, p);
565 FOR_PROVIDES(p2, pp2, s->name)
567 if (!MAPTST(&trans->transactsmap, p2))
569 s2 = pool->solvables + p2;
570 if (s2->repo != installed)
572 if (noobs && (s->name != s2->name || s->evr != s2->evr || s->arch != s2->arch))
574 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
576 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
578 queue_push2(ti, p, p2);
580 if (s->obsoletes && !noobs)
582 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
583 while ((obs = *obsp++) != 0)
585 FOR_PROVIDES(p2, pp2, obs)
587 s2 = pool->solvables + p2;
588 if (s2->repo != installed)
590 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
592 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
594 queue_push2(ti, p, p2);
602 solv_sort(ti->elements, ti->count / 2, 2 * sizeof(Id), obsq_sortcmp, pool);
603 for (i = j = 2; i < ti->count; i += 2)
605 if (ti->elements[i] == ti->elements[j - 2] && ti->elements[i + 1] == ti->elements[j - 1])
607 ti->elements[j++] = ti->elements[i];
608 ti->elements[j++] = ti->elements[i + 1];
610 queue_truncate(ti, j);
613 /* create transaction_installed helper */
614 /* entry > 0: exactly one obsoleter, entry < 0: multiple obsoleters, -entry is "best" */
615 trans->transaction_installed = solv_calloc(installed->end - installed->start, sizeof(Id));
616 for (i = 0; i < ti->count; i += 2)
618 j = ti->elements[i + 1] - installed->start;
619 if (!trans->transaction_installed[j])
620 trans->transaction_installed[j] = ti->elements[i];
623 /* more than one package obsoletes us. compare to find "best" */
625 if (trans->transaction_installed[j] > 0)
626 trans->transaction_installed[j] = -trans->transaction_installed[j];
627 q[0] = q[2] = ti->elements[i + 1];
628 q[1] = ti->elements[i];
629 q[3] = -trans->transaction_installed[j];
630 if (obsq_sortcmp(q, q + 2, pool) < 0)
631 trans->transaction_installed[j] = -ti->elements[i];
638 transaction_create_decisionq(Pool *pool, Queue *decisionq, Map *noobsmap)
640 Repo *installed = pool->installed;
646 trans = transaction_create(pool);
647 if (noobsmap && !noobsmap->size)
648 noobsmap = 0; /* ignore empty map */
649 queue_empty(&trans->steps);
650 map_init(&trans->transactsmap, pool->nsolvables);
652 for (i = 0; i < decisionq->count; i++)
654 p = decisionq->elements[i];
655 s = pool->solvables + (p > 0 ? p : -p);
658 if (installed && s->repo == installed && p < 0)
659 MAPSET(&trans->transactsmap, -p);
660 if ((!installed || s->repo != installed) && p > 0)
663 const char *n = pool_id2str(pool, s->name);
664 if (!strncmp(n, "patch:", 6))
666 if (!strncmp(n, "pattern:", 8))
669 MAPSET(&trans->transactsmap, p);
670 if (noobsmap && MAPTST(noobsmap, p))
674 MAPCLR(&trans->transactsmap, SYSTEMSOLVABLE);
676 map_init_clone(&trans->noobsmap, noobsmap);
678 create_transaction_info(trans, decisionq);
682 FOR_REPO_SOLVABLES(installed, p, s)
684 if (MAPTST(&trans->transactsmap, p))
685 queue_push(&trans->steps, p);
688 for (i = 0; i < decisionq->count; i++)
690 p = decisionq->elements[i];
691 if (p > 0 && MAPTST(&trans->transactsmap, p))
692 queue_push(&trans->steps, p);
698 transaction_installedresult(Transaction *trans, Queue *installedq)
700 Pool *pool = trans->pool;
701 Repo *installed = pool->installed;
706 queue_empty(installedq);
707 /* first the new installs, than the kept packages */
708 for (i = 0; i < trans->steps.count; i++)
710 p = trans->steps.elements[i];
711 s = pool->solvables + p;
712 if (installed && s->repo == installed)
714 queue_push(installedq, p);
716 cutoff = installedq->count;
719 FOR_REPO_SOLVABLES(installed, p, s)
720 if (!MAPTST(&trans->transactsmap, p))
721 queue_push(installedq, p);
727 transaction_create_installedmap(Transaction *trans, Map *installedmap)
729 Pool *pool = trans->pool;
730 Repo *installed = pool->installed;
735 map_init(installedmap, pool->nsolvables);
736 for (i = 0; i < trans->steps.count; i++)
738 p = trans->steps.elements[i];
739 s = pool->solvables + p;
740 if (!installed || s->repo != installed)
741 MAPSET(installedmap, p);
745 FOR_REPO_SOLVABLES(installed, p, s)
746 if (!MAPTST(&trans->transactsmap, p))
747 MAPSET(installedmap, p);
752 transaction_calc_installsizechange(Transaction *trans)
757 transaction_create_installedmap(trans, &installedmap);
758 change = pool_calc_installsizechange(trans->pool, &installedmap);
759 map_free(&installedmap);
764 transaction_calc_duchanges(Transaction *trans, DUChanges *mps, int nmps)
768 transaction_create_installedmap(trans, &installedmap);
769 pool_calc_duchanges(trans->pool, &installedmap, mps, nmps);
770 map_free(&installedmap);
773 struct _TransactionElement {
774 Id p; /* solvable id */
775 Id edges; /* pointer into edges data */
779 struct _TransactionOrderdata {
780 struct _TransactionElement *tes;
786 #define TYPE_BROKEN (1<<0)
787 #define TYPE_CON (1<<1)
789 #define TYPE_REQ_P (1<<2)
790 #define TYPE_PREREQ_P (1<<3)
792 #define TYPE_REQ (1<<4)
793 #define TYPE_PREREQ (1<<5)
795 #define TYPE_CYCLETAIL (1<<16)
796 #define TYPE_CYCLEHEAD (1<<17)
798 #define EDGEDATA_BLOCK 127
801 transaction_create(Pool *pool)
803 Transaction *trans = solv_calloc(1, sizeof(*trans));
809 transaction_create_clone(Transaction *srctrans)
811 Transaction *trans = transaction_create(srctrans->pool);
812 queue_init_clone(&trans->steps, &srctrans->steps);
813 queue_init_clone(&trans->transaction_info, &srctrans->transaction_info);
814 if (srctrans->transaction_installed)
816 Repo *installed = srctrans->pool->installed;
817 trans->transaction_installed = solv_calloc(installed->end - installed->start, sizeof(Id));
818 memcpy(trans->transaction_installed, srctrans->transaction_installed, (installed->end - installed->start) * sizeof(Id));
820 map_init_clone(&trans->transactsmap, &srctrans->transactsmap);
821 map_init_clone(&trans->noobsmap, &srctrans->noobsmap);
822 if (srctrans->orderdata)
824 struct _TransactionOrderdata *od = srctrans->orderdata;
825 trans->orderdata = solv_calloc(1, sizeof(*trans->orderdata));
826 trans->orderdata->tes = solv_malloc2(od->ntes, sizeof(*od->tes));
827 memcpy(trans->orderdata->tes, od->tes, od->ntes * sizeof(*od->tes));
828 trans->orderdata->ntes = od->ntes;
829 trans->orderdata->invedgedata = solv_malloc2(od->ninvedgedata, sizeof(Id));
830 memcpy(trans->orderdata->invedgedata, od->invedgedata, od->ninvedgedata * sizeof(Id));
831 trans->orderdata->ninvedgedata = od->ninvedgedata;
837 transaction_free(Transaction *trans)
839 queue_free(&trans->steps);
840 queue_free(&trans->transaction_info);
841 trans->transaction_installed = solv_free(trans->transaction_installed);
842 map_free(&trans->transactsmap);
843 map_free(&trans->noobsmap);
844 transaction_free_orderdata(trans);
849 transaction_free_orderdata(Transaction *trans)
851 if (trans->orderdata)
853 struct _TransactionOrderdata *od = trans->orderdata;
854 od->tes = solv_free(od->tes);
855 od->invedgedata = solv_free(od->invedgedata);
856 trans->orderdata = solv_free(trans->orderdata);
862 struct _TransactionElement *tes;
874 addteedge(struct orderdata *od, int from, int to, int type)
877 struct _TransactionElement *te;
882 /* printf("edge %d(%s) -> %d(%s) type %x\n", from, pool_solvid2str(pool, od->tes[from].p), to, pool_solvid2str(pool, od->tes[to].p), type); */
885 for (i = te->edges; od->edgedata[i]; i += 2)
886 if (od->edgedata[i] == to)
888 /* test of brokenness */
889 if (type == TYPE_BROKEN)
890 return od->edgedata[i] && (od->edgedata[i + 1] & TYPE_BROKEN) != 0 ? 1 : 0;
893 od->edgedata[i + 1] |= type;
896 if (i + 1 == od->nedgedata)
898 /* printf("tail add %d\n", i - te->edges); */
901 od->edgedata = solv_extend(od->edgedata, od->nedgedata, 3, sizeof(Id), EDGEDATA_BLOCK);
905 /* printf("extend %d\n", i - te->edges); */
906 od->edgedata = solv_extend(od->edgedata, od->nedgedata, 3 + (i - te->edges), sizeof(Id), EDGEDATA_BLOCK);
908 memcpy(od->edgedata + od->nedgedata, od->edgedata + te->edges, sizeof(Id) * (i - te->edges));
909 i = od->nedgedata + (i - te->edges);
910 te->edges = od->nedgedata;
912 od->edgedata[i] = to;
913 od->edgedata[i + 1] = type;
914 od->edgedata[i + 2] = 0; /* end marker */
915 od->nedgedata = i + 3;
920 addedge(struct orderdata *od, Id from, Id to, int type)
922 Transaction *trans = od->trans;
923 Pool *pool = trans->pool;
925 struct _TransactionElement *te;
928 /* printf("addedge %d %d type %d\n", from, to, type); */
929 s = pool->solvables + from;
930 if (s->repo == pool->installed && trans->transaction_installed[from - pool->installed->start])
932 /* obsolete, map to install */
933 if (trans->transaction_installed[from - pool->installed->start] > 0)
934 from = trans->transaction_installed[from - pool->installed->start];
941 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
942 transaction_all_obs_pkgs(trans, from, &ti);
943 for (i = 0; i < ti.count; i++)
944 ret |= addedge(od, ti.elements[i], to, type);
949 s = pool->solvables + to;
950 if (s->repo == pool->installed && trans->transaction_installed[to - pool->installed->start])
952 /* obsolete, map to install */
953 if (trans->transaction_installed[to - pool->installed->start] > 0)
954 to = trans->transaction_installed[to - pool->installed->start];
961 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
962 transaction_all_obs_pkgs(trans, to, &ti);
963 for (i = 0; i < ti.count; i++)
964 ret |= addedge(od, from, ti.elements[i], type);
970 /* map from/to to te numbers */
971 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
978 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
984 return addteedge(od, i, to, type);
989 havechoice(struct orderdata *od, Id p, Id q1, Id q2)
991 Transaction *trans = od->trans;
992 Pool *pool = trans->pool;
993 Id ti1buf[5], ti2buf[5];
997 /* both q1 and q2 are uninstalls. check if their TEs intersect */
998 /* common case: just one TE for both packages */
1000 printf("havechoice %d %d %d\n", p, q1, q2);
1002 if (trans->transaction_installed[q1 - pool->installed->start] == 0)
1004 if (trans->transaction_installed[q2 - pool->installed->start] == 0)
1006 if (trans->transaction_installed[q1 - pool->installed->start] == trans->transaction_installed[q2 - pool->installed->start])
1008 if (trans->transaction_installed[q1 - pool->installed->start] > 0 && trans->transaction_installed[q2 - pool->installed->start] > 0)
1010 queue_init_buffer(&ti1, ti1buf, sizeof(ti1buf)/sizeof(*ti1buf));
1011 transaction_all_obs_pkgs(trans, q1, &ti1);
1012 queue_init_buffer(&ti2, ti2buf, sizeof(ti2buf)/sizeof(*ti2buf));
1013 transaction_all_obs_pkgs(trans, q2, &ti2);
1014 for (i = 0; i < ti1.count; i++)
1015 for (j = 0; j < ti2.count; j++)
1016 if (ti1.elements[i] == ti2.elements[j])
1018 /* found a common edge */
1030 havescripts(Pool *pool, Id solvid)
1032 Solvable *s = pool->solvables + solvid;
1038 reqp = s->repo->idarraydata + s->requires;
1039 while ((req = *reqp++) != 0)
1041 if (req == SOLVABLE_PREREQMARKER)
1048 dep = pool_id2str(pool, req);
1049 if (*dep == '/' && strcmp(dep, "/sbin/ldconfig") != 0)
1057 addsolvableedges(struct orderdata *od, Solvable *s)
1059 Transaction *trans = od->trans;
1060 Pool *pool = trans->pool;
1061 Id req, *reqp, con, *conp;
1063 int i, j, pre, numins;
1064 Repo *installed = pool->installed;
1070 printf("addsolvableedges %s\n", pool_solvable2str(pool, s));
1072 p = s - pool->solvables;
1076 reqp = s->repo->idarraydata + s->requires;
1078 while ((req = *reqp++) != 0)
1080 if (req == SOLVABLE_PREREQMARKER)
1086 if (pre != TYPE_PREREQ && installed && s->repo == installed)
1088 /* ignore normal requires if we're getting obsoleted */
1089 if (trans->transaction_installed[p - pool->installed->start])
1094 numins = 0; /* number of packages to be installed providing it */
1095 provbyinst = 0; /* provided by kept package */
1096 FOR_PROVIDES(p2, pp2, req)
1098 s2 = pool->solvables + p2;
1101 reqq.count = 0; /* self provides */
1104 if (s2->repo == installed && !MAPTST(&trans->transactsmap, p2))
1108 printf("IGNORE inst provides %s by %s\n", pool_dep2str(pool, req), pool_solvable2str(pool, s2));
1109 reqq.count = 0; /* provided by package that stays installed */
1115 if (s2->repo != installed && !MAPTST(&trans->transactsmap, p2))
1116 continue; /* package stays uninstalled */
1118 if (s->repo == installed)
1120 /* s gets uninstalled */
1121 queue_pushunique(&reqq, p2);
1122 if (s2->repo != installed)
1127 if (s2->repo == installed)
1128 continue; /* s2 gets uninstalled */
1129 queue_pushunique(&reqq, p2);
1134 /* prune to harmless ->inst edges */
1135 for (i = j = 0; i < reqq.count; i++)
1136 if (pool->solvables[reqq.elements[i]].repo != installed)
1137 reqq.elements[j++] = reqq.elements[i];
1141 if (numins && reqq.count)
1143 if (s->repo == installed)
1145 for (i = 0; i < reqq.count; i++)
1147 if (pool->solvables[reqq.elements[i]].repo == installed)
1149 for (j = 0; j < reqq.count; j++)
1151 if (pool->solvables[reqq.elements[j]].repo != installed)
1153 if (trans->transaction_installed[reqq.elements[i] - pool->installed->start] == reqq.elements[j])
1154 continue; /* no self edge */
1156 printf("add interrreq uninst->inst edge (%s -> %s -> %s)\n", pool_solvid2str(pool, reqq.elements[i]), pool_dep2str(pool, req), pool_solvid2str(pool, reqq.elements[j]));
1158 addedge(od, reqq.elements[i], reqq.elements[j], pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1164 /* no mixed types, remove all deps on uninstalls */
1165 for (i = j = 0; i < reqq.count; i++)
1166 if (pool->solvables[reqq.elements[i]].repo != installed)
1167 reqq.elements[j++] = reqq.elements[i];
1172 for (i = 0; i < reqq.count; i++)
1175 p2 = reqq.elements[i];
1176 if (pool->solvables[p2].repo != installed)
1178 /* all elements of reqq are installs, thus have different TEs */
1179 choice = reqq.count - 1;
1180 if (pool->solvables[p].repo != installed)
1183 printf("add inst->inst edge choice %d (%s -> %s -> %s)\n", choice, pool_solvid2str(pool, p), pool_dep2str(pool, req), pool_solvid2str(pool, p2));
1185 addedge(od, p, p2, pre);
1190 printf("add uninst->inst edge choice %d (%s -> %s -> %s)\n", choice, pool_solvid2str(pool, p), pool_dep2str(pool, req), pool_solvid2str(pool, p2));
1192 addedge(od, p, p2, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1197 if (s->repo != installed)
1198 continue; /* no inst->uninst edges, please! */
1200 /* uninst -> uninst edge. Those make trouble. Only add if we must */
1201 if (trans->transaction_installed[p - installed->start] && !havescripts(pool, p))
1203 /* p is obsoleted by another package and has no scripts */
1204 /* we assume that the obsoletor is good enough to replace p */
1209 for (j = 0; j < reqq.count; j++)
1213 if (havechoice(od, p, reqq.elements[i], reqq.elements[j]))
1218 printf("add uninst->uninst edge choice %d (%s -> %s -> %s)\n", choice, pool_solvid2str(pool, p), pool_dep2str(pool, req), pool_solvid2str(pool, p2));
1220 addedge(od, p2, p, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1227 conp = s->repo->idarraydata + s->conflicts;
1228 while ((con = *conp++) != 0)
1230 FOR_PROVIDES(p2, pp2, con)
1234 s2 = pool->solvables + p2;
1237 if (s->repo == installed)
1239 if (s2->repo != installed && MAPTST(&trans->transactsmap, p2))
1241 /* deinstall p before installing p2 */
1243 printf("add conflict uninst->inst edge (%s -> %s -> %s)\n", pool_solvid2str(pool, p2), pool_dep2str(pool, con), pool_solvid2str(pool, p));
1245 addedge(od, p2, p, TYPE_CON);
1250 if (s2->repo == installed && MAPTST(&trans->transactsmap, p2))
1252 /* deinstall p2 before installing p */
1254 printf("add conflict uninst->inst edge (%s -> %s -> %s)\n", pool_solvid2str(pool, p), pool_dep2str(pool, con), pool_solvid2str(pool, p2));
1256 addedge(od, p, p2, TYPE_CON);
1263 if (s->repo == installed && solvable_lookup_idarray(s, SOLVABLE_TRIGGERS, &reqq) && reqq.count)
1265 /* we're getting deinstalled/updated. Try to do this before our
1266 * triggers are hit */
1267 for (i = 0; i < reqq.count; i++)
1269 Id tri = reqq.elements[i];
1270 FOR_PROVIDES(p2, pp2, tri)
1274 s2 = pool->solvables + p2;
1277 if (s2->name == s->name)
1278 continue; /* obsoleted anyway */
1279 if (s2->repo != installed && MAPTST(&trans->transactsmap, p2))
1281 /* deinstall/update p before installing p2 */
1283 printf("add trigger uninst->inst edge (%s -> %s -> %s)\n", pool_solvid2str(pool, p2), pool_dep2str(pool, tri), pool_solvid2str(pool, p));
1285 addedge(od, p2, p, TYPE_CON);
1294 /* break an edge in a cycle */
1296 breakcycle(struct orderdata *od, Id *cycle)
1298 Pool *pool = od->trans->pool;
1299 Id ddegmin, ddegmax, ddeg;
1301 struct _TransactionElement *te;
1304 ddegmin = ddegmax = 0;
1305 for (k = 0; cycle[k + 1]; k += 2)
1307 ddeg = od->edgedata[cycle[k + 1] + 1];
1310 if (!k || ddeg < ddegmin)
1316 if (ddeg == ddegmin)
1318 if (havescripts(pool, od->tes[cycle[l]].p) && !havescripts(pool, od->tes[cycle[k]].p))
1320 /* prefer k, as l comes from a package with contains scriptlets */
1325 /* same edge value, check for prereq */
1329 /* record brkoen cycle starting with the tail */
1330 queue_push(&od->cycles, od->cyclesdata.count); /* offset into data */
1331 queue_push(&od->cycles, k / 2); /* cycle elements */
1332 queue_push(&od->cycles, od->edgedata[cycle[l + 1] + 1]); /* broken edge */
1339 queue_push(&od->cyclesdata, cycle[k]);
1343 queue_push(&od->cyclesdata, 0); /* mark end */
1345 /* break that edge */
1346 od->edgedata[cycle[l + 1] + 1] |= TYPE_BROKEN;
1349 if (ddegmin < TYPE_REQ)
1353 /* cycle recorded, print it */
1354 if (ddegmin >= TYPE_REQ && (ddegmax & TYPE_PREREQ) != 0)
1355 POOL_DEBUG(SOLV_DEBUG_STATS, "CRITICAL ");
1356 POOL_DEBUG(SOLV_DEBUG_STATS, "cycle: --> ");
1357 for (k = 0; cycle[k + 1]; k += 2)
1359 te = od->tes + cycle[k];
1360 if ((od->edgedata[cycle[k + 1] + 1] & TYPE_BROKEN) != 0)
1361 POOL_DEBUG(SOLV_DEBUG_STATS, "%s ##%x##> ", pool_solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
1363 POOL_DEBUG(SOLV_DEBUG_STATS, "%s --%x--> ", pool_solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
1365 POOL_DEBUG(SOLV_DEBUG_STATS, "\n");
1369 dump_tes(struct orderdata *od)
1371 Pool *pool = od->trans->pool;
1374 struct _TransactionElement *te, *te2;
1377 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1379 Solvable *s = pool->solvables + te->p;
1380 POOL_DEBUG(SOLV_DEBUG_RESULT, "TE %4d: %c%s\n", i, s->repo == pool->installed ? '-' : '+', pool_solvable2str(pool, s));
1381 if (s->repo != pool->installed)
1384 transaction_all_obs_pkgs(od->trans, te->p, &obsq);
1385 for (j = 0; j < obsq.count; j++)
1386 POOL_DEBUG(SOLV_DEBUG_RESULT, " -%s\n", pool_solvid2str(pool, obsq.elements[j]));
1388 for (j = te->edges; od->edgedata[j]; j += 2)
1390 te2 = od->tes + od->edgedata[j];
1391 if ((od->edgedata[j + 1] & TYPE_BROKEN) == 0)
1392 POOL_DEBUG(SOLV_DEBUG_RESULT, " --%x--> TE %4d: %s\n", od->edgedata[j + 1], od->edgedata[j], pool_solvid2str(pool, te2->p));
1394 POOL_DEBUG(SOLV_DEBUG_RESULT, " ##%x##> TE %4d: %s\n", od->edgedata[j + 1], od->edgedata[j], pool_solvid2str(pool, te2->p));
1401 reachable(struct orderdata *od, Id i)
1403 struct _TransactionElement *te = od->tes + i;
1409 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1411 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1413 if (!od->tes[k].mark)
1415 if (od->tes[k].mark == 2)
1426 addcycleedges(struct orderdata *od, Id *cycle, Queue *todo)
1429 Transaction *trans = od->trans;
1430 Pool *pool = trans->pool;
1432 struct _TransactionElement *te;
1439 printf("addcycleedges\n");
1440 for (i = 0; (j = cycle[i]) != 0; i++)
1441 printf("cycle %s\n", pool_solvid2str(pool, od->tes[j].p));
1444 /* first add all the tail cycle edges */
1446 /* see what we can reach from the cycle */
1448 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1450 for (i = 0; (j = cycle[i]) != 0; i++)
1452 od->tes[j].mark = -1;
1453 queue_push(todo, j);
1457 i = queue_pop(todo);
1461 te->mark = te->mark < 0 ? 2 : 1;
1462 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1464 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1466 if (od->tes[k].mark > 0)
1467 continue; /* no need to visit again */
1468 queue_push(todo, k);
1471 /* now all cycle TEs are marked with 2, all TEs reachable
1472 * from the cycle are marked with 1 */
1474 od->tes[tail].mark = 1; /* no need to add edges */
1476 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1479 continue; /* reachable from cycle */
1480 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1482 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1484 if (od->tes[k].mark != 2)
1486 /* We found an edge to the cycle. Add an extra edge to the tail */
1487 /* the TE was not reachable, so we're not creating a new cycle! */
1489 printf("adding TO TAIL cycle edge %d->%d %s->%s!\n", i, tail, pool_solvid2str(pool, od->tes[i].p), pool_solvid2str(pool, od->tes[tail].p));
1491 j -= te->edges; /* in case we move */
1492 addteedge(od, i, tail, TYPE_CYCLETAIL);
1494 break; /* one edge is enough */
1499 /* now add all head cycle edges */
1502 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1505 for (i = 0; (j = cycle[i]) != 0; i++)
1508 od->tes[j].mark = 2;
1510 /* first the head to save some time */
1511 te = od->tes + head;
1512 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1514 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1516 if (!od->tes[k].mark)
1518 if (od->tes[k].mark == -1)
1519 od->tes[k].mark = -2; /* no need for another edge */
1521 for (i = 0; cycle[i] != 0; i++)
1523 if (cycle[i] == head)
1525 te = od->tes + cycle[i];
1526 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1528 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1530 /* see if we can reach a cycle TE from k */
1531 if (!od->tes[k].mark)
1533 if (od->tes[k].mark == -1)
1536 printf("adding FROM HEAD cycle edge %d->%d %s->%s [%s]!\n", head, k, pool_solvid2str(pool, od->tes[head].p), pool_solvid2str(pool, od->tes[k].p), pool_solvid2str(pool, od->tes[cycle[i]].p));
1538 addteedge(od, head, k, TYPE_CYCLEHEAD);
1539 od->tes[k].mark = -2; /* no need to add that one again */
1547 transaction_order(Transaction *trans, int flags)
1549 Pool *pool = trans->pool;
1550 Queue *tr = &trans->steps;
1551 Repo *installed = pool->installed;
1554 int i, j, k, numte, numedge;
1555 struct orderdata od;
1556 struct _TransactionElement *te;
1557 Queue todo, obsq, samerepoq, uninstq;
1558 int cycstart, cycel;
1566 start = now = solv_timems(0);
1567 POOL_DEBUG(SOLV_DEBUG_STATS, "ordering transaction\n");
1568 /* free old data if present */
1569 if (trans->orderdata)
1571 struct _TransactionOrderdata *od = trans->orderdata;
1572 od->tes = solv_free(od->tes);
1573 od->invedgedata = solv_free(od->invedgedata);
1574 trans->orderdata = solv_free(trans->orderdata);
1577 /* create a transaction element for every active component */
1579 for (i = 0; i < tr->count; i++)
1581 p = tr->elements[i];
1582 s = pool->solvables + p;
1583 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
1587 POOL_DEBUG(SOLV_DEBUG_STATS, "transaction elements: %d\n", numte);
1589 return; /* nothing to do... */
1591 numte++; /* leave first one zero */
1592 memset(&od, 0, sizeof(od));
1595 od.tes = solv_calloc(numte, sizeof(*od.tes));
1596 od.edgedata = solv_extend(0, 0, 1, sizeof(Id), EDGEDATA_BLOCK);
1599 queue_init(&od.cycles);
1601 /* initialize TEs */
1602 for (i = 0, te = od.tes + 1; i < tr->count; i++)
1604 p = tr->elements[i];
1605 s = pool->solvables + p;
1606 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
1612 /* create dependency graph */
1613 for (i = 0; i < tr->count; i++)
1614 addsolvableedges(&od, pool->solvables + tr->elements[i]);
1618 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1619 for (j = te->edges; od.edgedata[j]; j += 2)
1621 POOL_DEBUG(SOLV_DEBUG_STATS, "edges: %d, edge space: %d\n", numedge, od.nedgedata / 2);
1622 POOL_DEBUG(SOLV_DEBUG_STATS, "edge creation took %d ms\n", solv_timems(now));
1628 now = solv_timems(0);
1629 /* kill all cycles */
1631 for (i = numte - 1; i > 0; i--)
1632 queue_push(&todo, i);
1636 i = queue_pop(&todo);
1637 /* printf("- look at TE %d\n", i); */
1641 od.tes[i].mark = 2; /* done with that one */
1646 continue; /* already finished before */
1649 int edgestovisit = 0;
1650 /* new node, visit edges */
1651 for (j = te->edges; (k = od.edgedata[j]) != 0; j += 2)
1653 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1655 if (od.tes[k].mark == 2)
1656 continue; /* no need to visit again */
1657 if (!edgestovisit++)
1658 queue_push(&todo, -i); /* end of edges marker */
1659 queue_push(&todo, k);
1662 te->mark = 2; /* no edges, done with that one */
1664 te->mark = 1; /* under investigation */
1667 /* oh no, we found a cycle */
1668 /* find start of cycle node (<0) */
1669 for (j = todo.count - 1; j >= 0; j--)
1670 if (todo.elements[j] == -i)
1674 /* build te/edge chain */
1676 for (j = k; j < todo.count; j++)
1677 if (todo.elements[j] < 0)
1678 todo.elements[k++] = -todo.elements[j];
1679 cycel = k - cycstart;
1681 /* make room for edges, two extra element for cycle loop + terminating 0 */
1682 while (todo.count < cycstart + 2 * cycel + 2)
1683 queue_push(&todo, 0);
1684 cycle = todo.elements + cycstart;
1685 cycle[cycel] = i; /* close the loop */
1686 cycle[2 * cycel + 1] = 0; /* terminator */
1687 for (k = cycel; k > 0; k--)
1689 cycle[k * 2] = cycle[k];
1690 te = od.tes + cycle[k - 1];
1691 assert(te->mark == 1);
1692 te->mark = 0; /* reset investigation marker */
1693 /* printf("searching for edge from %d to %d\n", cycle[k - 1], cycle[k]); */
1694 for (j = te->edges; od.edgedata[j]; j += 2)
1695 if (od.edgedata[j] == cycle[k])
1697 assert(od.edgedata[j]);
1698 cycle[k * 2 - 1] = j;
1700 /* now cycle looks like this: */
1701 /* te1 edge te2 edge te3 ... teN edge te1 0 */
1702 breakcycle(&od, cycle);
1703 /* restart with start of cycle */
1704 todo.count = cycstart + 1;
1706 POOL_DEBUG(SOLV_DEBUG_STATS, "cycles broken: %d\n", od.ncycles);
1707 POOL_DEBUG(SOLV_DEBUG_STATS, "cycle breaking took %d ms\n", solv_timems(now));
1709 now = solv_timems(0);
1710 /* now go through all broken cycles and create cycle edges to help
1712 for (i = od.cycles.count - 3; i >= 0; i -= 3)
1714 if (od.cycles.elements[i + 2] >= TYPE_REQ)
1715 addcycleedges(&od, od.cyclesdata.elements + od.cycles.elements[i], &todo);
1717 for (i = od.cycles.count - 3; i >= 0; i -= 3)
1719 if (od.cycles.elements[i + 2] < TYPE_REQ)
1720 addcycleedges(&od, od.cyclesdata.elements + od.cycles.elements[i], &todo);
1722 POOL_DEBUG(SOLV_DEBUG_STATS, "cycle edge creation took %d ms\n", solv_timems(now));
1727 /* all edges are finally set up and there are no cycles, now the easy part.
1728 * Create an ordered transaction */
1729 now = solv_timems(0);
1730 /* first invert all edges */
1731 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1732 te->mark = 1; /* term 0 */
1733 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1735 for (j = te->edges; od.edgedata[j]; j += 2)
1737 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1739 od.tes[od.edgedata[j]].mark++;
1743 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1748 POOL_DEBUG(SOLV_DEBUG_STATS, "invedge space: %d\n", j + 1);
1749 od.invedgedata = solv_calloc(j + 1, sizeof(Id));
1750 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1752 for (j = te->edges; od.edgedata[j]; j += 2)
1754 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1756 od.invedgedata[--od.tes[od.edgedata[j]].mark] = i;
1759 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1760 te->edges = te->mark; /* edges now points into invedgedata */
1761 od.edgedata = solv_free(od.edgedata);
1762 od.nedgedata = j + 1;
1764 /* now the final ordering */
1765 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1767 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1768 for (j = te->edges; od.invedgedata[j]; j++)
1769 od.tes[od.invedgedata[j]].mark++;
1771 queue_init(&samerepoq);
1772 queue_init(&uninstq);
1774 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1777 if (installed && pool->solvables[te->p].repo == installed)
1778 queue_push(&uninstq, i);
1780 queue_push(&todo, i);
1782 assert(todo.count > 0 || uninstq.count > 0);
1783 oldcount = tr->count;
1790 temedianr = solv_calloc(numte, sizeof(Id));
1791 for (i = 1; i < numte; i++)
1793 Solvable *s = pool->solvables + od.tes[i].p;
1794 if (installed && s->repo == installed)
1797 j = solvable_lookup_num(s, SOLVABLE_MEDIANR, 1);
1802 /* select an TE i */
1804 i = queue_shift(&uninstq);
1805 else if (samerepoq.count)
1806 i = queue_shift(&samerepoq);
1807 else if (todo.count)
1809 /* find next repo/media */
1810 for (j = 0; j < todo.count; j++)
1812 if (!j || temedianr[todo.elements[j]] < lastmedia)
1815 lastmedia = temedianr[todo.elements[j]];
1818 lastrepo = pool->solvables[od.tes[todo.elements[i]].p].repo;
1820 /* move all matching TEs to samerepoq */
1821 for (i = j = 0; j < todo.count; j++)
1823 int k = todo.elements[j];
1824 if (temedianr[k] == lastmedia && pool->solvables[od.tes[k].p].repo == lastrepo)
1825 queue_push(&samerepoq, k);
1827 todo.elements[i++] = k;
1831 assert(samerepoq.count);
1832 i = queue_shift(&samerepoq);
1838 queue_push(tr, te->p);
1840 printf("do %s [%d]\n", pool_solvid2str(pool, te->p), temedianr[i]);
1842 s = pool->solvables + te->p;
1843 for (j = te->edges; od.invedgedata[j]; j++)
1845 struct _TransactionElement *te2 = od.tes + od.invedgedata[j];
1846 assert(te2->mark > 0);
1847 if (--te2->mark == 0)
1849 Solvable *s = pool->solvables + te2->p;
1851 printf("free %s [%d]\n", pool_solvid2str(pool, te2->p), temedianr[od.invedgedata[j]]);
1853 if (installed && s->repo == installed)
1854 queue_push(&uninstq, od.invedgedata[j]);
1855 else if (s->repo == lastrepo && temedianr[od.invedgedata[j]] == lastmedia)
1856 queue_push(&samerepoq, od.invedgedata[j]);
1858 queue_push(&todo, od.invedgedata[j]);
1862 solv_free(temedianr);
1864 queue_free(&samerepoq);
1865 queue_free(&uninstq);
1867 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1868 assert(te->mark == 0);
1870 /* add back obsoleted packages */
1871 transaction_add_obsoleted(trans);
1872 assert(tr->count == oldcount);
1874 POOL_DEBUG(SOLV_DEBUG_STATS, "creating new transaction took %d ms\n", solv_timems(now));
1875 POOL_DEBUG(SOLV_DEBUG_STATS, "transaction ordering took %d ms\n", solv_timems(start));
1877 if ((flags & SOLVER_TRANSACTION_KEEP_ORDERDATA) != 0)
1879 trans->orderdata = solv_calloc(1, sizeof(*trans->orderdata));
1880 trans->orderdata->tes = od.tes;
1881 trans->orderdata->ntes = numte;
1882 trans->orderdata->invedgedata = od.invedgedata;
1883 trans->orderdata->ninvedgedata = od.nedgedata;
1888 solv_free(od.invedgedata);
1890 queue_free(&od.cycles);
1891 queue_free(&od.cyclesdata);
1896 transaction_order_add_choices(Transaction *trans, Id chosen, Queue *choices)
1899 struct _TransactionOrderdata *od = trans->orderdata;
1900 struct _TransactionElement *te;
1903 return choices->count;
1906 /* initialization step */
1907 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1909 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1911 for (j = te->edges; od->invedgedata[j]; j++)
1912 od->tes[od->invedgedata[j]].mark++;
1914 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1916 queue_push(choices, te->p);
1917 return choices->count;
1919 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1920 if (te->p == chosen)
1923 return choices->count;
1926 /* hey! out-of-order installation! */
1929 for (j = te->edges; od->invedgedata[j]; j++)
1931 te = od->tes + od->invedgedata[j];
1932 assert(te->mark > 0 || te->mark == -1);
1933 if (te->mark > 0 && --te->mark == 0)
1934 queue_push(choices, te->p);
1936 return choices->count;
1940 transaction_add_obsoleted(Transaction *trans)
1942 Pool *pool = trans->pool;
1943 Repo *installed = pool->installed;
1950 if (!installed || !trans->steps.count)
1952 /* calculate upper bound */
1954 FOR_REPO_SOLVABLES(installed, p, s)
1955 if (MAPTST(&trans->transactsmap, p))
1960 steps = &trans->steps;
1961 queue_insertn(steps, 0, max);
1964 map_init(&done, installed->end - installed->start);
1966 for (j = 0, i = max; i < steps->count; i++)
1968 p = trans->steps.elements[i];
1969 if (pool->solvables[p].repo == installed)
1971 if (!trans->transaction_installed[p - pool->installed->start])
1972 trans->steps.elements[j++] = p;
1975 trans->steps.elements[j++] = p;
1977 transaction_all_obs_pkgs(trans, p, &obsq);
1978 for (k = 0; k < obsq.count; k++)
1980 p = obsq.elements[k];
1981 assert(p >= installed->start && p < installed->end);
1982 if (MAPTST(&done, p - installed->start))
1984 MAPSET(&done, p - installed->start);
1985 trans->steps.elements[j++] = p;
1989 /* free unneeded space */
1990 queue_truncate(steps, j);
1996 transaction_check_pkg(Transaction *trans, Id tepkg, Id pkg, Map *ins, Map *seen, int onlyprereq, Id noconfpkg, int depth)
1998 Pool *pool = trans->pool;
2003 if (MAPTST(seen, pkg))
2006 s = pool->solvables + pkg;
2008 printf("- %*s%c%s\n", depth * 2, "", s->repo == pool->installed ? '-' : '+', pool_solvable2str(pool, s));
2014 reqp = s->repo->idarraydata + s->requires;
2015 while ((req = *reqp++) != 0)
2017 if (req == SOLVABLE_PREREQMARKER)
2022 if (onlyprereq && !inpre)
2024 if (!strncmp(pool_id2str(pool, req), "rpmlib(", 7))
2027 /* first check kept packages, then freshly installed, then not yet uninstalled */
2028 FOR_PROVIDES(p, pp, req)
2030 if (!MAPTST(ins, p))
2032 if (MAPTST(&trans->transactsmap, p))
2035 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
2039 FOR_PROVIDES(p, pp, req)
2041 if (!MAPTST(ins, p))
2043 if (pool->solvables[p].repo == pool->installed)
2046 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
2051 FOR_PROVIDES(p, pp, req)
2053 if (!MAPTST(ins, p))
2056 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
2061 POOL_DEBUG(SOLV_DEBUG_RESULT, " %c%s: nothing provides %s needed by %c%s\n", pool->solvables[tepkg].repo == pool->installed ? '-' : '+', pool_solvid2str(pool, tepkg), pool_dep2str(pool, req), s->repo == pool->installed ? '-' : '+', pool_solvable2str(pool, s));
2068 transaction_check_order(Transaction *trans)
2070 Pool *pool = trans->pool;
2076 POOL_DEBUG(SOLV_WARN, "\nchecking transaction order...\n");
2077 map_init(&ins, pool->nsolvables);
2078 map_init(&seen, pool->nsolvables);
2079 if (pool->installed)
2080 FOR_REPO_SOLVABLES(pool->installed, p, s)
2083 for (i = 0; i < trans->steps.count; i++)
2085 p = trans->steps.elements[i];
2086 s = pool->solvables + p;
2087 if (s->repo != pool->installed)
2089 if (s->repo != pool->installed)
2091 if (havescripts(pool, p))
2094 transaction_check_pkg(trans, p, p, &ins, &seen, 1, lastins, 0);
2096 if (s->repo == pool->installed)
2101 POOL_DEBUG(SOLV_WARN, "transaction order check done.\n");