- refactor select_patches
authorMichael Schroeder <mls@suse.de>
Fri, 3 Jun 2011 16:06:50 +0000 (18:06 +0200)
committerMichael Schroeder <mls@suse.de>
Fri, 3 Jun 2011 16:06:50 +0000 (18:06 +0200)
examples/solv.c

index 2e8b343665a653a38987f55302273fd36eb01057..3ceab9465d8826041ea8a28339f6e23593c81e4c 100644 (file)
@@ -2500,6 +2500,58 @@ rewrite_repos(Pool *pool, Id *addedfileprovides)
   map_free(&providedids);
 }
 
+static void
+select_patches(Pool *pool, Queue *job)
+{
+  Id p, pp;
+  int pruneyou = 0;
+  Map installedmap;
+  Solvable *s;
+
+  map_init(&installedmap, pool->nsolvables);
+  if (pool->installed)
+    FOR_REPO_SOLVABLES(pool->installed, p, s)
+      MAPSET(&installedmap, p);
+
+  /* install all patches */
+  for (p = 1; p < pool->nsolvables; p++)
+    {
+      const char *type;
+      int r;
+      Id p2;
+
+      s = pool->solvables + p;
+      if (strncmp(pool_id2str(pool, s->name), "patch:", 6) != 0)
+       continue;
+      FOR_PROVIDES(p2, pp, s->name)
+       {
+         Solvable *s2 = pool->solvables + p2;
+         if (s2->name != s->name)
+           continue;
+         r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
+         if (r < 0 || (r == 0 && p > p2))
+           break;
+       }
+      if (p2)
+       continue;
+      type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
+      if (type && !strcmp(type, "optional"))
+       continue;
+      r = solvable_trivial_installable_map(s, &installedmap, 0);
+      if (r == -1)
+       continue;
+      if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
+       {
+         if (!pruneyou++)
+           queue_empty(job);
+       }
+      else if (pruneyou)
+       continue;
+      queue_push2(job, SOLVER_SOLVABLE, p);
+    }
+  map_free(&installedmap);
+}
+
 #define MODE_LIST        0
 #define MODE_INSTALL     1
 #define MODE_ERASE       2
@@ -2843,54 +2895,7 @@ main(int argc, char **argv)
     }
 
   if (mainmode == MODE_PATCH)
-    {
-      int pruneyou = 0;
-      Map installedmap;
-      Solvable *s;
-
-      map_init(&installedmap, pool->nsolvables);
-      if (pool->installed)
-        FOR_REPO_SOLVABLES(pool->installed, p, s)
-         MAPSET(&installedmap, p);
-
-      /* install all patches */
-      for (p = 1; p < pool->nsolvables; p++)
-       {
-         const char *type;
-         int r;
-         Id p2;
-
-         s = pool->solvables + p;
-         if (strncmp(pool_id2str(pool, s->name), "patch:", 6) != 0)
-           continue;
-         FOR_PROVIDES(p2, pp, s->name)
-           {
-             Solvable *s2 = pool->solvables + p2;
-             if (s2->name != s->name)
-               continue;
-             r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
-             if (r < 0 || (r == 0 && p > p2))
-               break;
-           }
-         if (p2)
-           continue;
-         type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
-         if (type && !strcmp(type, "optional"))
-           continue;
-         r = solvable_trivial_installable_map(s, &installedmap, 0);
-         if (r == -1)
-           continue;
-         if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
-           {
-             if (!pruneyou++)
-               queue_empty(&job);
-           }
-         else if (pruneyou)
-           continue;
-         queue_push2(&job, SOLVER_SOLVABLE, p);
-       }
-      map_free(&installedmap);
-    }
+    select_patches(pool, &job);
 
   // add mode
   for (i = 0; i < job.count; i += 2)