diff --git a/scripts/repository/parse_one_commit.php b/scripts/repository/parse_one_commit.php index 750d4507c1..855899b8bd 100755 --- a/scripts/repository/parse_one_commit.php +++ b/scripts/repository/parse_one_commit.php @@ -17,69 +17,7 @@ * limitations under the License. */ -$root = dirname(dirname(dirname(__FILE__))); -require_once $root.'/scripts/__init_script__.php'; -require_once $root.'/scripts/__init_env__.php'; - -if (empty($argv[1])) { - echo "usage: parse_one_commit.php [--herald]\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!"); -} - -if (isset($argv[2]) && $argv[2] == '--herald') { - $workers[] = new PhabricatorRepositoryCommitHeraldWorker($spec); -} - -foreach ($workers as $worker) { - echo "Running ".get_class($worker)."...\n"; - $worker->doWork(); -} - -echo "Done.\n"; - +echo "This script is obsolete. Instead, use:\n\n". + " $ reparse.php --message --change\n\n". + "See that script for more options.\n"; +exit(1); diff --git a/scripts/repository/reparse.php b/scripts/repository/reparse.php new file mode 100755 index 0000000000..c9d435fff5 --- /dev/null +++ b/scripts/repository/reparse.php @@ -0,0 +1,236 @@ +#!/usr/bin/env php +loadOneWhere( + 'callsign = %s OR phid = %s', + $reparse_what, + $reparse_what); + if (!$repository) { + throw new Exception("Unknown repository '{$reparse_what}'!"); + } + $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere( + 'repositoryID = %d', + $repository->getID()); + if (!$commits) { + throw new Exception("No commits have been discovered in that repository!"); + } + $callsign = $repository->getCallsign(); +} else { + $matches = null; + if (!preg_match('/r([A-Z]+)([a-z0-9]+)/', $reparse_what, $matches)) { + throw new Exception("Can't parse commit identifier!"); + } + $callsign = $matches[1]; + $commit_identifier = $matches[2]; + $repository = id(new PhabricatorRepository())->loadOneWhere( + 'callsign = %s', + $callsign); + if (!$repository) { + throw new Exception("No repository with callsign '{$callsign}'!"); + } + $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( + 'repositoryID = %d AND commitIdentifier = %s', + $repository->getID(), + $commit_identifier); + if (!$commit) { + throw new Exception( + "No matching commit '{$commit_identifier}' in repository '{$callsign}'. ". + "(For git and mercurial repositories, you must specify the entire ". + "commit hash.)"); + } + $commits = array($commit); +} + +if ($is_all) { + echo phutil_console_format( + '**NOTE**: This script will queue tasks to reparse the data. Once the '. + 'tasks have been queued, you need to run Taskmaster daemons to execute '. + 'them.'); + echo "\n\n"; + echo "QUEUEING TASKS (".number_format(count($commits))." Commits):\n"; +} + +$tasks = array(); +foreach ($commits as $commit) { + $classes = array(); + switch ($repository->getVersionControlSystem()) { + case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: + if ($reparse_message) { + $classes[] = 'PhabricatorRepositoryGitCommitMessageParserWorker'; + } + if ($reparse_change) { + $classes[] = 'PhabricatorRepositoryGitCommitChangeParserWorker'; + } + break; + case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: + if ($reparse_message) { + $classes[] = 'PhabricatorRepositoryMercurialCommitMessageParserWorker'; + } + if ($reparse_change) { + $classes[] = 'PhabricatorRepositoryMercurialCommitChangeParserWorker'; + } + break; + case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: + if ($reparse_message) { + $classes[] = 'PhabricatorRepositorySvnCommitMessageParserWorker'; + } + if ($reparse_change) { + $classes[] = 'PhabricatorRepositorySvnCommitChangeParserWorker'; + } + break; + } + + if ($reparse_herald) { + $classes[] = 'PhabricatorRepositoryCommitHeraldWorker'; + } + + $spec = array( + 'commitID' => $commit->getID(), + 'only' => true, + ); + + if ($is_all) { + foreach ($classes as $class) { + $task = new PhabricatorWorkerTask(); + $task->setTaskClass($class); + $task->setData($spec); + $task->save(); + + $commit_name = 'r'.$callsign.$commit->getCommitIdentifier(); + echo " Queued '{$class}' for commit '{$commit_name}'.\n"; + } + } else { + foreach ($classes as $class) { + $worker = newv($class, array($spec)); + echo "Running '{$class}'...\n"; + $worker->doWork(); + } + } +} + +echo "\nDone.\n"; + +function usage($message) { + echo "Usage Error: {$message}"; + echo "\n\n"; + echo "Run 'reparse.php --help' for detailed help.\n"; + exit(1); +} + +function help() { + $help = << --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 \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/daemon/controller/workertaskdetail/PhabricatorWorkerTaskDetailController.php b/src/applications/daemon/controller/workertaskdetail/PhabricatorWorkerTaskDetailController.php index d4acf74840..3eb9d24d1e 100644 --- a/src/applications/daemon/controller/workertaskdetail/PhabricatorWorkerTaskDetailController.php +++ b/src/applications/daemon/controller/workertaskdetail/PhabricatorWorkerTaskDetailController.php @@ -62,10 +62,12 @@ class PhabricatorWorkerTaskDetailController "NOTE: ". "You can manually retry this task by running this script:". "
".
-                  "phabricator/\$ ./scripts/repository/parse_one_commit.php ".
+                  "phabricator/\$ ./scripts/repository/reparse.php ".
                   "r".
                   phutil_escape_html($repository->getCallsign()).
                   phutil_escape_html($commit->getCommitIdentifier()).
+                  " ".
+                  "--change".
                 "
"; } }