Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.491
diff -u -p -r1.491 form.inc
--- includes/form.inc	13 Sep 2010 01:09:25 -0000	1.491
+++ includes/form.inc	14 Sep 2010 15:43:46 -0000
@@ -929,39 +929,16 @@ function drupal_prepare_form($form_id, &
     }
   }
 
-  // Check theme functions for this form.
+  // If no #theme has been set, automatically apply theme suggestions.
   // theme_form() itself is in #theme_wrappers and not #theme. Therefore, the
   // #theme function only has to care for rendering the inner form elements,
   // not the form itself.
-  drupal_theme_initialize();
-  $registry = theme_get_registry();
-  // If #theme has been set, check whether the theme function(s) exist, or
-  // remove the suggestion(s), so drupal_render() renders the children.
-  if (isset($form['#theme'])) {
-    if (is_array($form['#theme'])) {
-      foreach ($form['#theme'] as $key => $suggestion) {
-        if (!isset($registry[$suggestion])) {
-          unset($form['#theme'][$key]);
-        }
-      }
-      if (empty($form['#theme'])) {
-        unset($form['#theme']);
-      }
-    }
-    else {
-      if (!isset($registry[$form['#theme']])) {
-        unset($form['#theme']);
-      }
-    }
-  }
-  // Only try to auto-suggest theme functions, if #theme has not been set.
-  else {
-    if (isset($registry[$form_id])) {
-      $form['#theme'] = $form_id;
-    }
-    elseif (isset($form_state['build_info']['base_form_id']) && isset($registry[$form_state['build_info']['base_form_id']])) {
-      $form['#theme'] = $form_state['build_info']['base_form_id'];
+  if (!isset($form['#theme'])) {
+    $form['#theme'] = array();
+    if (isset($form_state['build_info']['base_form_id'])) {
+      $form['#theme'][] = $form_state['build_info']['base_form_id'];
     }
+    $form['#theme'][] = $form_id;
   }
 
   // Invoke hook_form_alter(), hook_form_BASE_FORM_ID_alter(), and
Index: includes/install.core.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/install.core.inc,v
retrieving revision 1.28
diff -u -p -r1.28 install.core.inc
--- includes/install.core.inc	1 Sep 2010 01:24:05 -0000	1.28
+++ includes/install.core.inc	14 Sep 2010 15:41:48 -0000
@@ -275,12 +275,12 @@ function install_begin_request(&$install
   require_once DRUPAL_ROOT . '/includes/cache-install.inc';
   $conf['cache_default_class'] = 'DrupalFakeCache';
 
-  // Prepare for themed output, if necessary. We need to run this at the
-  // beginning of the page request to avoid a different theme accidentally
-  // getting set.
-  if ($install_state['interactive']) {
-    drupal_maintenance_theme();
-  }
+  // Prepare for themed output. We need to run this at the beginning of the
+  // page request to avoid a different theme accidentally getting set. (We also
+  // need to run it even in the case of command-line installations, to prevent
+  // any code in the installer that happens to initialize the theme system from
+  // accessing the database before it is set up yet.)
+  drupal_maintenance_theme();
 
   // Check existing settings.php.
   $install_state['settings_verified'] = install_verify_settings();
Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.610
diff -u -p -r1.610 theme.inc
--- includes/theme.inc	11 Sep 2010 00:03:41 -0000	1.610
+++ includes/theme.inc	14 Sep 2010 15:45:31 -0000
@@ -768,7 +768,11 @@ function theme($hook, $variables = array
       }
     }
     if (!isset($hooks[$hook])) {
-      watchdog('theme', 'Theme key "@key" not found.', array('@key' => $hook), WATCHDOG_WARNING);
+      // Only log a message when not trying theme suggestions ($hook being an
+      // array).
+      if (!isset($candidate)) {
+        watchdog('theme', 'Theme key "@key" not found.', array('@key' => $hook), WATCHDOG_WARNING);
+      }
       return '';
     }
   }
