mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 10:12:41 +01:00
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
This commit is contained in:
parent
f748a47237
commit
ef0f30b662
2 changed files with 99 additions and 111 deletions
|
@ -53,7 +53,7 @@ if (count($revisions) != 1) {
|
||||||
$id = trim(strtolower(head($revisions)), 'd ');
|
$id = trim(strtolower(head($revisions)), 'd ');
|
||||||
$revision = id(new DifferentialRevision())->load($id);
|
$revision = id(new DifferentialRevision())->load($id);
|
||||||
|
|
||||||
if (!$id) {
|
if (!$revision) {
|
||||||
throw new Exception("No revision '{$id}' exists!");
|
throw new Exception("No revision '{$id}' exists!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,60 +20,88 @@
|
||||||
$root = dirname(dirname(dirname(__FILE__)));
|
$root = dirname(dirname(dirname(__FILE__)));
|
||||||
require_once $root.'/scripts/__init_script__.php';
|
require_once $root.'/scripts/__init_script__.php';
|
||||||
|
|
||||||
$is_all = false;
|
$args = new PhutilArgumentParser($argv);
|
||||||
$reparse_message = false;
|
$args->setSynopsis(<<<EOHELP
|
||||||
$reparse_change = false;
|
**reparse.php** __what__ __which_parts__ [--trace] [--force]
|
||||||
$reparse_herald = false;
|
|
||||||
$reparse_owners = false;
|
|
||||||
$reparse_what = false;
|
|
||||||
$force = false;
|
|
||||||
|
|
||||||
$args = array_slice($argv, 1);
|
Rerun the Diffusion parser on specific commits and repositories. Mostly
|
||||||
foreach ($args as $arg) {
|
useful for debugging changes to Diffusion.
|
||||||
if (!strncmp($arg, '--', 2)) {
|
EOHELP
|
||||||
$flag = substr($arg, 2);
|
);
|
||||||
switch ($flag) {
|
|
||||||
case 'all':
|
|
||||||
$is_all = true;
|
|
||||||
break;
|
|
||||||
case 'message':
|
|
||||||
case 'messages':
|
|
||||||
$reparse_message = true;
|
|
||||||
break;
|
|
||||||
case 'change':
|
|
||||||
case 'changes':
|
|
||||||
$reparse_change = true;
|
|
||||||
break;
|
|
||||||
case 'herald':
|
|
||||||
$reparse_herald = true;
|
|
||||||
break;
|
|
||||||
case 'owners':
|
|
||||||
$reparse_owners = true;
|
|
||||||
break;
|
|
||||||
case 'force':
|
|
||||||
$force = true;
|
|
||||||
break;
|
|
||||||
case 'trace':
|
|
||||||
PhutilServiceProfiler::installEchoListener();
|
|
||||||
break;
|
|
||||||
case 'help':
|
|
||||||
help();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
usage("Unknown flag '{$arg}'.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($reparse_what) {
|
|
||||||
usage("Specify exactly one thing to reparse.");
|
|
||||||
}
|
|
||||||
$reparse_what = $arg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$reparse_what) {
|
$args->parseStandardArguments();
|
||||||
|
$args->parse(
|
||||||
|
array(
|
||||||
|
// what
|
||||||
|
array(
|
||||||
|
'name' => 'revision',
|
||||||
|
'wildcard' => true,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'all',
|
||||||
|
'param' => 'callsign or phid',
|
||||||
|
'help' => 'Reparse all commits in the specified repository. This '.
|
||||||
|
'mode queues parsers into the task queue; you must run '.
|
||||||
|
'taskmasters to actually do the parses. Use with '.
|
||||||
|
'__--force-local__ to run the tasks locally instead of '.
|
||||||
|
'with taskmasters.',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'min-date',
|
||||||
|
'param' => 'date',
|
||||||
|
'help' => 'When used with __--all__, this will restrict to '.
|
||||||
|
'reparsing only the commits that are newer than __date__.',
|
||||||
|
),
|
||||||
|
// which parts
|
||||||
|
array(
|
||||||
|
'name' => 'message',
|
||||||
|
'help' => 'Reparse commit messages.',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'change',
|
||||||
|
'help' => 'Reparse changes.',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'herald',
|
||||||
|
'help' => 'Reevaluate Herald rules (may send huge amounts of email!)',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'owners',
|
||||||
|
'help' => 'Reevaluate related commits for owners packages (may '.
|
||||||
|
'delete existing relationship entries between your '.
|
||||||
|
'package and some old commits!)',
|
||||||
|
),
|
||||||
|
// misc options
|
||||||
|
array(
|
||||||
|
'name' => 'force',
|
||||||
|
'short' => 'f',
|
||||||
|
'help' => 'Act noninteractively, without prompting.',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'force-local',
|
||||||
|
'help' => 'Only used with __--all__, use this to run the tasks '.
|
||||||
|
'locally instead of deferring them to taskmaster daemons.',
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$all_from_repo = $args->getArg('all');
|
||||||
|
$reparse_message = $args->getArg('message');
|
||||||
|
$reparse_change = $args->getArg('change');
|
||||||
|
$reparse_herald = $args->getArg('herald');
|
||||||
|
$reparse_owners = $args->getArg('owners');
|
||||||
|
$reparse_what = $args->getArg('revision');
|
||||||
|
$force = $args->getArg('force');
|
||||||
|
$force_local = $args->getArg('force-local');
|
||||||
|
$min_date = $args->getArg('min-date');
|
||||||
|
|
||||||
|
if (count($reparse_what) > 1 || !($all_from_repo xor count($reparse_what))) {
|
||||||
usage("Specify a commit or repository to reparse.");
|
usage("Specify a commit or repository to reparse.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($args->getArg('trace')) {
|
||||||
|
PhutilServiceProfiler::installEchoListener();
|
||||||
|
}
|
||||||
|
|
||||||
if (!$reparse_message && !$reparse_change && !$reparse_herald &&
|
if (!$reparse_message && !$reparse_change && !$reparse_herald &&
|
||||||
!$reparse_owners) {
|
!$reparse_owners) {
|
||||||
usage("Specify what information to reparse with --message, --change, ".
|
usage("Specify what information to reparse with --message, --change, ".
|
||||||
|
@ -92,17 +120,27 @@ if ($reparse_owners && !$force) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$commits = array();
|
$commits = array();
|
||||||
if ($is_all) {
|
if ($all_from_repo) {
|
||||||
$repository = id(new PhabricatorRepository())->loadOneWhere(
|
$repository = id(new PhabricatorRepository())->loadOneWhere(
|
||||||
'callsign = %s OR phid = %s',
|
'callsign = %s OR phid = %s',
|
||||||
$reparse_what,
|
$all_from_repo,
|
||||||
$reparse_what);
|
$all_from_repo);
|
||||||
if (!$repository) {
|
if (!$repository) {
|
||||||
throw new Exception("Unknown repository '{$reparse_what}'!");
|
throw new Exception("Unknown repository {$all_from_repo}!");
|
||||||
|
}
|
||||||
|
$constraint = '';
|
||||||
|
if ($min_date) {
|
||||||
|
$table = new PhabricatorRepositoryCommit();
|
||||||
|
$conn_r = $table->establishConnection('r');
|
||||||
|
$constraint = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'AND epoch > unix_timestamp(%s)',
|
||||||
|
$min_date);
|
||||||
}
|
}
|
||||||
$commits = id(new PhabricatorRepositoryCommit())->loadAllWhere(
|
$commits = id(new PhabricatorRepositoryCommit())->loadAllWhere(
|
||||||
'repositoryID = %d',
|
'repositoryID = %d %Q',
|
||||||
$repository->getID());
|
$repository->getID(),
|
||||||
|
$constraint);
|
||||||
if (!$commits) {
|
if (!$commits) {
|
||||||
throw new Exception("No commits have been discovered in that repository!");
|
throw new Exception("No commits have been discovered in that repository!");
|
||||||
}
|
}
|
||||||
|
@ -133,7 +171,7 @@ if ($is_all) {
|
||||||
$commits = array($commit);
|
$commits = array($commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($is_all) {
|
if ($all_from_repo && !$force_local) {
|
||||||
echo phutil_console_format(
|
echo phutil_console_format(
|
||||||
'**NOTE**: This script will queue tasks to reparse the data. Once the '.
|
'**NOTE**: This script will queue tasks to reparse the data. Once the '.
|
||||||
'tasks have been queued, you need to run Taskmaster daemons to execute '.
|
'tasks have been queued, you need to run Taskmaster daemons to execute '.
|
||||||
|
@ -185,7 +223,7 @@ foreach ($commits as $commit) {
|
||||||
'only' => true,
|
'only' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($is_all) {
|
if ($all_from_repo && !$force_local) {
|
||||||
foreach ($classes as $class) {
|
foreach ($classes as $class) {
|
||||||
$task = new PhabricatorWorkerTask();
|
$task = new PhabricatorWorkerTask();
|
||||||
$task->setTaskClass($class);
|
$task->setTaskClass($class);
|
||||||
|
@ -207,57 +245,7 @@ foreach ($commits as $commit) {
|
||||||
echo "\nDone.\n";
|
echo "\nDone.\n";
|
||||||
|
|
||||||
function usage($message) {
|
function usage($message) {
|
||||||
echo "Usage Error: {$message}";
|
echo phutil_console_format(
|
||||||
echo "\n\n";
|
'**Usage Exception:** '.$message."\n");
|
||||||
echo "Run 'reparse.php --help' for detailed help.\n";
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function help() {
|
|
||||||
$help = <<<EOHELP
|
|
||||||
**SUMMARY**
|
|
||||||
|
|
||||||
**reparse.php** __what__ __which_parts__ [--trace] [--force]
|
|
||||||
|
|
||||||
Rerun the Diffusion parser on specific commits and repositories. Mostly
|
|
||||||
useful for debugging changes to Diffusion.
|
|
||||||
|
|
||||||
__what__: what to reparse
|
|
||||||
|
|
||||||
__commit__
|
|
||||||
Reparse one commit. This mode will reparse the commit in-process.
|
|
||||||
|
|
||||||
--all __repository_callsign__
|
|
||||||
--all __repository_phid__
|
|
||||||
Reparse all commits in the specified repository. These modes queue
|
|
||||||
parsers into the task queue, you must run taskmasters to actually
|
|
||||||
do the parses.
|
|
||||||
|
|
||||||
__which_parts__: which parts of the thing to reparse
|
|
||||||
|
|
||||||
__--message__
|
|
||||||
Reparse commit messages.
|
|
||||||
|
|
||||||
__--change__
|
|
||||||
Reparse changes.
|
|
||||||
|
|
||||||
__--herald__
|
|
||||||
Reevaluate Herald rules (may send huge amounts of email!)
|
|
||||||
|
|
||||||
__--owners__
|
|
||||||
Reevaluate related commits for owners packages (may delete existing
|
|
||||||
relationship entries between your package and some old commits!)
|
|
||||||
|
|
||||||
__--force__: act noninteractively, without prompting
|
|
||||||
__--trace__: run with debug tracing
|
|
||||||
__--help__: show this help
|
|
||||||
|
|
||||||
**EXAMPLES**
|
|
||||||
|
|
||||||
reparse.php rX123 --change # Reparse change for "rX123".
|
|
||||||
reparse.php --all E --message # Reparse all messages in "E" repository.
|
|
||||||
|
|
||||||
EOHELP;
|
|
||||||
echo phutil_console_format($help);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue