? includes/table.inc
Index: drush.api.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/drush.api.php,v
retrieving revision 1.9
diff -u -p -r1.9 drush.api.php
--- drush.api.php	11 Aug 2010 04:40:56 -0000	1.9
+++ drush.api.php	12 Aug 2010 12:07:49 -0000
@@ -157,7 +157,7 @@ function hook_drush_pm_adjust_download_d
  * the built-in --sanitize option of sql-sync, but simplified
  * to only work with default values on Drupal 6 + mysql.
  *
- * We test for both 'my-sanitize' and 'destination-my-sanitize'
+ * We test for both 'sanitize' and 'destination-sanitize'
  * options because we want to allow options set in a site-alias
  * to control the post-sync operations.  The options from the
  * destination alias are applied to the drush options context
@@ -166,9 +166,9 @@ function hook_drush_pm_adjust_download_d
  * @see drush_sql_pre_sql_sync().
  */
 function drush_hook_pre_sql_sync($source = NULL, $destination = NULL) {
-  if (drush_get_option(array('my-sanitize', 'destination-my-sanitize'), FALSE)) {
+  if (drush_get_option(array('sanitize', 'destination-sanitize'), FALSE)) {
     drush_sql_register_post_sync_op('my-sanitize-id', 
-      dt('Reset passwords and email addresses in user table', 
+      dt('Reset passwords and email addresses in user table'), 
       "update users set pass = MD5('password'), mail = concat('user+', uid, '@localhost') where uid > 0;");
   }
 }
Index: commands/sql/sync.sql.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/sql/sync.sql.inc,v
retrieving revision 1.28
diff -u -p -r1.28 sync.sql.inc
--- commands/sql/sync.sql.inc	11 Aug 2010 04:40:56 -0000	1.28
+++ commands/sql/sync.sql.inc	12 Aug 2010 12:07:49 -0000
@@ -4,12 +4,12 @@
 require_once DRUSH_BASE_PATH . '/commands/core/rsync.core.inc';
 
 /**
- * Sql sync validate function.  Look up the version of the
+ * Sql sync init function.  Look up the version of the
  * Drupal site being sync'ed.  At least one of the sites
  * must be local for this to work; if both sites are remote,
  * then $major_version will be FALSE.
  */
-function drush_sql_sync_validate($source = NULL, $destination = NULL) {
+function drush_sql_sync_init($source = NULL, $destination = NULL) {
   // Preflight destination in case it defines the alias used by the source
   _drush_sitealias_get_record($destination);
 
@@ -24,13 +24,12 @@ function drush_sql_sync_validate($source
   // actually use the databases record at this time.
   sitealias_get_databases_from_record($source_settings);
   sitealias_get_databases_from_record($destination_settings);
-
-  // Cache what version of Drupal we're syncing.
-  // Note that the version is cached in drush.inc; just
-  // call drush_drupal_version or drush_drupal_major_version
-  // to retrieve it later.
-  $major_version = drush_drupal_major_version_of_site(array($source_settings, $destination_settings));
-
+  
+  // Disable the fast but inacurate commandfile searching in DRUSH_BOOTSTRAP_DRUPAL_SITE,
+  // and rely on DRUSH_BOOTSTRAP_DRUPAL_FULL to bring in only the enabled commandfiles.
+  drush_set_option('enabled-commandfiles-only', TRUE);
+  drush_bootstrap_max_to_local_sitealias(array($source_settings, $destination_settings));
+  
   return TRUE;
 }
 
Index: includes/command.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/command.inc,v
retrieving revision 1.76
diff -u -p -r1.76 command.inc
--- includes/command.inc	22 Apr 2010 06:33:48 -0000	1.76
+++ includes/command.inc	12 Aug 2010 12:07:50 -0000
@@ -287,6 +287,18 @@ function drush_invoke($command) {
   // for better readability after the allow-spaces-in-commands
   // backwards-compatibility feature is removed.
   $hook = strtr($command, "- ", "__"); // n.b. str tr, not str str.
+  
+  // Call the hook init function, if it exists.
+  // If a command needs to bootstrap, it should do so in _init
+  // and not later; otherwise, the commandfile list might not
+  // be complete.
+  $func = 'drush_' . $hook . '_init';
+  if (function_exists($func)) {
+    drush_log(dt("Calling drush command init function: !func", array('!func' => $func)), 'bootstrap');
+    call_user_func_array($func, $args);
+  }
+
+  // Get the list of command files.
   $list = drush_commandfile_list();
 
   $functions = array();
@@ -522,11 +534,13 @@ function _drush_find_commandfiles($phase
       }
       break;
     case DRUSH_BOOTSTRAP_DRUPAL_SITE:
-      $searchpath[] = conf_path() . '/modules';
-      // Too early for variable_get('install_profile', 'default'); Just use default.
-      $searchpath[] = "profiles/default/modules";
-      // Add all module paths, even disabled modules. Prefer speed over accuracy.
-      $searchpath[] = 'sites/all/modules';
+      if (!drush_get_option('enabled-commandfiles-only', FALSE)) {
+        $searchpath[] = conf_path() . '/modules';
+        // Too early for variable_get('install_profile', 'default'); Just use default.
+        $searchpath[] = "profiles/default/modules";
+        // Add all module paths, even disabled modules. Prefer speed over accuracy.
+        $searchpath[] = 'sites/all/modules';
+      }
       break;
     case DRUSH_BOOTSTRAP_DRUPAL_FULL:
       // Add enabled module paths. Since we are bootstrapped,
Index: includes/environment.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/environment.inc,v
retrieving revision 1.90
diff -u -p -r1.90 environment.inc
--- includes/environment.inc	5 Aug 2010 22:14:16 -0000	1.90
+++ includes/environment.inc	12 Aug 2010 12:07:51 -0000
@@ -268,6 +268,46 @@ function drush_bootstrap_max($max_phase_
   return $phase_index;
 }
 
+/**
+ * Bootstrap the specified site alias.
+ *
+ * @param $site_record
+ *   The alias record for the given site alias.
+ *   @see drush_sitealias_get_record().
+ * @param $max_phase_index
+ *   Only attempt bootstrap to the specified level.
+ */
+function drush_bootstrap_max_to_sitealias($site_record, $max_phase_index = NULL) {
+  drush_sitealias_set_alias_context($site_record);
+  drush_bootstrap_max($max_phase_index);
+}
+
+/**
+ * Bootstrap the first site alias in the provided list 
+ * that is local.  This is used, for example, by sql-sync,
+ * which passes the source and destination targets so that
+ * the local site is bootstrapped.
+ *
+ * @param $site_record
+ *   The alias record for the given site alias.
+ *   @see drush_sitealias_get_record().
+ * @param $max_phase_index
+ *   Only attempt bootstrap to the specified level.
+ * @returns array
+ *   The alias record for the site that was bootstrapped
+ */
+function drush_bootstrap_max_to_local_sitealias($site_list, $max_phase_index = NULL) {
+  $bootstrapped_site = NULL;
+  
+  foreach ($site_list as $site) {
+    if (($bootstrapped_site == NULL) && (array_key_exists('root', $site) && !array_key_exists('remote-host', $site))) {
+      $bootstrapped_site = $site;
+      drush_bootstrap_max_to_sitealias($site, $max_phase_index);
+    }
+  }
+  
+  return $bootstrapped_site;
+}
 
 /**
  * Helper function to collect any errors that occur during the bootstrap process.
