Skip to content

Commit 1f88e08

Browse files
author
epriestley
committed
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.
1 parent 29ce4ed commit 1f88e08

File tree

8 files changed

+213
-68
lines changed

8 files changed

+213
-68
lines changed

scripts/daemon/phabricator_daemon_launcher.php

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -169,59 +169,6 @@
169169

170170
break;
171171

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;
225172
case '--help':
226173
case 'help':
227174
default:
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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";

src/applications/repository/daemon/committask/PhabricatorRepositoryCommitTaskDaemon.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,20 @@ final public function run() {
4747
$class = 'PhabricatorRepositoryGitCommitMessageParserWorker';
4848
$task = new PhabricatorWorkerTask();
4949
$task->setTaskClass($class);
50-
$task->setData($commit->getID());
50+
$task->setData(
51+
array(
52+
'commitID' => $commit->getID(),
53+
));
5154
$task->save();
5255
break;
5356
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
5457
$class = 'PhabricatorRepositorySvnCommitMessageParserWorker';
5558
$task = new PhabricatorWorkerTask();
5659
$task->setTaskClass($class);
57-
$task->setData($commit->getID());
60+
$task->setData(
61+
array(
62+
'commitID' => $commit->getID(),
63+
));
5864
$task->save();
5965
break;
6066
default:

src/applications/repository/worker/base/PhabricatorRepositoryCommitParserWorker.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class PhabricatorRepositoryCommitParserWorker
2323
protected $repository;
2424

2525
final public function doWork() {
26-
$commit_id = $this->getTaskData();
26+
$commit_id = idx($this->getTaskData(), 'commitID');
2727
if (!$commit_id) {
2828
return;
2929
}
@@ -49,6 +49,10 @@ final public function doWork() {
4949
return $this->parseCommit($repository, $commit);
5050
}
5151

52+
final protected function shouldQueueFollowupTasks() {
53+
return !!idx($this->getTaskData(), 'only');
54+
}
55+
5256
abstract protected function parseCommit(
5357
PhabricatorRepository $repository,
5458
PhabricatorRepositoryCommit $commit);

src/applications/repository/worker/commitmessageparser/git/PhabricatorRepositoryGitCommitMessageParserWorker.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,24 @@ public function parseCommit(
3030
$local_path,
3131
$commit->getCommitIdentifier());
3232

33-
// TODO: Need to slam UTF8?
3433

3534
list($author, $message) = explode("\0", $info);
3635

36+
// Make sure these are valid UTF-8.
37+
$author = phutil_utf8ize($author);
38+
$message = phutil_utf8ize($message);
39+
3740
$this->updateCommitData($author, $message);
3841

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+
}
4351
}
4452

4553
}

src/applications/repository/worker/commitmessageparser/svn/PhabricatorRepositorySvnCommitMessageParserWorker.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ public function parseCommit(
3737

3838
$this->updateCommitData($author, $message);
3939

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+
}
4449
}
4550

4651
}

src/infrastructure/daemon/control/PhabricatorDaemonControl.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@ public function executeHelpCommand() {
145145
**help**
146146
Show this help.
147147
148-
**parse-commit** __rXnnnn__
149-
Parse a single commit.
150-
151148
**repository-launch-master**
152149
Launches daemons to update and parse all tracked repositories. You
153150
must also launch Taskmaster daemons, either on the same machine or

0 commit comments

Comments
 (0)