Exemplo n.º 1
0
/**
 * The main function of the hook.
 *
 * Expects the following arguments:
 *
 *   - $argv[1] - The path of the configuration file, xsvn-config.php.
 *   - $argv[2] - The path of the subversion repository.
 *   - $argv[3] - Commit transaction name.
 *
 * @param argc
 *   The number of arguments on the command line.
 *
 * @param argv
 *   Array of the arguments.
 */
function xsvn_init($argc, $argv)
{
    $this_file = array_shift($argv);
    // argv[0]
    if ($argc != 4) {
        xsvn_help($this_file, STDERR);
        exit(3);
    }
    $config_file = array_shift($argv);
    // argv[1]
    $repo = array_shift($argv);
    // argv[2]
    $tx = array_shift($argv);
    // argv[3]
    // Load the configuration file and bootstrap Drupal.
    if (!file_exists($config_file)) {
        fwrite(STDERR, t('Error: failed to load configuration file.') . "\n");
        exit(4);
    }
    require_once $config_file;
    // Third argument is FALSE to indicate a transaction.
    $username = xsvn_get_commit_author($tx, $repo, FALSE);
    $item_paths = xsvn_get_commit_files($tx, $repo, FALSE);
    // Admins and other privileged users don't need to go through any checks.
    if (!in_array($username, $xsvn['allowed_users'])) {
        // Do a full Drupal bootstrap.
        xsvn_bootstrap($xsvn);
        // Construct a minimal commit operation array.
        $operation = array('type' => VERSIONCONTROL_OPERATION_COMMIT, 'repo_id' => $xsvn['repo_id'], 'username' => $username, 'labels' => array());
        // Set the $operation_items array from the item path and status.
        $operation_items = array();
        foreach ($item_paths as $path => $status) {
            $item = xsvn_get_operation_item($path, $status);
            $operation_items[$path] = $item;
        }
        $access = versioncontrol_has_write_access($operation, $operation_items);
        // Fail and print out error messages if commit access has been denied.
        if (!$access) {
            fwrite(STDERR, implode("\n\n", versioncontrol_get_access_errors()) . "\n\n");
            exit(6);
        }
    }
}
Exemplo n.º 2
0
function xcvs_init($argc, $argv)
{
    $this_file = array_shift($argv);
    // argv[0]
    if ($argc < 7) {
        xcvs_help($this_file, STDERR);
        exit(3);
    }
    $config_file = array_shift($argv);
    // argv[1]
    $username = array_shift($argv);
    // argv[2]
    $tag_name = array_shift($argv);
    // argv[3]
    $type = array_shift($argv);
    // argv[4]
    $cvs_op = array_shift($argv);
    // argv[5]
    $dir = array_shift($argv);
    // argv[6]
    // 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;
    // Check temporary file storage.
    $tempdir = xcvs_get_temp_directory($xcvs['temp']);
    // Admins and other privileged users don't need to go through any checks.
    if (!in_array($username, $xcvs['allowed_users'])) {
        // Do a full Drupal bootstrap.
        xcvs_bootstrap($xcvs);
        // Gather info for each tagged/branched file.
        $items = array();
        while (!empty($argv)) {
            $filename = array_shift($argv);
            $source_branch = array_shift($argv);
            $old = array_shift($argv);
            $new = array_shift($argv);
            $path = '/' . $dir . '/' . $filename;
            if ($type == 'N') {
                // is a tag
                $label_type = VERSIONCONTROL_OPERATION_TAG;
            } else {
                if ($type == 'T') {
                    // is a branch
                    $label_type = VERSIONCONTROL_OPERATION_BRANCH;
                }
            }
            if (in_array($cvs_op, array('add', 'mov'))) {
                $items[VERSIONCONTROL_ACTION_ADDED][$label_type][$path] = array('type' => VERSIONCONTROL_ITEM_FILE, 'path' => $path, 'revision' => $new);
                // $source_branch is not currently being used by Version Control API.
            }
            if (in_array($cvs_op, array('del', 'mov'))) {
                $item = array('type' => VERSIONCONTROL_ITEM_FILE, 'path' => $path, 'revision' => $old);
                if ($type == '?') {
                    $label_type = xcvs_branch_or_tag($tag_name, $item);
                }
                $items[VERSIONCONTROL_ACTION_DELETED][$label_type][$path] = $item;
            }
        }
        if (empty($items)) {
            fwrite(STDERR, "Operation doesn't affect any item, aborting.\n");
            exit(7);
        }
        foreach ($items as $action => $items_by_action) {
            foreach ($items_by_action as $label_type => $operation_items) {
                $operation = array('type' => $label_type, 'username' => $username, 'repo_id' => $xcvs['repo_id']);
                $label = array('type' => $label_type, 'name' => $tag_name, 'action' => $action);
                $operation['labels'] = array($label);
                $access = versioncontrol_has_write_access($operation, $operation_items);
                // Fail and print out error messages if branch/tag access has been denied.
                if (!$access) {
                    fwrite(STDERR, implode("\n\n", versioncontrol_get_access_errors()) . "\n\n");
                    exit(7);
                }
            }
        }
    }
    // If we get as far as this, the tagging/branching operation may happen.
    // Remember this directory so that posttag can combine tags/branches
    // from different directories in one tag/branch entry.
    $lastlog = $tempdir . '/xcvs-lastlog.' . posix_getpgrp();
    xcvs_log_add($lastlog, $dir);
    // Also remember the label type per item - posttag won't be able to determine
    // this by itself because the action has already been executed. Only needed
    // for branch/tag deletions - 'add' and 'mov' don't need this kind of crap.
    if ($cvs_op == 'del') {
        $taginfo = $tempdir . '/xcvs-taginfo.' . posix_getpgrp();
        foreach ($items as $action => $items_by_action) {
            foreach ($items_by_action as $label_type => $operation_items) {
                foreach ($operation_items as $path => $item) {
                    $ltype = $label_type == VERSIONCONTROL_OPERATION_TAG ? 'N' : 'T';
                    xcvs_log_add($taginfo, "{$path}," . $ltype . "\n", 'a');
                }
            }
        }
    }
    exit(0);
}
Exemplo n.º 3
0
/**
 * The main function of the hook.
 *
 * Expects the following arguments:
 *
 *   - $argv[1] - The path of the configuration file, xgit-config.php.
 *   - $argv[2] - The name of the ref being stored.
 *   - $argv[3] - The old object name stored in the ref.
 *   - $argv[4] - The new objectname to be stored in the ref.
 *
 * @param argc
 *   The number of arguments on the command line.
 *
 * @param argv
 *   Array of the arguments.
 */
