@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.

Use PhutilArgumentParser in reparse.php

Summary:
Update how arguments get parsed in reparse.php and add two new options
--force-local and --min-date (both to be used with --all). This diff also
fixes a bug in destroy_revision.php

Test Plan: ran the script

Reviewers: epriestley, vrana

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3275

+99 -111
+1 -1
scripts/differential/destroy_revision.php
··· 53 53 $id = trim(strtolower(head($revisions)), 'd '); 54 54 $revision = id(new DifferentialRevision())->load($id); 55 55 56 - if (!$id) { 56 + if (!$revision) { 57 57 throw new Exception("No revision '{$id}' exists!"); 58 58 } 59 59
+98 -110
scripts/repository/reparse.php
··· 20 20 $root = dirname(dirname(dirname(__FILE__))); 21 21 require_once $root.'/scripts/__init_script__.php'; 22 22 23 - $is_all = false; 24 - $reparse_message = false; 25 - $reparse_change = false; 26 - $reparse_herald = false; 27 - $reparse_owners = false; 28 - $reparse_what = false; 29 - $force = false; 23 + $args = new PhutilArgumentParser($argv); 24 + $args->setSynopsis(<<<EOHELP 25 + **reparse.php** __what__ __which_parts__ [--trace] [--force] 30 26 31 - $args = array_slice($argv, 1); 32 - foreach ($args as $arg) { 33 - if (!strncmp($arg, '--', 2)) { 34 - $flag = substr($arg, 2); 35 - switch ($flag) { 36 - case 'all': 37 - $is_all = true; 38 - break; 39 - case 'message': 40 - case 'messages': 41 - $reparse_message = true; 42 - break; 43 - case 'change': 44 - case 'changes': 45 - $reparse_change = true; 46 - break; 47 - case 'herald': 48 - $reparse_herald = true; 49 - break; 50 - case 'owners': 51 - $reparse_owners = true; 52 - break; 53 - case 'force': 54 - $force = true; 55 - break; 56 - case 'trace': 57 - PhutilServiceProfiler::installEchoListener(); 58 - break; 59 - case 'help': 60 - help(); 61 - break; 62 - default: 63 - usage("Unknown flag '{$arg}'."); 64 - break; 65 - } 66 - } else { 67 - if ($reparse_what) { 68 - usage("Specify exactly one thing to reparse."); 69 - } 70 - $reparse_what = $arg; 71 - } 72 - } 27 + Rerun the Diffusion parser on specific commits and repositories. Mostly 28 + useful for debugging changes to Diffusion. 29 + EOHELP 30 + ); 73 31 74 - if (!$reparse_what) { 32 + $args->parseStandardArguments(); 33 + $args->parse( 34 + array( 35 + // what 36 + array( 37 + 'name' => 'revision', 38 + 'wildcard' => true, 39 + ), 40 + array( 41 + 'name' => 'all', 42 + 'param' => 'callsign or phid', 43 + 'help' => 'Reparse all commits in the specified repository. This '. 44 + 'mode queues parsers into the task queue; you must run '. 45 + 'taskmasters to actually do the parses. Use with '. 46 + '__--force-local__ to run the tasks locally instead of '. 47 + 'with taskmasters.', 48 + ), 49 + array( 50 + 'name' => 'min-date', 51 + 'param' => 'date', 52 + 'help' => 'When used with __--all__, this will restrict to '. 53 + 'reparsing only the commits that are newer than __date__.', 54 + ), 55 + // which parts 56 + array( 57 + 'name' => 'message', 58 + 'help' => 'Reparse commit messages.', 59 + ), 60 + array( 61 + 'name' => 'change', 62 + 'help' => 'Reparse changes.', 63 + ), 64 + array( 65 + 'name' => 'herald', 66 + 'help' => 'Reevaluate Herald rules (may send huge amounts of email!)', 67 + ), 68 + array( 69 + 'name' => 'owners', 70 + 'help' => 'Reevaluate related commits for owners packages (may '. 71 + 'delete existing relationship entries between your '. 72 + 'package and some old commits!)', 73 + ), 74 + // misc options 75 + array( 76 + 'name' => 'force', 77 + 'short' => 'f', 78 + 'help' => 'Act noninteractively, without prompting.', 79 + ), 80 + array( 81 + 'name' => 'force-local', 82 + 'help' => 'Only used with __--all__, use this to run the tasks '. 83 + 'locally instead of deferring them to taskmaster daemons.', 84 + ), 85 + )); 86 + 87 + $all_from_repo = $args->getArg('all'); 88 + $reparse_message = $args->getArg('message'); 89 + $reparse_change = $args->getArg('change'); 90 + $reparse_herald = $args->getArg('herald'); 91 + $reparse_owners = $args->getArg('owners'); 92 + $reparse_what = $args->getArg('revision'); 93 + $force = $args->getArg('force'); 94 + $force_local = $args->getArg('force-local'); 95 + $min_date = $args->getArg('min-date'); 96 + 97 + if (count($reparse_what) > 1 || !($all_from_repo xor count($reparse_what))) { 75 98 usage("Specify a commit or repository to reparse."); 76 99 } 100 + 101 + if ($args->getArg('trace')) { 102 + PhutilServiceProfiler::installEchoListener(); 103 + } 104 + 77 105 if (!$reparse_message && !$reparse_change && !$reparse_herald && 78 106 !$reparse_owners) { 79 107 usage("Specify what information to reparse with --message, --change, ". ··· 92 120 } 93 121 94 122 $commits = array(); 95 - if ($is_all) { 123 + if ($all_from_repo) { 96 124 $repository = id(new PhabricatorRepository())->loadOneWhere( 97 125 'callsign = %s OR phid = %s', 98 - $reparse_what, 99 - $reparse_what); 126 + $all_from_repo, 127 + $all_from_repo); 100 128 if (!$repository) { 101 - throw new Exception("Unknown repository '{$reparse_what}'!"); 129 + throw new Exception("Unknown repository {$all_from_repo}!"); 130 + } 131 + $constraint = ''; 132 + if ($min_date) { 133 + $table = new PhabricatorRepositoryCommit(); 134 + $conn_r = $table->establishConnection('r'); 135 + $constraint = qsprintf( 136 + $conn_r, 137 + 'AND epoch > unix_timestamp(%s)', 138 + $min_date); 102 139 } 103 140 $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere( 104 - 'repositoryID = %d', 105 - $repository->getID()); 141 + 'repositoryID = %d %Q', 142 + $repository->getID(), 143 + $constraint); 106 144 if (!$commits) { 107 145 throw new Exception("No commits have been discovered in that repository!"); 108 146 } ··· 133 171 $commits = array($commit); 134 172 } 135 173 136 - if ($is_all) { 174 + if ($all_from_repo && !$force_local) { 137 175 echo phutil_console_format( 138 176 '**NOTE**: This script will queue tasks to reparse the data. Once the '. 139 177 'tasks have been queued, you need to run Taskmaster daemons to execute '. ··· 185 223 'only' => true, 186 224 ); 187 225 188 - if ($is_all) { 226 + if ($all_from_repo && !$force_local) { 189 227 foreach ($classes as $class) { 190 228 $task = new PhabricatorWorkerTask(); 191 229 $task->setTaskClass($class); ··· 207 245 echo "\nDone.\n"; 208 246 209 247 function usage($message) { 210 - echo "Usage Error: {$message}"; 211 - echo "\n\n"; 212 - echo "Run 'reparse.php --help' for detailed help.\n"; 213 - exit(1); 214 - } 215 - 216 - function help() { 217 - $help = <<<EOHELP 218 - **SUMMARY** 219 - 220 - **reparse.php** __what__ __which_parts__ [--trace] [--force] 221 - 222 - Rerun the Diffusion parser on specific commits and repositories. Mostly 223 - useful for debugging changes to Diffusion. 224 - 225 - __what__: what to reparse 226 - 227 - __commit__ 228 - Reparse one commit. This mode will reparse the commit in-process. 229 - 230 - --all __repository_callsign__ 231 - --all __repository_phid__ 232 - Reparse all commits in the specified repository. These modes queue 233 - parsers into the task queue, you must run taskmasters to actually 234 - do the parses. 235 - 236 - __which_parts__: which parts of the thing to reparse 237 - 238 - __--message__ 239 - Reparse commit messages. 240 - 241 - __--change__ 242 - Reparse changes. 243 - 244 - __--herald__ 245 - Reevaluate Herald rules (may send huge amounts of email!) 246 - 247 - __--owners__ 248 - Reevaluate related commits for owners packages (may delete existing 249 - relationship entries between your package and some old commits!) 250 - 251 - __--force__: act noninteractively, without prompting 252 - __--trace__: run with debug tracing 253 - __--help__: show this help 254 - 255 - **EXAMPLES** 256 - 257 - reparse.php rX123 --change # Reparse change for "rX123". 258 - reparse.php --all E --message # Reparse all messages in "E" repository. 259 - 260 - EOHELP; 261 - echo phutil_console_format($help); 248 + echo phutil_console_format( 249 + '**Usage Exception:** '.$message."\n"); 262 250 exit(1); 263 251 }