function xcvs_init($argc, $argv)
{
    $this_file = array_shift($argv);
    // argv[0]
    $config_file = array_shift($argv);
    // argv[1]
    if ($argc < 2) {
        xcvs_help($this_file, STDERR);
        exit(3);
    }
    // Load the configuration file and bootstrap Drupal.
    if (!file_exists($config_file)) {
        fwrite(STDERR, "Error: failed to load configuration file.\n");
        exit(4);
    }
    include_once $config_file;
    // Do a full Drupal bootstrap.
    xcvs_bootstrap($xcvs);
    $repository = versioncontrol_get_repository($xcvs['repo_id']);
    if (!isset($repository)) {
        fwrite(STDERR, "The repository corresponding to the configured repo id could not be loaded.\n");
        exit(1);
    }
    // Set the Drupal base path, so that url() returns a proper URL.
    global $base_url;
    $base_url = DRUPAL_SITE;
    // Do the export!
    fwrite(STDOUT, versioncontrol_export_accounts($repository));
    exit(0);
}
function xcvs_init($argc, $argv)
{
    $this_file = array_shift($argv);
    // argv[0]
    $config_file = array_shift($argv);
    // argv[1]
    $passwd_file = array_shift($argv);
    // argv[2]
    if ($argc < 3) {
        xcvs_help($this_file, STDERR);
        exit(3);
    }
    $passwd_file_new = $passwd_file . '.new';
    // Load the configuration file and bootstrap Drupal.
    if (!file_exists($config_file)) {
        fwrite(STDERR, $this_file . ": Failed to load configuration file.\n");
        exit(4);
    }
    require_once $config_file;
    // Do a full Drupal bootstrap.
    xcvs_bootstrap($xcvs);
    $repository = versioncontrol_get_repository($xcvs['repo_id']);
    if (!isset($repository)) {
        fwrite(STDERR, $this_file . ": The repository for the configured repo id could not be loaded.\n");
        exit(5);
    }
    // Set the Drupal base path, so that url() returns a proper URL.
    global $base_url;
    $base_url = DRUPAL_SITE;
    // Retrieve the file contents, and write them to the new file.
    $output = versioncontrol_export_accounts($repository);
    if (!file_put_contents($passwd_file_new, $output)) {
        fwrite(STDERR, $this_file . ": Writing to new passwd file failed!\n");
        exit(6);
    }
    // Rename the file.
    if (!rename($passwd_file_new, $passwd_file)) {
        fwrite(STDERR, $this_file . ": Renaming new passwd file failed!\n");
        exit(7);
    }
    exit(0);
}
function xgit_bootstrap()
{
    global $xgit;
    // Add $drupal_path to current value of the PHP include_path.
    set_include_path(get_include_path() . PATH_SEPARATOR . $xgit['drupal_path']);
    if (empty($_ENV['GIT_DRUPAL_UID'])) {
        fwrite(STDERR, "Error: No environment variable 'GIT_DRUPAL_UID' set or it is empty.\n");
        exit(VERSIONCONTROL_GIT_ERROR_NO_UID);
    }
    $xgit['uid'] = $_ENV['GIT_DRUPAL_UID'];
    chdir($xgit['drupal_path']);
    // Bootstrap Drupal so we can use drupal functions to access the databases, etc.
    if (!file_exists('./includes/bootstrap.inc')) {
        fwrite(STDERR, "Error: failed to load Drupal's bootstrap.inc file.\n");
        exit(VERSIONCONTROL_GIT_ERROR_FAILED_BOOTSTRAP);
    }
    // Set up the multisite directory if necessary.
    if ($xgit['multisite_directory']) {
        $_SERVER['HTTP_HOST'] = $xgit['multisite_directory'];
        // Set a dummy script name, so the multisite configuration
        // file search will always trigger.
        $_SERVER['SCRIPT_NAME'] = '/foo';
    }
    require_once './includes/bootstrap.inc';
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
    // Overwrite db_prefix if this is a simpletest run.
    if (isset($GLOBALS['simpletest_db_prefix'])) {
        $GLOBALS['db_prefix'] = $GLOBALS['simpletest_db_prefix'];
    }
    require_once drupal_get_path('module', 'versioncontrol_git') . '/versioncontrol_git.module';
    require_once drupal_get_path('module', 'versioncontrol_git') . '/versioncontrol_git.log.inc';
    $xgit['repo'] = versioncontrol_get_repository($xgit['repo_id']);
    if (!isset($_ENV['GIT_DIR'])) {
        xgit_help($this_file, STDERR);
        exit(VERSIONCONTROL_GIT_ERROR_NO_GIT_DIR);
    }
    $xgit['git_dir'] = $_ENV['PWD'];
    if (empty($xgit['repo'])) {
        $message = "Error: git repository with id '%s' does not exist.\n";
        fwrite(STDERR, sprintf($message, $xgit['repo_id']));
        exit(VERSIONCONTROL_GIT_ERROR_NO_REPOSITORY);
    }
}