function xgit_init($argc, $argv)
{
    $this_file = array_shift($argv);
    // argv[0]
    if ($argc != 5) {
        xgit_help($this_file, STDERR);
        exit(VERSIONCONTROL_GIT_ERROR_WRONG_ARGC);
    }
    $config_file = array_shift($argv);
    // argv[1]
    $ref = array_shift($argv);
    // argv[2]
    $old_obj = array_shift($argv);
    // argv[3]
    $new_obj = array_shift($argv);
    // argv[4]
    // Load the configuration file and bootstrap Drupal.
    if (!file_exists($config_file)) {
        fwrite(STDERR, t('Error: failed to load configuration file.') . "\n");
        exit(VERSIONCONTROL_GIT_ERROR_NO_CONFIG);
    }
    include_once $config_file;
    global $xgit;
    // Admins and other privileged users don't need to go through any checks.
    if (!in_array($xgit['uid'], $xgit['allowed_users'])) {
        // Do a full Drupal bootstrap.
        xgit_bootstrap();
        $ref_type = xgit_ref_type($ref);
        if ($ref_type === FALSE) {
            fwrite(STDERR, "Given reference '{$ref}' is invalid.\n\n");
            exit(VERSIONCONTROL_GIT_ERROR_INVALID_REF);
        }
        try {
            _xgit_assert_type(array($new_obj => array('commit', 'tag', 'empty'), $old_obj => array('commit', 'tag', 'empty')));
        } catch (Exception $e) {
            fwrite(STDERR, $e->getMessage());
            exit(VERSIONCONTROL_GIT_ERROR_INVALID_OBJ);
        }
        // Debugging help
        if ($GLOBALS['xgit_debug']) {
            $commits = xgit_get_commits($old_obj, $new_obj);
            $commits = implode(' ', $commits);
            fwrite(STDERR, 'DEBUG COMMITS:' . $commits . "\n");
        }
        $label = xgit_label_for($ref, $old_obj, $new_obj);
        foreach (xgit_get_commits($old_obj, $new_obj) as $commit) {
            $access = xgit_check_commit_access($commit, $label);
            // Fail and print out error messages if commit access has been denied.
            if (!$access) {
                fwrite(STDERR, implode("\n\n", versioncontrol_get_access_errors()) . "\n\n");
                exit(VERSIONCONTROL_GIT_ERROR_NO_ACCESS);
            }
        }
    }
    // Everything succeeded. Allow operation to complete.
    exit(0);
}
Exemplo n.º 4
0
function xcvs_init($argc, $argv)
{
    $this_file = array_shift($argv);
    // argv[0]
    if ($argc < 5) {
        xcvs_help($this_file, STDERR);
        exit(3);
    }
    $files = array_slice($argv, 4);
    $config_file = array_shift($argv);
    // argv[1]
    $username = array_shift($argv);
    // argv[2]
    $dir = array_shift($argv);
    // argv[3]
    $filenames = $argv;
    // the rest of the command line arguments
    // 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;
    // Check temporary file storage.
    $tempdir = xcvs_get_temp_directory($xcvs['temp']);
    // Admins and other privileged users don't need to go through any checks.
    if (!in_array($username, $xcvs['allowed_users'])) {
        // Do a full Drupal bootstrap.
        xcvs_bootstrap($xcvs);
        // Construct a minimal commit operation array.
        $operation = array('type' => VERSIONCONTROL_OPERATION_COMMIT, 'repo_id' => $xcvs['repo_id'], 'username' => $username, 'labels' => xcvs_commit_labels($xcvs['cwd']));
        $operation_items = array();
        foreach ($filenames as $filename) {
            list($path, $item) = xcvs_get_operation_item($filename, $dir, $xcvs['cwd']);
            $operation_items[$path] = $item;
        }
        $access = versioncontrol_has_write_access($operation, $operation_items);
        // Fail and print out error messages if commit access has been denied.
        if (!$access) {
            fwrite(STDERR, implode("\n\n", versioncontrol_get_access_errors()) . "\n\n");
            exit(6);
        }
    }
    // If we get as far as this, the commit may happen.
    // Remember this directory so that loginfo can combine commits
    // from different directories in one commit entry.
    $lastlog = $tempdir . '/xcvs-lastlog.' . posix_getpgrp();
    xcvs_log_add($lastlog, $dir);
    exit(0);
}