Imported Upstream version 0.7.8
[platform/upstream/libsolv.git] / src / transaction.c
index 78646ac..fb2cc9a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007-2009, Novell Inc.
+ * Copyright (c) 2007-2015, SUSE LLC
  *
  * This program is licensed under the BSD license, read LICENSE.BSD
  * for further information
@@ -21,6 +21,7 @@
 #include "solver.h"
 #include "bitmap.h"
 #include "pool.h"
+#include "poolarch.h"
 #include "evr.h"
 #include "util.h"
 
@@ -45,53 +46,60 @@ obsq_sortcmp(const void *ap, const void *bp, void *dp)
   obs = pool->solvables + ob;
   if (oas->name != obs->name)
     {
+      /* bring "same name" obsoleters (i.e. upgraders) to front */
       if (oas->name == s->name)
         return -1;
       if (obs->name == s->name)
         return 1;
-      return strcmp(id2str(pool, oas->name), id2str(pool, obs->name));
+      return strcmp(pool_id2str(pool, oas->name), pool_id2str(pool, obs->name));
     }
-  r = evrcmp(pool, oas->evr, obs->evr, EVRCMP_COMPARE);
+  r = pool_evrcmp(pool, oas->evr, obs->evr, EVRCMP_COMPARE);
   if (r)
     return -r; /* highest version first */
+  if (oas->arch != obs->arch)
+    {
+      /* bring same arch to front */
+      if (oas->arch == s->arch)
+        return -1;
+      if (obs->arch == s->arch)
+        return 1;
+    }
   return oa - ob;
 }
 
 void
