Skip to content

Commit 875455a

Browse files
aevriepriestley
authored and
epriestley
committed
Document reparse --min-date more, add validation
Summary: Sometimes it seems necessary to force a reparse of recent commits in production, it took me longer than expected to get this right. To make this easier, document the usage of --min-date further with usage examples and print a usage exception with the input if the supplied value isn't accepted by MySQL. (otherwise all commits will be affected in the case of user error) Test Plan: .. create TEST repo with commits dated 2013-04-03 .. $ ./reparse.php --all TEST --owners --min-date "2013a-04-03 10:30:19" .. see usage exception - invalid timestamp .. $ ./reparse.php --all TEST --owners --min-date "2013-04-03 10:30:19" .. reparse commits ok .. $ ./reparse.php --all TEST --owners --min-date "2013-04-04 10:30:19" .. see 'No commits have been discovered' .. $ ./reparse.php --all TEST --owners .. reparse commits ok .. $ ./reparse.php --help .. looks ok to me .. $ ./reparse.php --all TEST --owners --min-date 2013-04-03 10:30:19 .. see error - interprets 10:30:19 as commit and refuses .. $ ./reparse.php --all TEST --owners --min-date <<first commit time>> .. parse this commit and following .. $ ./reparse.php <<revision_id>> --owners --min-date <<first commit time>> .. see error - insist on --all if --min-date .. $ ./reparse.php <<revision_id>> --owners .. ok .. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D5579
1 parent 754705d commit 875455a

File tree

1 file changed

+56
-6
lines changed

1 file changed

+56
-6
lines changed

scripts/repository/reparse.php

+56-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,27 @@
1010
1111
Rerun the Diffusion parser on specific commits and repositories. Mostly
1212
useful for debugging changes to Diffusion.
13+
14+
e.g. enqueue reparse owners in the TEST repo for all commits:
15+
./reparse.php --all TEST --owners
16+
17+
e.g. do same but exclude before yesterday (local time):
18+
./reparse.php --all TEST --owners --min-date yesterday
19+
./reparse.php --all TEST --owners --min-date "today -1 day"
20+
21+
e.g. do same but exclude before 03/31/2013 (local time):
22+
./reparse.php --all TEST --owners --min-date "03/31/2013"
1323
EOHELP
1424
);
1525

26+
$min_date_usage_examples =
27+
"Valid examples:\n".
28+
" 'today', 'today 2pm', '-1 hour', '-2 hours', '-24 hours',\n".
29+
" 'yesterday', 'today -1 day', 'yesterday 2pm', '2pm -1 day',\n".
30+
" 'last Monday', 'last Monday 14:00', 'last Monday 2pm',\n".
31+
" '31 March 2013', '31 Mar', '03/31', '03/31/2013',\n".
32+
"See __http://www.php.net/manual/en/datetime.formats.php__ for more.\n";
33+
1634
$args->parseStandardArguments();
1735
$args->parse(
1836
array(
@@ -33,8 +51,9 @@
3351
array(
3452
'name' => 'min-date',
3553
'param' => 'date',
36-
'help' => 'When used with __--all__, this will restrict to '.
37-
'reparsing only the commits that are newer than __date__.',
54+
'help' => 'Must be used with __--all__, this will exclude commits '.
55+
'which are earlier than __date__.'.
56+
"\n".$min_date_usage_examples,
3857
),
3958
// which parts
4059
array(
@@ -87,11 +106,40 @@
87106
usage("Specify a commit or repository to reparse.");
88107
}
89108

109+
if ($all_from_repo && $reparse_what) {
110+
$commits = implode(', ', $reparse_what);
111+
usage(
112+
"Specify a commit or repository to reparse, not both:\n".
113+
"All from repo: ".$all_from_repo."\n".
114+
"Commit(s) to reparse: ".$commits);
115+
}
116+
90117
if (!$reparse_message && !$reparse_change && !$reparse_herald &&
91118
!$reparse_owners && !$reparse_harbormaster) {
92119
usage("Specify what information to reparse with --message, --change, ".
93120
"--herald, --harbormaster, and/or --owners");
94121
}
122+
123+
$min_timestamp = false;
124+
if ($min_date) {
125+
$min_timestamp = strtotime($min_date);
126+
127+
if (!$all_from_repo) {
128+
usage(
129+
"You must use --all if you specify --min-date\n".
130+
"e.g.\n".
131+
" ./reparse.php --all TEST --owners --min-date yesterday");
132+
}
133+
134+
// previous to PHP 5.1.0 you would compare with -1, instead of false
135+
if (false === $min_timestamp) {
136+
usage(
137+
"Supplied --min-date is not valid\n".
138+
"Supplied value: '".$min_date."'\n".
139+
$min_date_usage_examples);
140+
}
141+
}
142+
95143
if ($reparse_owners && !$force) {
96144
echo phutil_console_wrap(
97145
"You are about to recreate the relationship entries between the commits ".
@@ -114,13 +162,14 @@
114162
throw new Exception("Unknown repository {$all_from_repo}!");
115163
}
116164
$constraint = '';
117-
if ($min_date) {
165+
if ($min_timestamp) {
166+
echo "Excluding entries before UNIX timestamp: ".$min_timestamp."\n";
118167
$table = new PhabricatorRepositoryCommit();
119168
$conn_r = $table->establishConnection('r');
120169
$constraint = qsprintf(
121170
$conn_r,
122-
'AND epoch > unix_timestamp(%s)',
123-
$min_date);
171+
'AND epoch >= %d',
172+
$min_timestamp);
124173
}
125174
$commits = id(new PhabricatorRepositoryCommit())->loadAllWhere(
126175
'repositoryID = %d %Q',
@@ -236,6 +285,7 @@
236285

237286
function usage($message) {
238287
echo phutil_console_format(
239-
'**Usage Exception:** '.$message."\n");
288+
'**Usage Exception:** '.$message."\n".
289+
"Use __--help__ to display full help\n");
240290
exit(1);
241291
}

0 commit comments

Comments
 (0)