Skip to content

Commit 898ce6b

Browse files
aviveyepriestley
authored andcommitted
Search Symbols by Repository, not Project
Summary: Fixes T7977. - Move Indexed Languages and See Symbols From config to Repository - Make symbol search skip projects This also makes the default languages to Everything instead of Nothing. Test Plan: - Browse files, click symbols. - Use quick search to find symbols - Browse revision, click symbols Reviewers: joshuaspence, epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Maniphest Tasks: T7977 Differential Revision: https://secure.phabricator.com/D12687
1 parent 79e8d9f commit 898ce6b

16 files changed

+336
-83
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
$table_w = new PhabricatorRepository();
4+
$conn_w = $table_w->establishConnection('w');
5+
6+
// Repository and Project share a database.
7+
$conn_r = $table_w->establishConnection('r');
8+
$projects_table = 'repository_arcanistproject';
9+
10+
$raw_projects_data = queryfx_all($conn_r, 'SELECT * FROM %T', $projects_table);
11+
$raw_projects_data = ipull($raw_projects_data, null, 'id');
12+
13+
$repository_ids = ipull($raw_projects_data, 'repositoryID');
14+
$repositories = id(new PhabricatorRepositoryQuery())
15+
->setViewer(PhabricatorUser::getOmnipotentUser())
16+
->withIDs($repository_ids)
17+
->execute();
18+
19+
$projects_to_repo_ids_map = ipull($raw_projects_data, 'repositoryID', 'phid');
20+
$projects_to_repos_map = array();
21+
foreach ($projects_to_repo_ids_map as $projectPHID => $repositoryID) {
22+
$repo = idx($repositories, $repositoryID);
23+
if ($repo) {
24+
$projects_to_repos_map[$projectPHID] = $repo->getPHID();
25+
}
26+
}
27+
28+
foreach ($raw_projects_data as $project_row) {
29+
$repositoryID = idx($project_row, 'repositoryID');
30+
$repo = idx($repositories, $repositoryID);
31+
32+
if (!$repo) {
33+
continue;
34+
}
35+
36+
echo pht(
37+
"Migrating symbols configuration for '%s' project...\n",
38+
idx($project_row, 'name', '???'));
39+
40+
$symbol_index_projects = $project_row['symbolIndexProjects'];
41+
$symbol_index_projects = phutil_json_decode($symbol_index_projects);
42+
43+
$sources = $repo->getDetail('symbol-sources', array());
44+
foreach ($symbol_index_projects as $index_project) {
45+
$sources[] = idx($projects_to_repos_map, $index_project);
46+
}
47+
$sources = array_filter($sources);
48+
$sources = array_unique($sources);
49+
50+
$repo->setDetail('symbol-sources', $sources);
51+
52+
$languages = $project_row['symbolIndexLanguages'];
53+
$languages = phutil_json_decode($languages);
54+
55+
$languages = array_merge(
56+
$repo->getDetail('symbol-languages', array()),
57+
$languages);
58+
$languages = array_unique($languages);
59+
60+
$repo->setDetail('symbol-languages', $languages);
61+
62+
queryfx(
63+
$conn_w,
64+
'UPDATE %T SET details = %s WHERE id = %d',
65+
$table_w->getTableName(),
66+
json_encode($repo->getDetails()),
67+
$repo->getID());
68+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE {$NAMESPACE}_repository.repository_arcanistproject
2+
DROP COLUMN symbolIndexLanguages,
3+
DROP COLUMN symbolIndexProjects;

src/__phutil_library_map__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@
605605
'DiffusionRepositoryPath' => 'applications/diffusion/data/DiffusionRepositoryPath.php',
606606
'DiffusionRepositoryRef' => 'applications/diffusion/data/DiffusionRepositoryRef.php',
607607
'DiffusionRepositoryRemarkupRule' => 'applications/diffusion/remarkup/DiffusionRepositoryRemarkupRule.php',
608+
'DiffusionRepositorySymbolsController' => 'applications/diffusion/controller/DiffusionRepositorySymbolsController.php',
608609
'DiffusionRepositoryTag' => 'applications/diffusion/data/DiffusionRepositoryTag.php',
609610
'DiffusionRequest' => 'applications/diffusion/request/DiffusionRequest.php',
610611
'DiffusionResolveRefsConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionResolveRefsConduitAPIMethod.php',
@@ -3847,6 +3848,7 @@
38473848
'DiffusionRepositoryNewController' => 'DiffusionController',
38483849
'DiffusionRepositoryRef' => 'Phobject',
38493850
'DiffusionRepositoryRemarkupRule' => 'PhabricatorObjectRemarkupRule',
3851+
'DiffusionRepositorySymbolsController' => 'DiffusionRepositoryEditController',
38503852
'DiffusionResolveRefsConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod',
38513853
'DiffusionResolveUserQuery' => 'Phobject',
38523854
'DiffusionSSHWorkflow' => 'PhabricatorSSHWorkflow',

src/applications/differential/controller/DifferentialRevisionViewController.php

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,14 @@ public function processRequest() {
260260
'whitespace',
261261
DifferentialChangesetParser::WHITESPACE_IGNORE_MOST);
262262

263-
$arc_project = $target->getArcanistProject();
264-
if ($arc_project) {
265-
list($symbol_indexes, $project_phids) = $this->buildSymbolIndexes(
266-
$arc_project,
263+
$repository = $revision->getRepository();
264+
if ($repository) {
265+
list($symbol_indexes, $repository_phids) = $this->buildSymbolIndexes(
266+
$repository,
267267
$visible_changesets);
268268
} else {
269269
$symbol_indexes = array();
270-
$project_phids = null;
270+
$repository_phids = null;
271271
}
272272

273273
$revision_detail->setActions($actions);
@@ -307,12 +307,12 @@ public function processRequest() {
307307
),
308308
$comment_view);
309309

310-
if ($arc_project) {
310+
if ($repository) {
311311
Javelin::initBehavior(
312312
'repository-crossreference',
313313
array(
314314
'section' => $wrap_id,
315-
'projects' => $project_phids,
315+
'repositories' => $repository_phids,
316316
));
317317
}
318318

@@ -750,35 +750,33 @@ private function loadChangesetsAndVsMap(
750750
}
751751

752752
private function buildSymbolIndexes(
753-
PhabricatorRepositoryArcanistProject $arc_project,
753+
PhabricatorRepository $repository,
754754
array $visible_changesets) {
755755
assert_instances_of($visible_changesets, 'DifferentialChangeset');
756756

757757
$engine = PhabricatorSyntaxHighlighter::newEngine();
758758

759-
$langs = $arc_project->getSymbolIndexLanguages();
760-
if (!$langs) {
761-
return array(array(), array());
762-
}
759+
$langs = $repository->getSymbolLanguages();
760+
$langs = nonempty($langs, array());
763761

764762
$symbol_indexes = array();
765763

766-
$project_phids = array_merge(
767-
array($arc_project->getPHID()),
768-
nonempty($arc_project->getSymbolIndexProjects(), array()));
764+
$repository_phids = array_merge(
765+
array($repository->getPHID()),
766+
nonempty($repository->getSymbolSources(), array()));
769767

770768
$indexed_langs = array_fill_keys($langs, true);
771769
foreach ($visible_changesets as $key => $changeset) {
772770
$lang = $engine->getLanguageFromFilename($changeset->getFilename());
773-
if (isset($indexed_langs[$lang])) {
771+
if (empty($indexed_langs) || isset($indexed_langs[$lang])) {
774772
$symbol_indexes[$key] = array(
775-
'lang' => $lang,
776-
'projects' => $project_phids,
773+
'lang' => $lang,
774+
'repositories' => $repository_phids,
777775
);
778776
}
779777
}
780778

781-
return array($symbol_indexes, $project_phids);
779+
return array($symbol_indexes, $repository_phids);
782780
}
783781

784782
private function loadOtherRevisions(

src/applications/diffusion/application/PhabricatorDiffusionApplication.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public function getRoutes() {
100100
'hosting/' => 'DiffusionRepositoryEditHostingController',
101101
'(?P<serve>serve)/' => 'DiffusionRepositoryEditHostingController',
102102
'update/' => 'DiffusionRepositoryEditUpdateController',
103+
'symbol/' => 'DiffusionRepositorySymbolsController',
103104
),
104105
'pathtree/(?P<dblob>.*)' => 'DiffusionPathTreeController',
105106
'mirror/' => array(

src/applications/diffusion/controller/DiffusionBrowseFileController.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -266,32 +266,20 @@ private function buildCorpus(
266266

267267
$id = celerity_generate_unique_node_id();
268268

269-
$projects = $drequest->loadArcanistProjects();
270-
$langs = array();
271-
foreach ($projects as $project) {
272-
$ls = $project->getSymbolIndexLanguages();
273-
if (!$ls) {
274-
continue;
275-
}
276-
$dep_projects = $project->getSymbolIndexProjects();
277-
$dep_projects[] = $project->getPHID();
278-
foreach ($ls as $lang) {
279-
if (!isset($langs[$lang])) {
280-
$langs[$lang] = array();
281-
}
282-
$langs[$lang] += $dep_projects + array($project);
283-
}
284-
}
269+
$repo = $drequest->getRepository();
270+
$symbol_repos = $repo->getSymbolSources();
271+
$symbol_repos[] = $repo;
285272

286273
$lang = last(explode('.', $drequest->getPath()));
287-
288-
if (isset($langs[$lang])) {
274+
$repo_languages = $repo->getSymbolLanguages();
275+
$repo_languages = array_fill_keys($repo_languages, true);
276+
if (empty($repo_languages) || isset($repo_languages[$lang])) {
289277
Javelin::initBehavior(
290278
'repository-crossreference',
291279
array(
292280
'container' => $id,
293281
'lang' => $lang,
294-
'projects' => $langs[$lang],
282+
'repositories' => $symbol_repos,
295283
));
296284
}
297285

src/applications/diffusion/controller/DiffusionRepositoryEditMainController.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ protected function processDiffusionRequest(AphrontRequest $request) {
6262
$encoding_properties =
6363
$this->buildEncodingProperties($repository, $encoding_actions);
6464

65+
$symbols_actions = $this->buildSymbolsActions($repository);
66+
$symbols_properties =
67+
$this->buildSymbolsProperties($repository, $symbols_actions);
68+
6569
$hosting_properties = $this->buildHostingProperties(
6670
$repository,
6771
$this->buildHostingActions($repository));
@@ -157,6 +161,10 @@ protected function processDiffusionRequest(AphrontRequest $request) {
157161
->setHeaderText(pht('Text Encoding'))
158162
->addPropertyList($encoding_properties);
159163

164+
$boxes[] = id(new PHUIObjectBoxView())
165+
->setHeaderText(pht('Symbols'))
166+
->addPropertyList($symbols_properties);
167+
160168
if ($branches_properties) {
161169
$boxes[] = id(new PHUIObjectBoxView())
162170
->setHeaderText(pht('Branches'))
@@ -1187,6 +1195,53 @@ private function buildMirrorList(
11871195
return $mirror_list;
11881196
}
11891197

1198+
private function buildSymbolsActions(PhabricatorRepository $repository) {
1199+
$viewer = $this->getRequest()->getUser();
1200+
1201+
$view = id(new PhabricatorActionListView())
1202+
->setObjectURI($this->getRequest()->getRequestURI())
1203+
->setUser($viewer);
1204+
1205+
$edit = id(new PhabricatorActionView())
1206+
->setIcon('fa-pencil')
1207+
->setName(pht('Edit Symbols'))
1208+
->setHref(
1209+
$this->getRepositoryControllerURI($repository, 'edit/symbol/'));
1210+
$view->addAction($edit);
1211+
1212+
return $view;
1213+
}
1214+
1215+
private function buildSymbolsProperties(
1216+
PhabricatorRepository $repository,
1217+
PhabricatorActionListView $actions) {
1218+
1219+
$viewer = $this->getRequest()->getUser();
1220+
1221+
$view = id(new PHUIPropertyListView())
1222+
->setUser($viewer)
1223+
->setActionList($actions);
1224+
1225+
$languages = $repository->getSymbolLanguages();
1226+
1227+
if ($languages) {
1228+
$languages = implode(', ', $languages);
1229+
} else {
1230+
$languages = phutil_tag('em', array(), pht('Any'));
1231+
}
1232+
$view->addProperty(pht('Languages'), $languages);
1233+
1234+
$sources = $repository->getSymbolSources();
1235+
if ($sources) {
1236+
$handles = $viewer->loadHandles($sources);
1237+
$sources = $handles->renderList();
1238+
} else {
1239+
$sources = phutil_tag('em', array(), pht('This Repository Only'));
1240+
}
1241+
$view->addProperty(pht('Use Symbols From'), $sources);
1242+
return $view;
1243+
}
1244+
11901245
private function getEnvConfigLink() {
11911246
$config_href = '/config/edit/environment.append-paths/';
11921247
return phutil_tag(

0 commit comments

Comments
 (0)