-solver_transaction_all_pkgs(Solver *solv, Id p, Queue *pkgs)
+transaction_all_obs_pkgs(Transaction *trans, Id p, Queue *pkgs)
 {
-  Pool *pool = solv->pool;
+  Pool *pool = trans->pool;
   Solvable *s = pool->solvables + p;
-  Queue *ti = &solv->transaction_info;
+  Queue *ti = &trans->transaction_info;
   Id q;
   int i;
 
   queue_empty(pkgs);
   if (p <= 0 || !s->repo)
     return;
-  if (s->repo == solv->installed)
+  if (s->repo == pool->installed)
     {
-      q = solv->transaction_installed[p - solv->installed->start];
+      q = trans->transaction_installed[p - pool->installed->start];
       if (!q)
        return;
       if (q > 0)
        {
+         /* only a single obsoleting package */
          queue_push(pkgs, q);
          return;
        }
       /* find which packages obsolete us */
       for (i = 0; i < ti->count; i += 2)
        if (ti->elements[i + 1] == p)
-         {
-           queue_push(pkgs, p);
-           queue_push(pkgs, ti->elements[i]);
-         }
+         queue_push2(pkgs, p, ti->elements[i]);
       /* sort obsoleters */
       if (pkgs->count > 2)
-       sat_sort(pkgs->elements, pkgs->count / 2, 2 * sizeof(Id), obsq_sortcmp, pool);
+       solv_sort(pkgs->elements, pkgs->count / 2, 2 * sizeof(Id), obsq_sortcmp, pool);
       for (i = 0; i < pkgs->count; i += 2)
        pkgs->elements[i / 2] = pkgs->elements[i + 1];
-      pkgs->count /= 2;
+      queue_truncate(pkgs, pkgs->count / 2);
     }
   else
     {
@@ -107,64 +115,268 @@ solver_transaction_all_pkgs(Solver *solv, Id p, Queue *pkgs)
 }
 
 Id
-solver_transaction_pkg(Solver *solv, Id p)
+transaction_obs_pkg(Transaction *trans, Id p)
 {
-  Pool *pool = solv->pool;
+  Pool *pool = trans->pool;
   Solvable *s = pool->solvables + p;
-  Queue ti;
-  Id tibuf[5];
+  Queue *ti;
+  int i;
 
   if (p <= 0 || !s->repo)
     return 0;
-  if (s->repo == solv->installed)
+  if (s->repo == pool->installed)
     {
-      p = solv->transaction_installed[p - solv->installed->start];
+      p = trans->transaction_installed[p - pool->installed->start];
       return p < 0 ? -p : p;
     }
-  queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
-  solver_transaction_all_pkgs(solv, p, &ti);
-  p = ti.count ? ti.elements[0] : 0;
-  queue_free(&ti);
-  return p;
+  ti = &trans->transaction_info;
+  for (i = 0; i < ti->count; i += 2)
+    if (ti->elements[i] == p)
+      return ti->elements[i + 1];
+  return 0;
+}
+
+
+/*
+ * calculate base type of transaction element
+ */
+
+static Id
+transaction_base_type(Transaction *trans, Id p)
+{
+  Pool *pool = trans->pool;
+  Solvable *s, *s2;
+  int r;
+  Id p2;
+
+  if (!MAPTST(&trans->transactsmap, p))
+    return SOLVER_TRANSACTION_IGNORE;
+  p2 = transaction_obs_pkg(trans, p);
+  if (pool->installed && pool->solvables[p].repo == pool->installed)
+    {
+      /* erase */
+      if (!p2)
+       return SOLVER_TRANSACTION_ERASE;
+      s = pool->solvables + p;
+      s2 = pool->solvables + p2;
+      if (s->name == s2->name)
+       {
+         if (s->evr == s2->evr && solvable_identical(s, s2))
+           return SOLVER_TRANSACTION_REINSTALLED;
+         r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
+         if (r < 0)
+           return SOLVER_TRANSACTION_UPGRADED;
+         else if (r > 0)
+           return SOLVER_TRANSACTION_DOWNGRADED;
+         return SOLVER_TRANSACTION_CHANGED;
+       }
+      return SOLVER_TRANSACTION_OBSOLETED;
+    }
+  else
+    {
+      /* install or multiinstall */
+      int multi = trans->multiversionmap.size && MAPTST(&trans->multiversionmap, p);
+      if (multi)
+       {
+         if (p2)
+           {
+             s = pool->solvables + p;
+             s2 = pool->solvables + p2;
+             if (s->name == s2->name && s->arch == s2->arch && s->evr == s2->evr)
+               return SOLVER_TRANSACTION_MULTIREINSTALL;
+           }
+         return SOLVER_TRANSACTION_MULTIINSTALL;
+       }
+      if (!p2)
+       return SOLVER_TRANSACTION_INSTALL;
+      s = pool->solvables + p;
+      s2 = pool->solvables + p2;
+      if (s->name == s2->name)
+       {
+         if (s->evr == s2->evr && solvable_identical(s, s2))
+           return SOLVER_TRANSACTION_REINSTALL;
+         r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
+         if (r > 0)
+           return SOLVER_TRANSACTION_UPGRADE;
+         else if (r < 0)
+           return SOLVER_TRANSACTION_DOWNGRADE;
+         else
+           return SOLVER_TRANSACTION_CHANGE;
+       }
+      return SOLVER_TRANSACTION_OBSOLETES;
+    }
+}
+
+/* these packages do not get installed by the package manager */
+static inline int
+is_pseudo_package(Pool *pool, Solvable *s)
+{
+  const char *n = pool_id2str(pool, s->name);
+  if (*n == 'p' && !strncmp(n, "patch:", 6))
+    return 1;
+  if (*n == 'p' && !strncmp(n, "pattern:", 8))
+    return 1;
+  if (*n == 'p' && !strncmp(n, "product:", 8))
+    return 1;
+  if (*n == 'a' && !strncmp(n, "application:", 12))
+    return 1;
+  return 0;
+}
+
+/* these packages will never show up installed */
+static inline int
+is_noinst_pseudo_package(Pool *pool, Solvable *s)
+{
+  const char *n = pool_id2str(pool, s->name);
+  if (!strncmp(n, "patch:", 6))
+    return 1;
+  if (!strncmp(n, "pattern:", 8))
+    {
+#if defined(SUSE) && defined(ENABLE_LINKED_PKGS)
+      /* unlike normal patterns, autopatterns *can* be installed (via the package link),
+         so do not filter them */
+      if (s->provides)
+       {
+         Id prv, *prvp = s->repo->idarraydata + s->provides;
+         while ((prv = *prvp++) != 0)
+           if (ISRELDEP(prv) && !strcmp(pool_id2str(pool, prv), "autopattern()"))
+             return 0;
+       }
+#endif
+      return 1;
+    }
+  return 0;
 }
 
-/* type filtering, needed if either not all packages are shown
+static int
+obsoleted_by_pseudos_only(Transaction *trans, Id p)
+{
+  Pool *pool = trans->pool;
+  Queue q;
+  Id op;
+  int i;
+
+  op = transaction_obs_pkg(trans, p);
+  if (op && !is_pseudo_package(pool, pool->solvables + op))
+    return 0;
+  queue_init(&q);
+  transaction_all_obs_pkgs(trans, p, &q);
+  for (i = 0; i < q.count; i++)
+    if (!is_pseudo_package(pool, pool->solvables + q.elements[i]))
+      break;
+  i = !q.count || i < q.count ? 0 : 1;
+  queue_free(&q);
+  return i;
+}
+
+/*
+ * return type of transaction element
+ *
+ * filtering is needed if either not all packages are shown
  * or replaces are not shown, as otherwise parts of the
  * transaction might not be shown to the user */
 
 Id
-solver_transaction_filter(Solver *solv, Id type, Id p, int flags)
+transaction_type(Transaction *trans, Id p, int mode)
 {
-  Pool *pool = solv->pool;
+  Pool *pool = trans->pool;
   Solvable *s = pool->solvables + p;
   Queue oq, rq;
-  Id q;
+  Id type, q;
   int i, j, ref = 0;
 
+  if (!s->repo)
+    return SOLVER_TRANSACTION_IGNORE;
+
+  /* XXX: SUSE only? */
+  if (!(mode & SOLVER_TRANSACTION_KEEP_PSEUDO) && is_noinst_pseudo_package(pool, s))
+    return SOLVER_TRANSACTION_IGNORE;
+
+  type = transaction_base_type(trans, p);
+
+  if (type == SOLVER_TRANSACTION_IGNORE)
+    return SOLVER_TRANSACTION_IGNORE;  /* not part of the transaction */
+
+  if ((mode & SOLVER_TRANSACTION_RPM_ONLY) != 0)
+    {
+      /* application wants to know what to feed to the package manager */
+      if (!(mode & SOLVER_TRANSACTION_KEEP_PSEUDO) && is_pseudo_package(pool, s))
+       return SOLVER_TRANSACTION_IGNORE;
+      if (type == SOLVER_TRANSACTION_ERASE || type == SOLVER_TRANSACTION_INSTALL || type == SOLVER_TRANSACTION_MULTIINSTALL)
+       return type;
+      if (s->repo == pool->installed)
+       {
+         /* check if we're a real package that is obsoleted by pseudos */
+         if (!is_pseudo_package(pool, s) && obsoleted_by_pseudos_only(trans, s - pool->solvables))
+           return SOLVER_TRANSACTION_ERASE;
+         return SOLVER_TRANSACTION_IGNORE;     /* ignore as we're being obsoleted */
+       }
+      if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
+       return SOLVER_TRANSACTION_MULTIINSTALL;
+      return SOLVER_TRANSACTION_INSTALL;
+    }
+
+  if ((mode & SOLVER_TRANSACTION_SHOW_MULTIINSTALL) == 0)
+    {
+      /* application wants to make no difference between install
+       * and multiinstall */
+      if (type == SOLVER_TRANSACTION_MULTIINSTALL)
+        type = SOLVER_TRANSACTION_INSTALL;
+      if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
+        type = SOLVER_TRANSACTION_REINSTALL;
+    }
+
+  if ((mode & SOLVER_TRANSACTION_CHANGE_IS_REINSTALL) != 0)
+    {
+      /* application wants to make no difference between change
+       * and reinstall */
+      if (type == SOLVER_TRANSACTION_CHANGED)
+       type = SOLVER_TRANSACTION_REINSTALLED;
+      else if (type == SOLVER_TRANSACTION_CHANGE)
+       type = SOLVER_TRANSACTION_REINSTALL;
+    }
+
   if (type == SOLVER_TRANSACTION_ERASE || type == SOLVER_TRANSACTION_INSTALL || type == SOLVER_TRANSACTION_MULTIINSTALL)
     return type;
 
-  if (s->repo == pool->installed && (flags & SOLVER_TRANSACTION_SHOW_ACTIVE) == 0)
+  if (s->repo == pool->installed && (mode & SOLVER_TRANSACTION_SHOW_ACTIVE) == 0)
     {
-      /* erase element */
-      if ((flags & SOLVER_TRANSACTION_SHOW_REPLACES) == 0 && type == SOLVER_TRANSACTION_REPLACED)
+      /* erase element and we're showing the passive side */
+      if (type == SOLVER_TRANSACTION_OBSOLETED && (mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
        type = SOLVER_TRANSACTION_ERASE;
+      if (type == SOLVER_TRANSACTION_OBSOLETED && (mode & SOLVER_TRANSACTION_OBSOLETE_IS_UPGRADE) != 0)
+       type = SOLVER_TRANSACTION_UPGRADED;
       return type;
     }
-  if (s->repo != pool->installed && (flags & SOLVER_TRANSACTION_SHOW_ACTIVE) != 0)
+  if (s->repo != pool->installed && (mode & SOLVER_TRANSACTION_SHOW_ACTIVE) != 0)
     {
-      if ((flags & SOLVER_TRANSACTION_SHOW_REPLACES) == 0 && type == SOLVER_TRANSACTION_REPLACE)
+      /* install element and we're showing the active side */
+      if (type == SOLVER_TRANSACTION_OBSOLETES && (mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
        type = SOLVER_TRANSACTION_INSTALL;
+      if (type == SOLVER_TRANSACTION_OBSOLETES && (mode & SOLVER_TRANSACTION_OBSOLETE_IS_UPGRADE) != 0)
+       type = SOLVER_TRANSACTION_UPGRADE;
       return type;
     }
 
+  /* the element doesn't match the show mode */
+
+  /* if we're showing all references, we can ignore this package */
+  if ((mode & (SOLVER_TRANSACTION_SHOW_ALL|SOLVER_TRANSACTION_SHOW_OBSOLETES)) == (SOLVER_TRANSACTION_SHOW_ALL|SOLVER_TRANSACTION_SHOW_OBSOLETES))
+    return SOLVER_TRANSACTION_IGNORE;
+
+  /* we're not showing all refs. check if some other package
+   * references us. If yes, it's safe to ignore this package,
+   * otherwise we need to map the type */
+
   /* most of the time there's only one reference, so check it first */
-  q = solver_transaction_pkg(solv, p);
-  if ((flags & SOLVER_TRANSACTION_SHOW_REPLACES) == 0)
+  q = transaction_obs_pkg(trans, p);
+
+  if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
     {
       Solvable *sq = pool->solvables + q;
       if (sq->name != s->name)
        {
+         /* it's a replace but we're not showing replaces. map type. */
          if (s->repo == pool->installed)
            return SOLVER_TRANSACTION_ERASE;
          else if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
@@ -173,26 +385,29 @@ solver_transaction_filter(Solver *solv, Id type, Id p, int flags)
            return SOLVER_TRANSACTION_INSTALL;
        }
     }
-  if (solver_transaction_pkg(solv, q) == p)
-    return type;
+
+  /* if there's a match, p will be shown when q
+   * is processed */
+  if (transaction_obs_pkg(trans, q) == p)
+    return SOLVER_TRANSACTION_IGNORE;
 
   /* too bad, a miss. check em all */
   queue_init(&oq);
   queue_init(&rq);
-  solver_transaction_all_pkgs(solv, p, &oq);
+  transaction_all_obs_pkgs(trans, p, &oq);
   for (i = 0; i < oq.count; i++)
     {
       q = oq.elements[i];
-      if ((flags & SOLVER_TRANSACTION_SHOW_REPLACES) == 0)
+      if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
        {
          Solvable *sq = pool->solvables + q;
          if (sq->name != s->name)
            continue;
        }
       /* check if we are referenced? */
-      if ((flags & SOLVER_TRANSACTION_SHOW_ALL) != 0)
+      if ((mode & SOLVER_TRANSACTION_SHOW_ALL) != 0)
        {
-         solver_transaction_all_pkgs(solv, q, &rq);
+         transaction_all_obs_pkgs(trans, q, &rq);
          for (j = 0; j < rq.count; j++)
            if (rq.elements[j] == p)
              {
@@ -202,7 +417,7 @@ solver_transaction_filter(Solver *solv, Id type, Id p, int flags)
          if (ref)
            break;
        }
-      else if (solver_transaction_pkg(solv, q) == p)
+      else if (transaction_obs_pkg(trans, q) == p)
         {
          ref = 1;
          break;
@@ -213,860 +428,477 @@ solver_transaction_filter(Solver *solv, Id type, Id p, int flags)
 
   if (!ref)
     {
+      /* we're not referenced. map type */
       if (s->repo == pool->installed)
-       type = SOLVER_TRANSACTION_ERASE;
+       return SOLVER_TRANSACTION_ERASE;
       else if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
-       type = SOLVER_TRANSACTION_MULTIINSTALL;
+       return SOLVER_TRANSACTION_MULTIINSTALL;
       else
-       type = SOLVER_TRANSACTION_INSTALL;
+       return SOLVER_TRANSACTION_INSTALL;
+    }
+  /* there was a ref, so p is shown with some other package */
+  return SOLVER_TRANSACTION_IGNORE;
+}
+
+
+
+static int
+classify_cmp(const void *ap, const void *bp, void *dp)
+{
+  Transaction *trans = dp;
+  Pool *pool = trans->pool;
+  const Id *a = ap;
+  const Id *b = bp;
+  int r;
+
+  r = a[0] - b[0];
+  if (r)
+    return r;
+  r = a[2] - b[2];
+  if (r)
+    return a[2] && b[2] ? strcmp(pool_id2str(pool, a[2]), pool_id2str(pool, b[2])) : r;
+  r = a[3] - b[3];
+  if (r)
+    return a[3] && b[3] ? strcmp(pool_id2str(pool, a[3]), pool_id2str(pool, b[3])) : r;
+  return 0;
+}
+
+static int
+classify_cmp_pkgs(const void *ap, const void *bp, void *dp)
+{
+  Transaction *trans = dp;
+  Pool *pool = trans->pool;
+  Id a = *(Id *)ap;
+  Id b = *(Id *)bp;
+  Solvable *sa, *sb;
+
+  sa = pool->solvables + a;
+  sb = pool->solvables + b;
+  if (sa->name != sb->name)
+    return strcmp(pool_id2str(pool, sa->name), pool_id2str(pool, sb->name));
+  if (sa->evr != sb->evr)
+    {
+      int r = pool_evrcmp(pool, sa->evr, sb->evr, EVRCMP_COMPARE);
+      if (r)
+       return r;
+    }
+  return a - b;
+}
+
+static inline void
+queue_push4(Queue *q, Id id1, Id id2, Id id3, Id id4)
+{
+  queue_push(q, id1);
+  queue_push(q, id2);
+  queue_push(q, id3);
+  queue_push(q, id4);
+}
+
+static inline void
+queue_unshift4(Queue *q, Id id1, Id id2, Id id3, Id id4)
+{
+  queue_unshift(q, id4);
+  queue_unshift(q, id3);
+  queue_unshift(q, id2);
+  queue_unshift(q, id1);
+}
+
+void
+transaction_classify(Transaction *trans, int mode, Queue *classes)
+{
+  Pool *pool = trans->pool;
+  int ntypes[SOLVER_TRANSACTION_MAXTYPE + 1];
+  Solvable *s, *sq;
+  Id v, vq, type, p, q;
+  int i, j;
+
+  queue_empty(classes);
+  memset(ntypes, 0, sizeof(ntypes));
+  /* go through transaction and classify each step */
+  for (i = 0; i < trans->steps.count; i++)
+    {
+      p = trans->steps.elements[i];
+      s = pool->solvables + p;
+      type = transaction_type(trans, p, mode);
+      ntypes[type]++;
+      if (!pool->installed || s->repo != pool->installed)
+       continue;
+      /* don't report vendor/arch changes if we were mapped to erase. */
+      if (type == SOLVER_TRANSACTION_ERASE)
+       continue;
+      /* look at arch/vendor changes */
+      q = transaction_obs_pkg(trans, p);
+      if (!q)
+       continue;
+      sq = pool->solvables + q;
+
+      v = s->arch;
+      vq = sq->arch;
+      if (v != vq)
+       {
+         if ((mode & SOLVER_TRANSACTION_MERGE_ARCHCHANGES) != 0)
+           v = vq = 0;
+         for (j = 0; j < classes->count; j += 4)
+           if (classes->elements[j] == SOLVER_TRANSACTION_ARCHCHANGE && classes->elements[j + 2] == v && classes->elements[j + 3] == vq)
+             break;
+         if (j == classes->count)
+           queue_push4(classes, SOLVER_TRANSACTION_ARCHCHANGE, 1, v, vq);
+         else
+           classes->elements[j + 1]++;
+       }
+
+      v = s->vendor ? s->vendor : 1;
+      vq = sq->vendor ? sq->vendor : 1;
+      if (v != vq)
+       {
+         if ((mode & SOLVER_TRANSACTION_MERGE_VENDORCHANGES) != 0)
+           v = vq = 0;
+         for (j = 0; j < classes->count; j += 4)
+           if (classes->elements[j] == SOLVER_TRANSACTION_VENDORCHANGE && classes->elements[j + 2] == v && classes->elements[j + 3] == vq)
+             break;
+         if (j == classes->count)
+           queue_push4(classes, SOLVER_TRANSACTION_VENDORCHANGE, 1, v, vq);
+         else
+           classes->elements[j + 1]++;
+       }
+    }
+  /* now sort all vendor/arch changes */
+  if (classes->count > 4)
+    solv_sort(classes->elements, classes->count / 4, 4 * sizeof(Id), classify_cmp, trans);
+  /* finally add all classes. put erases last */
+  i = SOLVER_TRANSACTION_ERASE;
+  if (ntypes[i])
+    queue_unshift4(classes, i, ntypes[i], 0, 0);
+  for (i = SOLVER_TRANSACTION_MAXTYPE; i > 0; i--)
+    {
+      if (!ntypes[i])
+       continue;
+      if (i == SOLVER_TRANSACTION_ERASE)
+       continue;
+      queue_unshift4(classes, i, ntypes[i], 0, 0);
+    }
+}
+
+void
+transaction_classify_pkgs(Transaction *trans, int mode, Id class, Id from, Id to, Queue *pkgs)
+{
+  Pool *pool = trans->pool;
+  int i;
+  Id type, p, q;
+  Solvable *s, *sq;
+
+  queue_empty(pkgs);
+  for (i = 0; i < trans->steps.count; i++)
+    {
+      p = trans->steps.elements[i];
+      s = pool->solvables + p;
+      if (class <= SOLVER_TRANSACTION_MAXTYPE)
+       {
+         type = transaction_type(trans, p, mode);
+         if (type == class)
+           queue_push(pkgs, p);
+         continue;
+       }
+      if (!pool->installed || s->repo != pool->installed)
+       continue;
+      q = transaction_obs_pkg(trans, p);
+      if (!q)
+       continue;
+      sq = pool->solvables + q;
+      if (class == SOLVER_TRANSACTION_ARCHCHANGE)
+       {
+         if ((!from && !to) || (s->arch == from && sq->arch == to))
+           queue_push(pkgs, p);
+         continue;
+       }
+      if (class == SOLVER_TRANSACTION_VENDORCHANGE)
+       {
+         Id v = s->vendor ? s->vendor : 1;
+         Id vq = sq->vendor ? sq->vendor : 1;
+         if ((!from && !to) || (v == from && vq == to))
+           queue_push(pkgs, p);
+         continue;
+       }
     }
-  return type;
+  if (pkgs->count > 1)
+    solv_sort(pkgs->elements, pkgs->count, sizeof(Id), classify_cmp_pkgs, trans);
 }
 
 static void
-create_transaction_info(Solver *solv)
+create_transaction_info(Transaction *trans, Queue *decisionq)
 {
-  Pool *pool = solv->pool;
-  Queue *ti = &solv->transaction_info;
-  Repo *installed = solv->installed;
-  int i, j, noobs;
+  Pool *pool = trans->pool;
+  Queue *ti = &trans->transaction_info;
+  Repo *installed = pool->installed;
+  int i, j, multi;
   Id p, p2, pp2;
   Solvable *s, *s2;
 
   queue_empty(ti);
+  trans->transaction_installed = solv_free(trans->transaction_installed);
   if (!installed)
     return;    /* no info needed */
-  for (i = 0; i < solv->decisionq.count; i++)
+  for (i = 0; i < decisionq->count; i++)
     {
-      p = solv->decisionq.elements[i];
+      p = decisionq->elements[i];
       if (p <= 0 || p == SYSTEMSOLVABLE)
        continue;
       s = pool->solvables + p;
-      if (s->repo == installed)
+      if (!s->repo || s->repo == installed)
+       continue;
+      if (!MAPTST(&trans->transactsmap, p))
        continue;
-      noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p);
+      multi = trans->multiversionmap.size && MAPTST(&trans->multiversionmap, p);
       FOR_PROVIDES(p2, pp2, s->name)
        {
-         if (solv->decisionmap[p2] > 0)
+         if (!MAPTST(&trans->transactsmap, p2))
            continue;
          s2 = pool->solvables + p2;
          if (s2->repo != installed)
            continue;
-         if (noobs && (s->name != s2->name || s->evr != s2->evr || s->arch != s2->arch))
+         if (multi && (s->name != s2->name || s->evr != s2->evr || s->arch != s2->arch))
            continue;
-         if (!solv->implicitobsoleteusesprovides && s->name != s2->name)
+         if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
            continue;
-         queue_push(ti, p);
-         queue_push(ti, p2);
+         if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, s2))
+           continue;
+         queue_push2(ti, p, p2);
        }
-      if (s->obsoletes && !noobs)
+      if (s->obsoletes && !multi)
        {
          Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
          while ((obs = *obsp++) != 0)
            {
              FOR_PROVIDES(p2, pp2, obs)
                {
+                 if (!MAPTST(&trans->transactsmap, p2))
+                   continue;
                  s2 = pool->solvables + p2;
                  if (s2->repo != installed)
                    continue;
-                 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
+                 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, s2, obs))
+                   continue;
+                 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
                    continue;
-                 queue_push(ti, p);
-                 queue_push(ti, p2);
+                 queue_push2(ti, p, p2);
                }
            }
        }
     }
-  sat_sort(ti->elements, ti->count / 2, 2 * sizeof(Id), obsq_sortcmp, pool);
-  /* now unify */
-  for (i = j = 0; i < ti->count; i += 2)
+  if (ti->count > 2)
     {
-      if (j && ti->elements[i] == ti->elements[j - 2] && ti->elements[i + 1] == ti->elements[j - 1])
-       continue;
-      ti->elements[j++] = ti->elements[i];
-      ti->elements[j++] = ti->elements[i + 1];
+      /* sort and unify */
+      solv_sort(ti->elements, ti->count / 2, 2 * sizeof(Id), obsq_sortcmp, pool);
+      for (i = j = 2; i < ti->count; i += 2)
+       {
+         if (ti->elements[i] == ti->elements[j - 2] && ti->elements[i + 1] == ti->elements[j - 1])
+           continue;
+         ti->elements[j++] = ti->elements[i];
+         ti->elements[j++] = ti->elements[i + 1];
+       }
+      queue_truncate(ti, j);
     }
-  ti->count = j;
 
   /* create transaction_installed helper */
-  solv->transaction_installed = sat_calloc(installed->end - installed->start, sizeof(Id));
+  /*   entry > 0: exactly one obsoleter, entry < 0: multiple obsoleters, -entry is "best" */
+  trans->transaction_installed = solv_calloc(installed->end - installed->start, sizeof(Id));
   for (i = 0; i < ti->count; i += 2)
     {
       j = ti->elements[i + 1] - installed->start;
-      if (!solv->transaction_installed[j])
-       solv->transaction_installed[j] = ti->elements[i];
+      if (!trans->transaction_installed[j])
+       trans->transaction_installed[j] = ti->elements[i];
       else
        {
-         /* more than one package obsoletes us. compare */
+         /* more than one package obsoletes us. compare to find "best" */
          Id q[4];
-         if (solv->transaction_installed[j] > 0)
-           solv->transaction_installed[j] = -solv->transaction_installed[j];
+         if (trans->transaction_installed[j] > 0)
+           trans->transaction_installed[j] = -trans->transaction_installed[j];
          q[0] = q[2] = ti->elements[i + 1];
          q[1] = ti->elements[i];
-         q[3] = -solv->transaction_installed[j];
+         q[3] = -trans->transaction_installed[j];
          if (obsq_sortcmp(q, q + 2, pool) < 0)
-           solv->transaction_installed[j] = -ti->elements[i];
+           trans->transaction_installed[j] = -ti->elements[i];
        }
     }
 }
 
-
-void
-solver_create_transaction(Solver *solv)
+/* create a transaction from the decisionq */
+Transaction *
+transaction_create_decisionq(Pool *pool, Queue *decisionq, Map *multiversionmap)
 {
-  Pool *pool = solv->pool;
-  Repo *installed = solv->installed;
-  int i, r, noobs;
-  Id p, p2;
-  Solvable *s, *s2;
+  Repo *installed = pool->installed;
+  int i, needmulti;
+  Id p, pp;
+  Solvable *s;
+  Transaction *trans;
+  Map selfdestructmap;
+
+  trans = transaction_create(pool);
+  if (multiversionmap && !multiversionmap->size)
+    multiversionmap = 0;       /* ignore empty map */
+  queue_empty(&trans->steps);
+  map_init(&trans->transactsmap, pool->nsolvables);
+  needmulti = 0;
+  map_init(&selfdestructmap, 0);
+  FOR_PROVIDES(p, pp, LIBSOLV_SELF_DESTRUCT_PKG)
+    {
+      if (!selfdestructmap.size)
+       map_grow(&selfdestructmap, pool->nsolvables);
+      MAPSET(&selfdestructmap, p);
+    }
+  for (i = 0; i < decisionq->count; i++)
+    {
+      p = decisionq->elements[i];
+      s = pool->solvables + (p > 0 ? p : -p);
+      if (!s->repo)
+       continue;
+      if (installed && s->repo == installed && p < 0)
+       MAPSET(&trans->transactsmap, -p);
+      if (!(installed && s->repo == installed) && p > 0)
+       {
+         if (selfdestructmap.size && MAPTST(&selfdestructmap, p))
+           continue;
+         MAPSET(&trans->transactsmap, p);
+         if (multiversionmap && MAPTST(multiversionmap, p))
+           needmulti = 1;
+       }
+    }
+  map_free(&selfdestructmap);
+  MAPCLR(&trans->transactsmap, SYSTEMSOLVABLE);
+  if (needmulti)
+    map_init_clone(&trans->multiversionmap, multiversionmap);
 
-  queue_empty(&solv->transaction);
-  create_transaction_info(solv);
+  create_transaction_info(trans, decisionq);
 
   if (installed)
     {
       FOR_REPO_SOLVABLES(installed, p, s)
        {
-         if (solv->decisionmap[p] > 0)
-           continue;
-         p2 = solver_transaction_pkg(solv, p);
-         if (!p2)
-           queue_push(&solv->transaction, SOLVER_TRANSACTION_ERASE);
-         else
-           {
-             s2 = pool->solvables + p2;
-             if (s->name == s2->name)
-               {
-                 if (s->evr == s2->evr && solvable_identical(s, s2))
-                   queue_push(&solv->transaction, SOLVER_TRANSACTION_REINSTALLED);
-                 else
-                   {
-                     r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
-                     if (r < 0)
-                       queue_push(&solv->transaction, SOLVER_TRANSACTION_UPGRADED);
-                     else if (r > 0)
-                       queue_push(&solv->transaction, SOLVER_TRANSACTION_DOWNGRADED);
-                     else
-                       queue_push(&solv->transaction, SOLVER_TRANSACTION_CHANGED);
-                   }
-               }
-             else
-               queue_push(&solv->transaction, SOLVER_TRANSACTION_REPLACED);
-           }
-         queue_push(&solv->transaction, p);
+         if (MAPTST(&trans->transactsmap, p))
+           queue_push(&trans->steps, p);
        }
     }
-  for (i = 0; i < solv->decisionq.count; i++)
+  for (i = 0; i < decisionq->count; i++)
     {
-      p = solv->decisionq.elements[i];
-      if (p < 0 || p == SYSTEMSOLVABLE)
-       continue;
-      s = pool->solvables + p;
-      if (solv->installed && s->repo == solv->installed)
-       continue;
-      noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p);
-      p2 = solver_transaction_pkg(solv, p);
-      if (noobs)
-       queue_push(&solv->transaction, p2 ? SOLVER_TRANSACTION_MULTIREINSTALL : SOLVER_TRANSACTION_MULTIINSTALL);
-      else if (!p2)
-       queue_push(&solv->transaction, SOLVER_TRANSACTION_INSTALL);
-      else
-       {
-         s2 = pool->solvables + p2;
-         if (s->name == s2->name)
-           {
-             if (s->evr == s2->evr && solvable_identical(s, s2))
-               queue_push(&solv->transaction, SOLVER_TRANSACTION_REINSTALL);
-             else
-               {
-                 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
-                 if (r > 0)
-                   queue_push(&solv->transaction, SOLVER_TRANSACTION_UPGRADE);
-                 else if (r < 0)
-                   queue_push(&solv->transaction, SOLVER_TRANSACTION_DOWNGRADE);
-                 else
-                   queue_push(&solv->transaction, SOLVER_TRANSACTION_CHANGE);
-               }
-           }
-         else
-           queue_push(&solv->transaction, SOLVER_TRANSACTION_REPLACE);
-       }
-      queue_push(&solv->transaction, p);
+      p = decisionq->elements[i];
+      if (p > 0 && MAPTST(&trans->transactsmap, p))
+        queue_push(&trans->steps, p);
     }
+  return trans;
 }
 
-#define TYPE_BROKEN    (1<<0)
-#define TYPE_CON       (1<<1)
-
-#define TYPE_REQ_P     (1<<2)
-#define TYPE_PREREQ_P  (1<<3)
-
-#define TYPE_REQ       (1<<4)
-#define TYPE_PREREQ    (1<<5)
-
-#define EDGEDATA_BLOCK 127
-
-struct transel {
-  Id p;
-  Id type;
-  Id edges;
-  Id invedges;
-  Id mark;
-  Id medianr;
-  Id ddeg;     /* unused */
-};
-
-struct orderdata {
-  Solver *solv;
-  struct transel *tes;
-  int ntes;
-  Id *edgedata;
-  int nedgedata;
-  Id *invedgedata;
-  Map cycletes;
-};
-
-static int
-addedge(struct orderdata *od, Id from, Id to, int type)
+int
+transaction_installedresult(Transaction *trans, Queue *installedq)
 {
-  Solver *solv = od->solv;
-  Pool *pool = solv->pool;
+  Pool *pool = trans->pool;
+  Repo *installed = pool->installed;
   Solvable *s;
-  struct transel *te;
-  int i;
+  int i, cutoff;
+  Id p;
 
-  // printf("addedge %d %d type %d\n", from, to, type);
-  s = pool->solvables + from;
-  if (s->repo == solv->installed && solv->transaction_installed[from - solv->installed->start])
+  queue_empty(installedq);
+  /* first the new installs, than the kept packages */
+  for (i = 0; i < trans->steps.count; i++)
     {
-      /* passive, map to active */
-      if (solv->transaction_installed[from - solv->installed->start] > 0)
-       from = solv->transaction_installed[from - solv->installed->start];
-      else
-       {
-         int ret = 0;
-         Queue ti;
-         Id tibuf[5];
-
-         queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
-         solver_transaction_all_pkgs(solv, from, &ti);
-         for (i = 0; i < ti.count; i++)
-           ret |= addedge(od, ti.elements[i], to, type);
-         queue_free(&ti);
-         return ret;
-       }
+      p = trans->steps.elements[i];
+      s = pool->solvables + p;
+      if (installed && s->repo == installed)
+       continue;
+      queue_push(installedq, p);
     }
-  s = pool->solvables + to;
-  if (s->repo == solv->installed && solv->transaction_installed[to - solv->installed->start])
+  cutoff = installedq->count;
+  if (installed)
     {
-      /* passive, map to active */
-      if (solv->transaction_installed[to - solv->installed->start] > 0)
-       to = solv->transaction_installed[to - solv->installed->start];
-      else
-       {
-         int ret = 0;
-         Queue ti;
-         Id tibuf[5];
-
-         queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
-         solver_transaction_all_pkgs(solv, to, &ti);
-         for (i = 0; i < ti.count; i++)
-           ret |= addedge(od, from, ti.elements[i], type);
-         queue_free(&ti);
-         return ret;
-       }
+      FOR_REPO_SOLVABLES(installed, p, s)
+       if (!MAPTST(&trans->transactsmap, p))
+          queue_push(installedq, p);
     }
+  return cutoff;
+}
 
-  /* map target to te num */
-  for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
-    if (te->p == to)
-      break;
-  if (i == od->ntes)
-    return 0;
-  to = i;
-
-  for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
-    if (te->p == from)
-      break;
-  if (i == od->ntes)
-    return 0;
-
-  if (i == to)
-    return 0;  /* no edges to ourselfes */
-
-  /* printf("edge %d(%s) -> %d(%s) type %x\n", i, solvid2str(pool, od->tes[i].p), to, solvid2str(pool, od->tes[to].p), type); */
+static void
+transaction_make_installedmap(Transaction *trans, Map *installedmap)
+{
+  Pool *pool = trans->pool;
+  Repo *installed = pool->installed;
+  Solvable *s;
+  Id p;
+  int i;
 
-  for (i = te->edges; od->edgedata[i]; i += 2)
-    if (od->edgedata[i] == to)
-      break;
-  /* test of brokenness */
-  if (type == TYPE_BROKEN)
-    return od->edgedata[i] && (od->edgedata[i + 1] & TYPE_BROKEN) != 0 ? 1 : 0;
-  if (od->edgedata[i])
-    {
-      od->edgedata[i + 1] |= type;
-      return 0;
-    }
-  if (i + 1 == od->nedgedata)
+  map_init(installedmap, pool->nsolvables);
+  for (i = 0; i < trans->steps.count; i++)
     {
-      /* printf("tail add %d\n", i - te->edges); */
-      if (!i)
-       te->edges = ++i;
-      od->edgedata = sat_extend(od->edgedata, od->nedgedata, 3, sizeof(Id), EDGEDATA_BLOCK);
+      p = trans->steps.elements[i];
+      s = pool->solvables + p;
+      if (!installed || s->repo != installed)
+        MAPSET(installedmap, p);
     }
-  else
+  if (installed)
     {
-      /* printf("extend %d\n", i - te->edges); */
-      od->edgedata = sat_extend(od->edgedata, od->nedgedata, 3 + (i - te->edges), sizeof(Id), EDGEDATA_BLOCK);
-      if (i > te->edges)
-       memcpy(od->edgedata + od->nedgedata, od->edgedata + te->edges, sizeof(Id) * (i - te->edges));
-      i = od->nedgedata + (i - te->edges);
-      te->edges = od->nedgedata;
+      FOR_REPO_SOLVABLES(installed, p, s)
+       if (!MAPTST(&trans->transactsmap, p))
+          MAPSET(installedmap, p);
     }
-  od->edgedata[i] = to;
-  od->edgedata[i + 1] = type;
-  od->edgedata[i + 2] = 0;
-  od->nedgedata = i + 3;
-  te->ddeg++;
-  od->tes[to].ddeg--;
-  return 0;
 }
 
-static int
-havechoice(struct orderdata *od, Id p, Id q1, Id q2)
+long long
+transaction_calc_installsizechange(Transaction *trans)
 {
-  Solver *solv = od->solv;
-  Id ti1buf[5], ti2buf[5];
-  Queue ti1, ti2;
-  int i, j;
+  Map installedmap;
+  long long change;
 
-  /* both q1 and q2 are uninstalls. check if their TEs intersect */
-  /* common case: just one TE for both packages */
-  printf("havechoice %d %d %d\n", p, q1, q2);
-  if (solv->transaction_installed[q1 - solv->installed->start] == 0)
-    return 1;
-  if (solv->transaction_installed[q2 - solv->installed->start] == 0)
-    return 1;
-  if (solv->transaction_installed[q1 - solv->installed->start] == solv->transaction_installed[q2 - solv->installed->start])
-    return 0;
-  if (solv->transaction_installed[q1 - solv->installed->start] > 0 && solv->transaction_installed[q2 - solv->installed->start] > 0)
-    return 1;
-  queue_init_buffer(&ti1, ti1buf, sizeof(ti1buf)/sizeof(*ti1buf));
-  solver_transaction_all_pkgs(solv, q1, &ti1);
-  queue_init_buffer(&ti2, ti2buf, sizeof(ti2buf)/sizeof(*ti2buf));
-  solver_transaction_all_pkgs(solv, q2, &ti2);
-  for (i = 0; i < ti1.count; i++)
-    for (j = 0; j < ti2.count; j++)
-      if (ti1.elements[i] == ti2.elements[j])
-       {
-         /* found a common edge */
-         queue_free(&ti1);
-         queue_free(&ti2);
-         return 0;
-       }
-  queue_free(&ti1);
-  queue_free(&ti2);
-  return 1;
+  transaction_make_installedmap(trans, &installedmap);
+  change = pool_calc_installsizechange(trans->pool, &installedmap);
+  map_free(&installedmap);
+  return change;
 }
 
-static void
-addsolvableedges(struct orderdata *od, Solvable *s)
+void
+transaction_calc_duchanges(Transaction *trans, DUChanges *mps, int nmps)
 {
-  Solver *solv = od->solv;
-  Pool *pool = solv->pool;
-  Id req, *reqp, con, *conp;
-  Id p, p2, pp2;
-  int i, j, pre, numins;
-  Repo *installed = solv->installed;
-  Solvable *s2;
-  Queue reqq;
-
-  p = s - pool->solvables;
-  queue_init(&reqq);
-  if (s->requires)
-    {
-      reqp = s->repo->idarraydata + s->requires;
-      pre = TYPE_REQ;
-      while ((req = *reqp++) != 0)
-       {
-         if (req == SOLVABLE_PREREQMARKER)
-           {
-             pre = TYPE_PREREQ;
-             continue;
-           }
-         queue_empty(&reqq);
-         numins = 0;   /* number of packages to be installed providing it */
-         FOR_PROVIDES(p2, pp2, req)
-           {
-             s2 = pool->solvables + p2;
-             if (p2 == p)
-               {
-                 reqq.count = 0;       /* self provides */
-                 break;
-               }
-             if (s2->repo == installed && solv->decisionmap[p2] > 0)
-               {
-                 reqq.count = 0;       /* provided by package that stays installed */
-                 break;
-               }
-             if (s2->repo != installed && solv->decisionmap[p2] <= 0)
-               continue;               /* package stays uninstalled */
-             
-             if (s->repo == installed)
-               {
-                 /* s gets uninstalled */
-                 queue_pushunique(&reqq, p2);
-                 if (s2->repo != installed)
-                   numins++;
-               }
-             else
-               {
-                 if (s2->repo == installed)
-                   continue;   /* s2 gets uninstalled */
-                 queue_pushunique(&reqq, p2);
-                 /* EDGE s(A) -> s2(A) */
-               }
-           }
-         if (numins && reqq.count)
-           {
-             /* no mixed types, remove all deps on uninstalls */
-             for (i = j = 0; i < reqq.count; i++)
-               if (pool->solvables[reqq.elements[i]].repo != installed)
-                 reqq.elements[j++] = reqq.elements[i];
-             reqq.count = j;
-           }
-          if (!reqq.count)
-           continue;
-          for (i = 0; i < reqq.count; i++)
-           {
-             int choice = 0;
-             p2 = reqq.elements[i];
-             if (pool->solvables[p2].repo != installed)
-               {
-                 /* all elements of reqq are installs, thus have different TEs */
-                 choice = reqq.count - 1;
-                 if (pool->solvables[p].repo != installed)
-                   {
-#if 0
-                     printf("add inst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
-#endif
-                     addedge(od, p, p2, pre);
-                   }
-                 else
-                   {
-#if 0
-                     printf("add uninst->inst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
-#endif
-                     addedge(od, p, p2, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
-                   }
-               }
-             else
-               {
-#if 1
-                 choice = 0;
-                 for (j = 0; j < reqq.count; j++)
-                   {
-                     if (i == j)
-                       continue;
-                     if (havechoice(od, p, reqq.elements[i], reqq.elements[j]))
-                       choice++;
-                   }
-#endif
-#if 0
-                 printf("add uninst->uninst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
-#endif
-                 addedge(od, p2, p, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
-               }
-           }
-       }
-    }
-  if (s->conflicts)
-    {
-      conp = s->repo->idarraydata + s->conflicts;
-      while ((con = *conp++) != 0)
-       {
-         FOR_PROVIDES(p2, pp2, con)
-           {
-             if (p2 == p)
-               continue;
-             s2 = pool->solvables + p2;
-             if (!s2->repo)
-               continue;
-             if (s->repo == installed)
-               {
-                 if (s2->repo != installed && solv->decisionmap[p2] >= 0)
-                   {
-                     /* deinstall p before installing p2 */
-                     addedge(od, p2, p, TYPE_CON);
-                   }
-               }
-             else
-               {
-                 if (s2->repo == installed && solv->decisionmap[p2] < 0)
-                   {
-                     /* deinstall p2 before installing p */
-                     addedge(od, p, p2, TYPE_CON);
-                   }
-               }
+  Map installedmap;
 
-           }
-       }
-    }
-  queue_free(&reqq);
+  transaction_make_installedmap(trans, &installedmap);
+  pool_calc_duchanges(trans->pool, &installedmap, mps, nmps);
+  map_free(&installedmap);
 }
 
-static inline int
-haveprereq(Pool *pool, Id solvid)
+Transaction *
+transaction_create(Pool *pool)
 {
-  Solvable *s = pool->solvables + solvid;
-  if (s->requires)
-    {
-      Id req, *reqp;
-      int inpre = 0;
-      reqp = s->repo->idarraydata + s->requires;
-      while ((req = *reqp++) != 0)
-       {
-          if (req == SOLVABLE_PREREQMARKER)
-           {
-             inpre = 1;
-             continue;
-           }
-         if (inpre && strncmp(id2str(pool, req), "rpmlib(", 7) != 0)
-           return 1;
-       }
-    }
-  return 0;
+  Transaction *trans = solv_calloc(1, sizeof(*trans));
+  trans->pool = pool;
+  return trans;
 }
 
-void
-breakcycle(struct orderdata *od, Id *cycle)
+Transaction *
+transaction_create_clone(Transaction *srctrans)
 {
-  Pool *pool = od->solv->pool;
-  Id ddegmin, ddegmax, ddeg;
-  int k, l;
-  struct transel *te;
-
-  l = 0;
-  ddegmin = ddegmax = 0;
-  for (k = 0; cycle[k + 1]; k += 2)
-    {
-      MAPSET(&od->cycletes, cycle[k]); /* this te is involved in a cycle */
-      ddeg = od->edgedata[cycle[k + 1] + 1];
-      if (ddeg > ddegmax)
-       ddegmax = ddeg;
-      if (!k || ddeg < ddegmin)
-       {
-         l = k;
-         ddegmin = ddeg;
-         continue;
-       }
-      if (ddeg == ddegmin)
-       {
-         if (haveprereq(pool, od->tes[cycle[l]].p) && !haveprereq(pool, od->tes[cycle[k]].p))
-           {
-             /* prefer k, as l comes from a package with contains scriptlets */
-             l = k;
-             ddegmin = ddeg;
-             continue;
-           }
-         /* same edge value, check for prereq */
-       }
-    }
-
-  od->edgedata[cycle[l + 1] + 1] |= TYPE_BROKEN;
-
-#if 1
-  if (ddegmin < TYPE_REQ)
-    return;
-#endif
-
-
-  /* cycle recorded, print it */
-  if ((ddegmax & TYPE_PREREQ) != 0)
-    printf("CRITICAL ");
-  printf("cycle: --> ");
-  for (k = 0; cycle[k + 1]; k += 2)
-    {
-      te = od->tes +  cycle[k];
-      if ((od->edgedata[cycle[k + 1] + 1] & TYPE_BROKEN) != 0)
-        printf("%s ##%x##> ", solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
-      else
-        printf("%s --%x--> ", solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
-    }
-  printf("\n");
+  Transaction *trans = transaction_create(srctrans->pool);
+  queue_init_clone(&trans->steps, &srctrans->steps);
+  queue_init_clone(&trans->transaction_info, &srctrans->transaction_info);
+  if (srctrans->transaction_installed)
+    {
+      Repo *installed = srctrans->pool->installed;
+      trans->transaction_installed = solv_memdup2(srctrans->transaction_installed, installed->end - installed->start, sizeof(Id));
+    }
+  map_init_clone(&trans->transactsmap, &srctrans->transactsmap);
+  map_init_clone(&trans->multiversionmap, &srctrans->multiversionmap);
+  if (srctrans->orderdata)
+    transaction_clone_orderdata(trans, srctrans);
+  return trans;
 }
 
 void
-solver_order_transaction(Solver *solv)
+transaction_free(Transaction *trans)
 {
-  Pool *pool = solv->pool;
-  Queue *tr = &solv->transaction;
-  Repo *installed = solv->installed;
-  Id type, p;
-  Solvable *s;
-  int i, j, k, numte, numedge;
-  struct orderdata od;
-  struct transel *te;
-  Queue todo, obsq;
-  int cycstart, cycel, broken;
-  Id *cycle, *obstypes;
-  int oldcount;
-  int now;
-
-  POOL_DEBUG(SAT_DEBUG_STATS, "ordering transaction\n");
-  now = sat_timems(0);
-  /* create a transaction element for every active component */
-  numte = 0;
-  for (i = 0; i < tr->count; i += 2)
-    {
-      p = tr->elements[i + 1];
-      s = pool->solvables + p;
-      if (s->repo != installed || !solv->transaction_installed[p - solv->installed->start])
-       numte++;
-    }
-  if (!numte)
-    return;    /* nothing to do... */
-
-  POOL_DEBUG(SAT_DEBUG_STATS, "transaction elements: %d\n", numte);
-  numte++;     /* leave first one zero */
-  memset(&od, 0, sizeof(od));
-  od.solv = solv;
-  od.ntes = numte;
-  od.tes = sat_calloc(numte, sizeof(*od.tes));
-  od.edgedata = sat_extend(0, 0, 1, sizeof(Id), EDGEDATA_BLOCK);
-  od.edgedata[0] = 0;
-  od.nedgedata = 1;
-  map_init(&od.cycletes, numte);
-
-  for (i = 0, te = od.tes + 1; i < tr->count; i += 2)
-    {
-      p = tr->elements[i + 1];
-      s = pool->solvables + p;
-      if (s->repo == installed && solv->transaction_installed[p - solv->installed->start])
-       continue;
-      te->p = p;
-      te->type = tr->elements[i];
-      te->medianr = solvable_lookup_num(s, SOLVABLE_MEDIANR, 0);
-      te++;
-    }
-
-  /* create dependency graph */
-  for (i = 0; i < tr->count; i += 2)
-    {
-      type = tr->elements[i];
-      p = tr->elements[i + 1];
-      addsolvableedges(&od, pool->solvables + p);
-    }
-
-  /* count edges */
-  numedge = 0;
-  for (i = 1, te = od.tes + i; i < numte; i++, te++)
-    for (j = te->edges; od.edgedata[j]; j += 2)
-      numedge++;
-  POOL_DEBUG(SAT_DEBUG_STATS, "edges: %d, edge space: %d\n", numedge, od.nedgedata / 2);
-  
-  /* kill all cycles */
-  broken = 0;
-
-  queue_init(&todo);
-  for (i = numte - 1; i > 0; i--)
-    queue_push(&todo, i);
-
-  while (todo.count)
-    {
-      i = queue_pop(&todo);
-      /* printf("- look at TE %d\n", i); */
-      if (i < 0)
-       {
-         i = -i;
-         od.tes[i].mark = 2;   /* done with that one */
-         continue;
-       }
-      te = od.tes + i;
-      if (te->mark == 2)
-       continue;               /* already finished before */
-      if (te->mark == 0)
-       {
-         int edgestovisit = 0;
-         /* new node, visit edges */
-         for (j = te->edges; (k = od.edgedata[j]) != 0; j += 2)
-           {
-             if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
-               continue;
-             if (od.tes[k].mark == 2)
-               continue;       /* no need to visit again */
-             if (!edgestovisit++)
-               queue_push(&todo, -i);  /* end of edges marker */
-             queue_push(&todo, k);
-           }
-         if (!edgestovisit)
-           te->mark = 2;       /* no edges, done with that one */
-         else
-           te->mark = 1;       /* under investigation */
-         continue;
-       }
-      /* oh no, we found a cycle */
-      /* find start of cycle node (<0) */
-      for (j = todo.count - 1; j >= 0; j--)
-       if (todo.elements[j] == -i)
-         break;
-      assert(j >= 0);
-      cycstart = j;
-      /* build te/edge chain */
-      k = cycstart;
-      for (j = k; j < todo.count; j++)
-       if (todo.elements[j] < 0)
-         todo.elements[k++] = -todo.elements[j];
-      cycel = k - cycstart;
-      assert(cycel > 1);
-      /* make room for edges, two extra element for cycle loop + terminating 0 */
-      while (todo.count < cycstart + 2 * cycel + 2)
-       queue_push(&todo, 0);
-      cycle = todo.elements + cycstart;
-      cycle[cycel] = i;                /* close the loop */
-      cycle[2 * cycel + 1] = 0;        /* terminator */
-      for (k = cycel; k > 0; k--)
-       {
-         cycle[k * 2] = cycle[k];
-         te = od.tes + cycle[k - 1];
-         if (te->mark == 1)
-           te->mark = 0;       /* reset investigation marker */
-         /* printf("searching for edge from %d to %d\n", cycle[k - 1], cycle[k]); */
-         for (j = te->edges; od.edgedata[j]; j += 2)
-           if (od.edgedata[j] == cycle[k])
-             break;
-         assert(od.edgedata[j]);
-         cycle[k * 2 - 1] = j;
-       }
-      /* now cycle looks like this: */
-      /* te1 edge te2 edge te3 ... teN edge te1 0 */
-      breakcycle(&od, cycle);
-      broken++;
-      /* restart with start of cycle */
-      todo.count = cycstart + 1;
-    }
-  POOL_DEBUG(SAT_DEBUG_STATS, "cycles broken: %d\n", broken);
-
-  /* invert all edges */
-  for (i = 1, te = od.tes + i; i < numte; i++, te++)
-    {
-      te->invedges = 1;        /* term 0 */
-      te->mark = 0;    /* backref count */
-    }
-
-  for (i = 1, te = od.tes + i; i < numte; i++, te++)
-    {
-      for (j = te->edges; od.edgedata[j]; j += 2)
-        {
-         if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
-           continue;
-         struct transel *te2 = od.tes + od.edgedata[j];
-         te2->invedges++;
-       }
-    }
-  j = 1;
-  for (i = 1, te = od.tes + i; i < numte; i++, te++)
-    {
-      te->invedges += j;
-      j = te->invedges;
-    }
-  POOL_DEBUG(SAT_DEBUG_STATS, "invedge space: %d\n", j + 1);
-  od.invedgedata = sat_calloc(j + 1, sizeof(Id));
-  for (i = 1, te = od.tes + i; i < numte; i++, te++)
-    {
-      for (j = te->edges; od.edgedata[j]; j += 2)
-        {
-         if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
-           continue;
-         struct transel *te2 = od.tes + od.edgedata[j];
-         od.invedgedata[--te2->invedges] = i;
-         te->mark++;
-       }
-    }
-  /* now the final ordering */
-  for (i = 1, te = od.tes + i; i < numte; i++, te++)
-    if (te->mark == 0)
-      queue_push(&todo, i);
-  assert(todo.count > 0);
-  if (installed)
-    {
-      obstypes = sat_calloc(installed->end - installed->start, sizeof(Id));
-      for (i = 0; i < tr->count; i += 2)
-       {
-         p = tr->elements[i + 1];
-         s = pool->solvables + p;
-         if (s->repo == installed && solv->transaction_installed[p - installed->start])
-           obstypes[p - installed->start] = tr->elements[i];
-       }
-    }
-  else
-    obstypes = 0;
-  oldcount = tr->count;
-  queue_empty(tr);
-  queue_init(&obsq);
-  
-  while (todo.count)
-    {
-      /* select an i */
-      i = todo.count;
-      if (installed)
-       {
-         for (i = 0; i < todo.count; i++)
-           {
-             j = todo.elements[i];
-             if (pool->solvables[od.tes[j].p].repo == installed)
-               break;
-           }
-       }
-      if (i == todo.count)
-       {
-         for (i = 0; i < todo.count; i++)
-           {
-             j = todo.elements[i];
-             if (MAPTST(&od.cycletes, j))
-               break;
-           }
-       }
-      if (i == todo.count)
-        i = 0;
-      te = od.tes + todo.elements[i];
-      queue_push(tr, te->type);
-      queue_push(tr, te->p);
-      s = pool->solvables + te->p;
-      if (installed && s->repo != installed)
-       {
-         queue_empty(&obsq);
-         solver_transaction_all_pkgs(solv, te->p, &obsq);
-         for (j = 0; j < obsq.count; j++)
-           {
-             p = obsq.elements[j];
-             assert(p >= installed->start && p < installed->end);
-             if (obstypes[p - installed->start])
-               {
-                 queue_push(tr, obstypes[p - installed->start]);
-                 queue_push(tr, p);
-                 obstypes[p - installed->start] = 0;
-               }
-           }
-       }
-      if (i < todo.count - 1)
-        memmove(todo.elements + i, todo.elements + i + 1, (todo.count - 1 - i) * sizeof(Id));
-      queue_pop(&todo);
-      for (j = te->invedges; od.invedgedata[j]; j++)
-       {
-         struct transel *te2 = od.tes + od.invedgedata[j];
-         assert(te2->mark > 0);
-         if (--te2->mark == 0)
-           {
-             queue_push(&todo, od.invedgedata[j]);
-           }
-       }
-    }
-  queue_free(&todo);
-  queue_free(&obsq);
-  for (i = 1, te = od.tes + i; i < numte; i++, te++)
-    assert(te->mark == 0);
-  assert(tr->count == oldcount);
-  POOL_DEBUG(SAT_DEBUG_STATS, "transaction ordering took %d ms\n", sat_timems(now));
+  queue_free(&trans->steps);
+  queue_free(&trans->transaction_info);
+  trans->transaction_installed = solv_free(trans->transaction_installed);
+  map_free(&trans->transactsmap);
+  map_free(&trans->multiversionmap);
+  if (trans->orderdata)
+    transaction_free_orderdata(trans);
+  free(trans);
 }