Refactor repository reparse scripts to be more useful

Summary:
Splitting up D960 a bit, see that for context.

We currently have two scripts, "parse_one_commit.php" and
"reparse_all_commit_messages.php", but they're sort of silly and you can't do
certain things with them. Replace them with one script which is more flexible
and can do specific reparse steps on individual commits or entire repos.

I left the old scripts as stubs since I think there are some FB wiki docs and
stuff that mention them. I'll delete them in a month or whenever I remember or
something.

Test Plan: Ran "reparse.php" with various arguments, including vs-one-commit,
vs-repository, with --trace, and against different types of repos.

Reviewers: Makinde, jungejason, nh, tuomaspelkonen, aran

Reviewed By: jungejason

CC: aran, jungejason

Differential Revision: 964
This commit is contained in:
epriestley
2011-09-26 15:04:04 -07:00
parent 7b8b469da3
commit be26c6a5c1
4 changed files with 247 additions and 142 deletions

View File

@@ -17,79 +17,8 @@
* limitations under the License.
*/
$root = dirname(dirname(dirname(__FILE__)));
require_once $root.'/scripts/__init_script__.php';
require_once $root.'/scripts/__init_env__.php';
echo "This script is obsolete. Instead, use:\n\n".
" $ reparse.php --all <repository_name> --message\n\n".
"See that script for more options.\n";
exit(1);
phutil_require_module('phutil', 'console');
if (empty($argv[1])) {
echo "usage: reparse_all_commit_messages.php all\n".
" reparse_all_commit_messages.php <repository_callsign>\n";
exit(1);
}
echo phutil_console_format(
'This script will queue tasks to reparse every commit message known to '.
'Diffusion. Once the tasks have been inserted, you need to start '.
'Taskmaster daemons to execute them.');
$ok = phutil_console_confirm('Do you want to continue?');
if (!$ok) {
die(1);
}
if ($argv[1] == 'all') {
echo "Loading all repositories...\n";
$repositories = id(new PhabricatorRepository())->loadAll();
echo "Loading all commits...\n";
$commits = id(new PhabricatorRepositoryCommit())->loadAll();
} else {
$callsign = $argv[1];
echo "Loading '{$callsign}' repository...\n";
$repository = id(new PhabricatorRepository())->loadOneWhere(
'callsign = %s',
$argv[1]);
if (!$repository) {
throw new Exception("No such repository exists!");
}
$repositories = array(
$repository->getID() => $repository,
);
echo "Loading commits in '{$callsign}' repository...\n";
$commits = id(new PhabricatorRepositoryCommit())->loadAllWhere(
'repositoryID = %d',
$repository->getID());
}
echo "Inserting tasks for ".count($commits)." commits";
foreach ($commits as $commit) {
echo ".";
$id = $commit->getID();
$repo = idx($repositories, $commit->getRepositoryID());
if (!$repo) {
echo "\nWarning: Commit #{$id} has an invalid repository ID.\n";
}
switch ($repo->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
$task_class = 'PhabricatorRepositoryGitCommitMessageParserWorker';
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$task_class = 'PhabricatorRepositorySvnCommitMessageParserWorker';
break;
default:
throw new Exception("Unknown repository type!");
}
$task = new PhabricatorWorkerTask();
$task->setTaskClass($task_class);
$task->setData(
array(
'commitID' => $commit->getID(),
'only' => true,
));
$task->save();
}
echo "\nDone.\n";