@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move 'phd parse-commit' to a dedicated script; allow message parsing tasks to be executed in isolation, provide a script to requeue all message reparses, stop parse-commit from inserting side-effect tasks.

+213 -68
-53
scripts/daemon/phabricator_daemon_launcher.php
··· 169 169 170 170 break; 171 171 172 - case 'parse-commit': 173 - $commit = isset($argv[2]) ? $argv[2] : null; 174 - if (!$commit) { 175 - throw new Exception("Provide a commit to parse!"); 176 - } 177 - $matches = null; 178 - if (!preg_match('/r([A-Z]+)([a-z0-9]+)/', $commit, $matches)) { 179 - throw new Exception("Can't parse commit identifier!"); 180 - } 181 - $repo = id(new PhabricatorRepository())->loadOneWhere( 182 - 'callsign = %s', 183 - $matches[1]); 184 - if (!$repo) { 185 - throw new Exception("Unknown repository!"); 186 - } 187 - $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( 188 - 'repositoryID = %d AND commitIdentifier = %s', 189 - $repo->getID(), 190 - $matches[2]); 191 - if (!$commit) { 192 - throw new Exception('Unknown commit.'); 193 - } 194 - 195 - $workers = array(); 196 - 197 - 198 - switch ($repo->getVersionControlSystem()) { 199 - case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: 200 - $workers[] = new PhabricatorRepositoryGitCommitMessageParserWorker( 201 - $commit->getID()); 202 - $workers[] = new PhabricatorRepositoryGitCommitChangeParserWorker( 203 - $commit->getID()); 204 - break; 205 - case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 206 - $workers[] = new PhabricatorRepositorySvnCommitMessageParserWorker( 207 - $commit->getID()); 208 - $workers[] = new PhabricatorRepositorySvnCommitChangeParserWorker( 209 - $commit->getID()); 210 - break; 211 - default: 212 - throw new Exception("Unknown repository type!"); 213 - } 214 - 215 - ExecFuture::pushEchoMode(true); 216 - 217 - foreach ($workers as $worker) { 218 - echo "Running ".get_class($worker)."...\n"; 219 - $worker->doWork(); 220 - } 221 - 222 - echo "Done.\n"; 223 - 224 - break; 225 172 case '--help': 226 173 case 'help': 227 174 default:
+83
scripts/repository/parse_one_commit.php
··· 1 + #!/usr/bin/env php 2 + <?php 3 + 4 + /* 5 + * Copyright 2011 Facebook, Inc. 6 + * 7 + * Licensed under the Apache License, Version 2.0 (the "License"); 8 + * you may not use this file except in compliance with the License. 9 + * You may obtain a copy of the License at 10 + * 11 + * http://www.apache.org/licenses/LICENSE-2.0 12 + * 13 + * Unless required by applicable law or agreed to in writing, software 14 + * distributed under the License is distributed on an "AS IS" BASIS, 15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 + * See the License for the specific language governing permissions and 17 + * limitations under the License. 18 + */ 19 + 20 + $root = dirname(dirname(dirname(__FILE__))); 21 + require_once $root.'/scripts/__init_script__.php'; 22 + require_once $root.'/scripts/__init_env__.php'; 23 + 24 + if (empty($argv[1])) { 25 + echo "usage: parse_one_commit.php <commit_name>\n"; 26 + die(1); 27 + } 28 + 29 + $commit = isset($argv[1]) ? $argv[1] : null; 30 + if (!$commit) { 31 + throw new Exception("Provide a commit to parse!"); 32 + } 33 + $matches = null; 34 + if (!preg_match('/r([A-Z]+)([a-z0-9]+)/', $commit, $matches)) { 35 + throw new Exception("Can't parse commit identifier!"); 36 + } 37 + $repo = id(new PhabricatorRepository())->loadOneWhere( 38 + 'callsign = %s', 39 + $matches[1]); 40 + if (!$repo) { 41 + throw new Exception("Unknown repository!"); 42 + } 43 + $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( 44 + 'repositoryID = %d AND commitIdentifier = %s', 45 + $repo->getID(), 46 + $matches[2]); 47 + if (!$commit) { 48 + throw new Exception('Unknown commit.'); 49 + } 50 + 51 + $workers = array(); 52 + 53 + $spec = array( 54 + 'commitID' => $commit->getID(), 55 + 'only' => true, 56 + ); 57 + 58 + switch ($repo->getVersionControlSystem()) { 59 + case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: 60 + $workers[] = new PhabricatorRepositoryGitCommitMessageParserWorker( 61 + $spec); 62 + $workers[] = new PhabricatorRepositoryGitCommitChangeParserWorker( 63 + $spec); 64 + break; 65 + case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 66 + $workers[] = new PhabricatorRepositorySvnCommitMessageParserWorker( 67 + $spec); 68 + $workers[] = new PhabricatorRepositorySvnCommitChangeParserWorker( 69 + $spec); 70 + break; 71 + default: 72 + throw new Exception("Unknown repository type!"); 73 + } 74 + 75 + ExecFuture::pushEchoMode(true); 76 + 77 + foreach ($workers as $worker) { 78 + echo "Running ".get_class($worker)."...\n"; 79 + $worker->doWork(); 80 + } 81 + 82 + echo "Done.\n"; 83 +
+95
scripts/repository/reparse_all_commit_messages.php
··· 1 + #!/usr/bin/env php 2 + <?php 3 + 4 + /* 5 + * Copyright 2011 Facebook, Inc. 6 + * 7 + * Licensed under the Apache License, Version 2.0 (the "License"); 8 + * you may not use this file except in compliance with the License. 9 + * You may obtain a copy of the License at 10 + * 11 + * http://www.apache.org/licenses/LICENSE-2.0 12 + * 13 + * Unless required by applicable law or agreed to in writing, software 14 + * distributed under the License is distributed on an "AS IS" BASIS, 15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 + * See the License for the specific language governing permissions and 17 + * limitations under the License. 18 + */ 19 + 20 + $root = dirname(dirname(dirname(__FILE__))); 21 + require_once $root.'/scripts/__init_script__.php'; 22 + require_once $root.'/scripts/__init_env__.php'; 23 + 24 + phutil_require_module('phutil', 'console'); 25 + 26 + if (empty($argv[1])) { 27 + echo "usage: reparse_all_commit_messages.php all\n". 28 + " reparse_all_commit_messages.php <repository_callsign>\n"; 29 + exit(1); 30 + } 31 + 32 + 33 + echo phutil_console_format( 34 + 'This script will queue tasks to reparse every commit message known to '. 35 + 'Diffusion. Once the tasks have been inserted, you need to start '. 36 + 'Taskmaster daemons to execute them.'); 37 + 38 + $ok = phutil_console_confirm('Do you want to continue?'); 39 + if (!$ok) { 40 + die(1); 41 + } 42 + 43 + if ($argv[1] == 'all') { 44 + echo "Loading all repositories...\n"; 45 + $repositories = id(new PhabricatorRepository())->loadAll(); 46 + echo "Loading all commits...\n"; 47 + $commits = id(new PhabricatorRepositoryCommit())->loadAll(); 48 + } else { 49 + $callsign = $argv[1]; 50 + echo "Loading '{$callsign}' repository...\n"; 51 + $repository = id(new PhabricatorRepository())->loadOneWhere( 52 + 'callsign = %s', 53 + $argv[1]); 54 + if (!$repository) { 55 + throw new Exception("No such repository exists!"); 56 + } 57 + $repositories = array( 58 + $repository->getID() => $repository, 59 + ); 60 + echo "Loading commits in '{$callsign}' repository...\n"; 61 + $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere( 62 + 'repositoryID = %d', 63 + $repository->getID()); 64 + } 65 + 66 + echo "Inserting tasks for ".count($commits)." commits"; 67 + foreach ($commits as $commit) { 68 + echo "."; 69 + $id = $commit->getID(); 70 + $repo = idx($repositories, $commit->getRepositoryID()); 71 + if (!$repo) { 72 + echo "\nWarning: Commit #{$id} has an invalid repository ID.\n"; 73 + } 74 + 75 + switch ($repo->getVersionControlSystem()) { 76 + case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: 77 + $task_class = 'PhabricatorRepositoryGitCommitMessageParserWorker'; 78 + break; 79 + case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 80 + $task_class = 'PhabricatorRepositorySvnCommitMessageParserWorker'; 81 + break; 82 + default: 83 + throw new Exception("Unknown repository type!"); 84 + } 85 + 86 + $task = new PhabricatorWorkerTask(); 87 + $task->setTaskClass($task_class); 88 + $task->setData( 89 + array( 90 + 'commitID' => $commit->getID(), 91 + 'only' => true, 92 + )); 93 + $task->save(); 94 + } 95 + echo "\nDone.\n";
+8 -2
src/applications/repository/daemon/committask/PhabricatorRepositoryCommitTaskDaemon.php
··· 47 47 $class = 'PhabricatorRepositoryGitCommitMessageParserWorker'; 48 48 $task = new PhabricatorWorkerTask(); 49 49 $task->setTaskClass($class); 50 - $task->setData($commit->getID()); 50 + $task->setData( 51 + array( 52 + 'commitID' => $commit->getID(), 53 + )); 51 54 $task->save(); 52 55 break; 53 56 case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 54 57 $class = 'PhabricatorRepositorySvnCommitMessageParserWorker'; 55 58 $task = new PhabricatorWorkerTask(); 56 59 $task->setTaskClass($class); 57 - $task->setData($commit->getID()); 60 + $task->setData( 61 + array( 62 + 'commitID' => $commit->getID(), 63 + )); 58 64 $task->save(); 59 65 break; 60 66 default:
+5 -1
src/applications/repository/worker/base/PhabricatorRepositoryCommitParserWorker.php
··· 23 23 protected $repository; 24 24 25 25 final public function doWork() { 26 - $commit_id = $this->getTaskData(); 26 + $commit_id = idx($this->getTaskData(), 'commitID'); 27 27 if (!$commit_id) { 28 28 return; 29 29 } ··· 47 47 $this->repository = $repository; 48 48 49 49 return $this->parseCommit($repository, $commit); 50 + } 51 + 52 + final protected function shouldQueueFollowupTasks() { 53 + return !!idx($this->getTaskData(), 'only'); 50 54 } 51 55 52 56 abstract protected function parseCommit(
+13 -5
src/applications/repository/worker/commitmessageparser/git/PhabricatorRepositoryGitCommitMessageParserWorker.php
··· 30 30 $local_path, 31 31 $commit->getCommitIdentifier()); 32 32 33 - // TODO: Need to slam UTF8? 34 33 35 34 list($author, $message) = explode("\0", $info); 35 + 36 + // Make sure these are valid UTF-8. 37 + $author = phutil_utf8ize($author); 38 + $message = phutil_utf8ize($message); 36 39 37 40 $this->updateCommitData($author, $message); 38 41 39 - $task = new PhabricatorWorkerTask(); 40 - $task->setTaskClass('PhabricatorRepositoryGitCommitChangeParserWorker'); 41 - $task->setData($commit->getID()); 42 - $task->save(); 42 + if ($this->shouldQueueFollowupTasks()) { 43 + $task = new PhabricatorWorkerTask(); 44 + $task->setTaskClass('PhabricatorRepositoryGitCommitChangeParserWorker'); 45 + $task->setData( 46 + array( 47 + 'commitID' => $commit->getID(), 48 + )); 49 + $task->save(); 50 + } 43 51 } 44 52 45 53 }
+9 -4
src/applications/repository/worker/commitmessageparser/svn/PhabricatorRepositorySvnCommitMessageParserWorker.php
··· 37 37 38 38 $this->updateCommitData($author, $message); 39 39 40 - $task = new PhabricatorWorkerTask(); 41 - $task->setTaskClass('PhabricatorRepositorySvnCommitChangeParserWorker'); 42 - $task->setData($commit->getID()); 43 - $task->save(); 40 + if ($this->shouldQueueFollowupTasks()) { 41 + $task = new PhabricatorWorkerTask(); 42 + $task->setTaskClass('PhabricatorRepositorySvnCommitChangeParserWorker'); 43 + $task->setData( 44 + array( 45 + 'commitID' => $commit->getID(), 46 + )); 47 + $task->save(); 48 + } 44 49 } 45 50 46 51 }
-3
src/infrastructure/daemon/control/PhabricatorDaemonControl.php
··· 145 145 **help** 146 146 Show this help. 147 147 148 - **parse-commit** __rXnnnn__ 149 - Parse a single commit. 150 - 151 148 **repository-launch-master** 152 149 Launches daemons to update and parse all tracked repositories. You 153 150 must also launch Taskmaster daemons, either on the same machine or