diff --git a/scripts/daemon/phabricator_daemon_launcher.php b/scripts/daemon/phabricator_daemon_launcher.php index 5bcb312005..ef2806d5ba 100755 --- a/scripts/daemon/phabricator_daemon_launcher.php +++ b/scripts/daemon/phabricator_daemon_launcher.php @@ -169,59 +169,6 @@ switch (isset($argv[1]) ? $argv[1] : 'help') { break; - case 'parse-commit': - $commit = isset($argv[2]) ? $argv[2] : null; - if (!$commit) { - throw new Exception("Provide a commit to parse!"); - } - $matches = null; - if (!preg_match('/r([A-Z]+)([a-z0-9]+)/', $commit, $matches)) { - throw new Exception("Can't parse commit identifier!"); - } - $repo = id(new PhabricatorRepository())->loadOneWhere( - 'callsign = %s', - $matches[1]); - if (!$repo) { - throw new Exception("Unknown repository!"); - } - $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( - 'repositoryID = %d AND commitIdentifier = %s', - $repo->getID(), - $matches[2]); - if (!$commit) { - throw new Exception('Unknown commit.'); - } - - $workers = array(); - - - switch ($repo->getVersionControlSystem()) { - case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: - $workers[] = new PhabricatorRepositoryGitCommitMessageParserWorker( - $commit->getID()); - $workers[] = new PhabricatorRepositoryGitCommitChangeParserWorker( - $commit->getID()); - break; - case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: - $workers[] = new PhabricatorRepositorySvnCommitMessageParserWorker( - $commit->getID()); - $workers[] = new PhabricatorRepositorySvnCommitChangeParserWorker( - $commit->getID()); - break; - default: - throw new Exception("Unknown repository type!"); - } - - ExecFuture::pushEchoMode(true); - - foreach ($workers as $worker) { - echo "Running ".get_class($worker)."...\n"; - $worker->doWork(); - } - - echo "Done.\n"; - - break; case '--help': case 'help': default: diff --git a/scripts/repository/parse_one_commit.php b/scripts/repository/parse_one_commit.php new file mode 100755 index 0000000000..56f29156a6 --- /dev/null +++ b/scripts/repository/parse_one_commit.php @@ -0,0 +1,83 @@ +#!/usr/bin/env php +\n"; + die(1); +} + +$commit = isset($argv[1]) ? $argv[1] : null; +if (!$commit) { + throw new Exception("Provide a commit to parse!"); +} +$matches = null; +if (!preg_match('/r([A-Z]+)([a-z0-9]+)/', $commit, $matches)) { + throw new Exception("Can't parse commit identifier!"); +} +$repo = id(new PhabricatorRepository())->loadOneWhere( + 'callsign = %s', + $matches[1]); +if (!$repo) { + throw new Exception("Unknown repository!"); +} +$commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( + 'repositoryID = %d AND commitIdentifier = %s', + $repo->getID(), + $matches[2]); +if (!$commit) { + throw new Exception('Unknown commit.'); +} + +$workers = array(); + +$spec = array( + 'commitID' => $commit->getID(), + 'only' => true, +); + +switch ($repo->getVersionControlSystem()) { + case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: + $workers[] = new PhabricatorRepositoryGitCommitMessageParserWorker( + $spec); + $workers[] = new PhabricatorRepositoryGitCommitChangeParserWorker( + $spec); + break; + case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: + $workers[] = new PhabricatorRepositorySvnCommitMessageParserWorker( + $spec); + $workers[] = new PhabricatorRepositorySvnCommitChangeParserWorker( + $spec); + break; + default: + throw new Exception("Unknown repository type!"); +} + +ExecFuture::pushEchoMode(true); + +foreach ($workers as $worker) { + echo "Running ".get_class($worker)."...\n"; + $worker->doWork(); +} + +echo "Done.\n"; + diff --git a/scripts/repository/reparse_all_commit_messages.php b/scripts/repository/reparse_all_commit_messages.php new file mode 100755 index 0000000000..b9fac56381 --- /dev/null +++ b/scripts/repository/reparse_all_commit_messages.php @@ -0,0 +1,95 @@ +#!/usr/bin/env php +\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"; diff --git a/src/applications/repository/daemon/committask/PhabricatorRepositoryCommitTaskDaemon.php b/src/applications/repository/daemon/committask/PhabricatorRepositoryCommitTaskDaemon.php index 9e0aab76cc..79b977c197 100644 --- a/src/applications/repository/daemon/committask/PhabricatorRepositoryCommitTaskDaemon.php +++ b/src/applications/repository/daemon/committask/PhabricatorRepositoryCommitTaskDaemon.php @@ -47,14 +47,20 @@ class PhabricatorRepositoryCommitTaskDaemon $class = 'PhabricatorRepositoryGitCommitMessageParserWorker'; $task = new PhabricatorWorkerTask(); $task->setTaskClass($class); - $task->setData($commit->getID()); + $task->setData( + array( + 'commitID' => $commit->getID(), + )); $task->save(); break; case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: $class = 'PhabricatorRepositorySvnCommitMessageParserWorker'; $task = new PhabricatorWorkerTask(); $task->setTaskClass($class); - $task->setData($commit->getID()); + $task->setData( + array( + 'commitID' => $commit->getID(), + )); $task->save(); break; default: diff --git a/src/applications/repository/worker/base/PhabricatorRepositoryCommitParserWorker.php b/src/applications/repository/worker/base/PhabricatorRepositoryCommitParserWorker.php index fade2cda75..20994b2afb 100644 --- a/src/applications/repository/worker/base/PhabricatorRepositoryCommitParserWorker.php +++ b/src/applications/repository/worker/base/PhabricatorRepositoryCommitParserWorker.php @@ -23,7 +23,7 @@ abstract class PhabricatorRepositoryCommitParserWorker protected $repository; final public function doWork() { - $commit_id = $this->getTaskData(); + $commit_id = idx($this->getTaskData(), 'commitID'); if (!$commit_id) { return; } @@ -49,6 +49,10 @@ abstract class PhabricatorRepositoryCommitParserWorker return $this->parseCommit($repository, $commit); } + final protected function shouldQueueFollowupTasks() { + return !!idx($this->getTaskData(), 'only'); + } + abstract protected function parseCommit( PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit); diff --git a/src/applications/repository/worker/commitmessageparser/git/PhabricatorRepositoryGitCommitMessageParserWorker.php b/src/applications/repository/worker/commitmessageparser/git/PhabricatorRepositoryGitCommitMessageParserWorker.php index 0ad674752b..2989452786 100644 --- a/src/applications/repository/worker/commitmessageparser/git/PhabricatorRepositoryGitCommitMessageParserWorker.php +++ b/src/applications/repository/worker/commitmessageparser/git/PhabricatorRepositoryGitCommitMessageParserWorker.php @@ -30,16 +30,24 @@ class PhabricatorRepositoryGitCommitMessageParserWorker $local_path, $commit->getCommitIdentifier()); - // TODO: Need to slam UTF8? list($author, $message) = explode("\0", $info); + // Make sure these are valid UTF-8. + $author = phutil_utf8ize($author); + $message = phutil_utf8ize($message); + $this->updateCommitData($author, $message); - $task = new PhabricatorWorkerTask(); - $task->setTaskClass('PhabricatorRepositoryGitCommitChangeParserWorker'); - $task->setData($commit->getID()); - $task->save(); + if ($this->shouldQueueFollowupTasks()) { + $task = new PhabricatorWorkerTask(); + $task->setTaskClass('PhabricatorRepositoryGitCommitChangeParserWorker'); + $task->setData( + array( + 'commitID' => $commit->getID(), + )); + $task->save(); + } } } diff --git a/src/applications/repository/worker/commitmessageparser/svn/PhabricatorRepositorySvnCommitMessageParserWorker.php b/src/applications/repository/worker/commitmessageparser/svn/PhabricatorRepositorySvnCommitMessageParserWorker.php index 75da4e66ed..c8c8d95478 100644 --- a/src/applications/repository/worker/commitmessageparser/svn/PhabricatorRepositorySvnCommitMessageParserWorker.php +++ b/src/applications/repository/worker/commitmessageparser/svn/PhabricatorRepositorySvnCommitMessageParserWorker.php @@ -37,10 +37,15 @@ class PhabricatorRepositorySvnCommitMessageParserWorker $this->updateCommitData($author, $message); - $task = new PhabricatorWorkerTask(); - $task->setTaskClass('PhabricatorRepositorySvnCommitChangeParserWorker'); - $task->setData($commit->getID()); - $task->save(); + if ($this->shouldQueueFollowupTasks()) { + $task = new PhabricatorWorkerTask(); + $task->setTaskClass('PhabricatorRepositorySvnCommitChangeParserWorker'); + $task->setData( + array( + 'commitID' => $commit->getID(), + )); + $task->save(); + } } } diff --git a/src/infrastructure/daemon/control/PhabricatorDaemonControl.php b/src/infrastructure/daemon/control/PhabricatorDaemonControl.php index ce72b27b26..03170ba872 100644 --- a/src/infrastructure/daemon/control/PhabricatorDaemonControl.php +++ b/src/infrastructure/daemon/control/PhabricatorDaemonControl.php @@ -145,9 +145,6 @@ final class PhabricatorDaemonControl { **help** Show this help. - **parse-commit** __rXnnnn__ - Parse a single commit. - **repository-launch-master** Launches daemons to update and parse all tracked repositories. You must also launch Taskmaster daemons, either on the same machine or