The following commit has been merged in the master branch:
commit 9a830e9d5fcb8c48bb84bdebb3f606984ce2ca45
Author: Jonathan Nieder <[email protected]>
Date:   Wed Apr 14 12:17:29 2010 +0200

    dpkg: Factor out package-listing functions from packages()
    
    Split packages() into bite-sized pieces. No functional change
    intended.
    
    Signed-off-by: Jonathan Nieder <[email protected]>
    Signed-off-by: Guillem Jover <[email protected]>

diff --git a/src/packages.c b/src/packages.c
index 0c1a69b..392001a 100644
--- a/src/packages.c
+++ b/src/packages.c
@@ -54,12 +54,72 @@ add_to_queue(struct pkginfo *pkg)
   pkg_queue_push(&queue, pkg);
 }
 
-void packages(const char *const *argv) {
+static void
+enqueue_pending(void)
+{
   struct pkgiterator *it;
   struct pkginfo *pkg;
+
+  it = iterpkgstart();
+  while ((pkg = iterpkgnext(it)) != NULL) {
+    switch (cipaction->arg) {
+    case act_configure:
+      if (!(pkg->status == stat_unpacked ||
+            pkg->status == stat_halfconfigured ||
+            pkg->trigpend_head))
+        continue;
+      if (pkg->want != want_install)
+        continue;
+      break;
+    case act_triggers:
+      if (!pkg->trigpend_head)
+        continue;
+      if (pkg->want != want_install)
+        continue;
+      break;
+    case act_remove:
+    case act_purge:
+      if (pkg->want != want_purge) {
+        if (pkg->want != want_deinstall)
+          continue;
+        if (pkg->status == stat_configfiles)
+          continue;
+      }
+      if (pkg->status == stat_notinstalled)
+        continue;
+      break;
+    default:
+      internerr("unknown action '%d'", cipaction->arg);
+    }
+    add_to_queue(pkg);
+  }
+  iterpkgend(it);
+}
+
+static void
+enqueue_specified(const char *const *argv)
+{
   const char *thisarg;
   size_t l;
-  
+
+  while ((thisarg = *argv++) != NULL) {
+    struct pkginfo *pkg;
+
+    pkg = findpackage(thisarg);
+    if (pkg->status == stat_notinstalled) {
+      l = strlen(pkg->name);
+
+      if (l >= sizeof(DEBEXT) && !strcmp(pkg->name+l-sizeof(DEBEXT)+1,DEBEXT))
+        badusage(_("you must specify packages by their own names,"
+                   " not by quoting the names of the files they come in"));
+    }
+    add_to_queue(pkg);
+  }
+}
+
+void
+packages(const char *const *argv)
+{
   trigproc_install_hooks();
 
   modstatdb_init(admindir,
@@ -70,59 +130,15 @@ void packages(const char *const *argv) {
   log_message("startup packages %s", cipaction->olong);
 
   if (f_pending) {
-
     if (*argv)
       badusage(_("--%s --pending does not take any non-option 
arguments"),cipaction->olong);
 
-    it= iterpkgstart();
-    while ((pkg = iterpkgnext(it)) != NULL) {
-      switch (cipaction->arg) {
-      case act_configure:
-        if (!(pkg->status == stat_unpacked ||
-              pkg->status == stat_halfconfigured ||
-              pkg->trigpend_head))
-          continue;
-        if (pkg->want != want_install)
-          continue;
-        break;
-      case act_triggers:
-        if (!pkg->trigpend_head)
-          continue;
-        if (pkg->want != want_install)
-          continue;
-        break;
-      case act_remove:
-      case act_purge:
-        if (pkg->want != want_purge) {
-          if (pkg->want != want_deinstall) continue;
-          if (pkg->status == stat_configfiles) continue;
-        }
-        if (pkg->status == stat_notinstalled)
-          continue;
-        break;
-      default:
-        internerr("unknown action '%d'", cipaction->arg);
-      }
-      add_to_queue(pkg);
-    }
-    iterpkgend(it);
-
+    enqueue_pending();
   } else {
-        
     if (!*argv)
       badusage(_("--%s needs at least one package name argument"), 
cipaction->olong);
-    
-    while ((thisarg = *argv++) != NULL) {
-      pkg= findpackage(thisarg);
-      if (pkg->status == stat_notinstalled) {
-        l= strlen(pkg->name);
-        if (l >= sizeof(DEBEXT) && 
!strcmp(pkg->name+l-sizeof(DEBEXT)+1,DEBEXT))
-          badusage(_("you must specify packages by their own names,"
-                   " not by quoting the names of the files they come in"));
-      }
-      add_to_queue(pkg);
-    }
 
+    enqueue_specified(argv);
   }
 
   ensure_diversions();

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to