Skip to content

Commit e4c4724

Browse files
author
epriestley
committedAug 24, 2016
Migrate the "badcommit" table to use the less-hacky "hint" mechanism
Summary: Ref T11522. This migrates any "badcommit" data (which probably only exists at Facebook and on 1-2 other installs in the wild) to the new "hint" table. Test Plan: - Wrote some bad commit annotations to the badcommit table. - Viewed them in the web UI and used `bin/repository reparse --change ...` to reparse them. Saw "this is bad" messages. - Ran migration, verified that valid "badcommit" rows were successfully migrated to become "hint" rows. - Viewed the new web UI and re-parsed the change, saw "unreadable commit" messages. - Viewed a good commit; reparsed a good commit. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11522 Differential Revision: https://secure.phabricator.com/D16435
1 parent 8a4fbcd commit e4c4724

9 files changed

+77
-36
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
$table = new PhabricatorRepositoryCommit();
4+
$conn = $table->establishConnection('w');
5+
6+
$rows = queryfx_all(
7+
$conn,
8+
'SELECT fullCommitName FROM repository_badcommit');
9+
10+
$viewer = PhabricatorUser::getOmnipotentUser();
11+
12+
foreach ($rows as $row) {
13+
$identifier = $row['fullCommitName'];
14+
15+
$commit = id(new DiffusionCommitQuery())
16+
->setViewer($viewer)
17+
->withIdentifiers(array($identifier))
18+
->executeOne();
19+
20+
if (!$commit) {
21+
echo tsprintf(
22+
"%s\n",
23+
pht(
24+
'Skipped hint for "%s", this is not a valid commit.',
25+
$identifier));
26+
} else {
27+
PhabricatorRepositoryCommitHint::updateHint(
28+
$commit->getRepository()->getPHID(),
29+
$commit->getCommitIdentifier(),
30+
null,
31+
PhabricatorRepositoryCommitHint::HINT_UNREADABLE);
32+
33+
echo tsprintf(
34+
"%s\n",
35+
pht(
36+
'Updated commit hint for "%s".',
37+
$identifier));
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE {$NAMESPACE}_repository.repository_badcommit;

‎src/applications/diffusion/controller/DiffusionCommitController.php

+16-10
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,29 @@ public function handleRequest(AphrontRequest $request) {
167167

168168
$count = count($changes);
169169

170-
$bad_commit = null;
171-
if ($count == 0) {
172-
$bad_commit = queryfx_one(
173-
id(new PhabricatorRepository())->establishConnection('r'),
174-
'SELECT * FROM %T WHERE fullCommitName = %s',
175-
PhabricatorRepository::TABLE_BADCOMMIT,
176-
$commit->getMonogram());
170+
$is_unreadable = false;
171+
if (!$count) {
172+
$hint = id(new DiffusionCommitHintQuery())
173+
->setViewer($viewer)
174+
->withRepositoryPHIDs(array($repository->getPHID()))
175+
->withOldCommitIdentifiers(array($commit->getCommitIdentifier()))
176+
->executeOne();
177+
if ($hint) {
178+
$is_unreadable = $hint->isUnreadable();
179+
}
177180
}
178181

179182
$show_changesets = false;
180183
$info_panel = null;
181184
$change_list = null;
182185
$change_table = null;
183-
if ($bad_commit) {
186+
if ($is_unreadable) {
184187
$info_panel = $this->renderStatusMessage(
185-
pht('Bad Commit'),
186-
$bad_commit['description']);
188+
pht('Unreadable Commit'),
189+
pht(
190+
'This commit has been marked as unreadable by an administrator. '.
191+
'It may have been corrupted or created improperly by an external '.
192+
'tool.'));
187193
} else if ($is_foreign) {
188194
// Don't render anything else.
189195
} else if (!$commit->isImported()) {

‎src/applications/diffusion/query/DiffusionCommitHintQuery.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
4343
if ($this->repositoryPHIDs !== null) {
4444
$where[] = qsprintf(
4545
$conn,
46-
'reositoryPHID IN (%Ls)',
46+
'repositoryPHID IN (%Ls)',
4747
$this->repositoryPHIDs);
4848
}
4949

‎src/applications/repository/storage/PhabricatorRepository.php

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
3535
const TABLE_PATHCHANGE = 'repository_pathchange';
3636
const TABLE_FILESYSTEM = 'repository_filesystem';
3737
const TABLE_SUMMARY = 'repository_summary';
38-
const TABLE_BADCOMMIT = 'repository_badcommit';
3938
const TABLE_LINTMESSAGE = 'repository_lintmessage';
4039
const TABLE_PARENTS = 'repository_parents';
4140
const TABLE_COVERAGE = 'repository_coverage';

‎src/applications/repository/storage/PhabricatorRepositoryCommitHint.php

+5
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ public static function updateHint($repository_phid, $old, $new, $type) {
101101
}
102102

103103

104+
public function isUnreadable() {
105+
return ($this->getHintType() == self::HINT_UNREADABLE);
106+
}
107+
108+
104109
/* -( PhabricatorPolicyInterface )----------------------------------------- */
105110

106111

‎src/applications/repository/storage/PhabricatorRepositorySchemaSpec.php

-14
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,6 @@ final class PhabricatorRepositorySchemaSpec
66
public function buildSchemata() {
77
$this->buildEdgeSchemata(new PhabricatorRepository());
88

9-
$this->buildRawSchema(
10-
id(new PhabricatorRepository())->getApplicationName(),
11-
PhabricatorRepository::TABLE_BADCOMMIT,
12-
array(
13-
'fullCommitName' => 'text64',
14-
'description' => 'text',
15-
),
16-
array(
17-
'PRIMARY' => array(
18-
'columns' => array('fullCommitName'),
19-
'unique' => true,
20-
),
21-
));
22-
239
$this->buildRawSchema(
2410
id(new PhabricatorRepository())->getApplicationName(),
2511
PhabricatorRepository::TABLE_COVERAGE,

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,16 @@ abstract protected function parseCommit(
9595
PhabricatorRepository $repository,
9696
PhabricatorRepositoryCommit $commit);
9797

98-
protected function isBadCommit(PhabricatorRepositoryCommit $commit) {
99-
$repository = new PhabricatorRepository();
98+
protected function loadCommitHint(PhabricatorRepositoryCommit $commit) {
99+
$viewer = PhabricatorUser::getOmnipotentUser();
100100

101-
$bad_commit = queryfx_one(
102-
$repository->establishConnection('w'),
103-
'SELECT * FROM %T WHERE fullCommitName = %s',
104-
PhabricatorRepository::TABLE_BADCOMMIT,
105-
$commit->getMonogram());
101+
$repository = $commit->getRepository();
106102

107-
return (bool)$bad_commit;
103+
return id(new DiffusionCommitHintQuery())
104+
->setViewer($viewer)
105+
->withRepositoryPHIDs(array($repository->getPHID()))
106+
->withOldCommitIdentifiers(array($commit->getCommitIdentifier()))
107+
->executeOne();
108108
}
109109

110110
public function renderForDisplay(PhabricatorUser $viewer) {

‎src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryCommitChangeParserWorker.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ protected function parseCommit(
2222
PhabricatorRepositoryCommit $commit) {
2323

2424
$this->log("%s\n", pht('Parsing "%s"...', $commit->getMonogram()));
25-
if ($this->isBadCommit($commit)) {
26-
$this->log(pht('This commit is marked bad!'));
25+
26+
$hint = $this->loadCommitHint($commit);
27+
if ($hint && $hint->isUnreadable()) {
28+
$this->log(
29+
pht(
30+
'This commit is marked as unreadable, so changes will not be '.
31+
'parsed.'));
2732
return;
2833
}
2934

0 commit comments

Comments
 (0)
Failed to load comments.