die(plugin_lang_get('invalid_checkin_url'));
}
# Let plugins try to intepret POST data before we do
$t_predata = event_signal('EVENT_SOURCE_PRECOMMIT');
# Expect plugin data in form of array( repo_name, data )
if (is_array($t_predata) && count($t_predata) == 2) {
    $t_repo = $t_predata['repo'];
    $f_data = $t_predata['data'];
} else {
    $f_repo_name = gpc_get_string('repo_name', '');
    $f_data = gpc_get_string('data');
    # Try to find the repository by name
    $t_repo = SourceRepo::load_by_name($f_repo_name);
}
# Repo not found
if (is_null($t_repo)) {
    die(plugin_lang_get('invalid_repo'));
}
$t_vcs = SourceVCS::repo($t_repo);
# Let the plugins handle commit data
$t_changesets = $t_vcs->commit($t_repo, $f_data);
# Changesets couldn't be loaded apparently
if (!is_array($t_changesets)) {
    die(plugin_lang_get('invalid_changeset'));
}
# No more changesets to checkin
if (count($t_changesets) < 1) {
    return;
}
Source_Process_Changesets($t_changesets);
# keep checking for more changesets to import
$t_error = false;
while (true) {
    # import the next batch of changesets
    $t_changesets = $t_vcs->import_full($t_new_repo);
    # check for errors
    if (!is_array($t_changesets)) {
        $t_error = true;
        break;
    }
    # if no more entries, we're done
    if (count($t_changesets) < 1) {
        break;
    }
    $t_new_repo->name = $t_repo->name;
    Source_Process_Changesets($t_changesets, $t_new_repo);
}
# if we errored, delete the new repo and stop
if ($t_error) {
    SourceRepo::delete($t_new_repo->id);
    echo '<br/><div class="center">';
    echo plugin_lang_get('import_full_failed'), '<br/>';
    print_bracket_link(plugin_page('repo_manage_page') . '&id=' . $t_repo->id, plugin_lang_get('back_repo'));
    echo '</div>';
    # otherwise, rename and save the new repo, then delete the old
} else {
    $t_new_repo->save();
    SourceRepo::delete($t_repo->id);
    $t_stats = $t_new_repo->stats();
    echo '<br/><div class="center">';
    echo sprintf(plugin_lang_get('import_stats'), $t_stats['changesets'], $t_stats['files'], $t_stats['bugs']), '<br/>';