From c5fa7421c222701de53231c13100fed2446f276e Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 27 Feb 2017 10:21:23 -0800 Subject: [PATCH] Allow commits to be queried by repository using the `tagged(...)` typehaead function Summary: Fixes T12322. Allows you to search for commits using the `tagged(...)` repository function, so you can find "any commmit in any repository tagged with android" or similar. I moved the function from Differential (which was the application using it) to Diffusion (which is more accurately the application which provides it). I fixed a bug where searching for `tagged(xyz)` would have no effect (constraint was ignored) if there were no repositories tagged with "xyz". The fix isn't perfectly clean, but should work properly for the moment. Test Plan: - Searched with `tagged(...)` in Diffusion and Differential. - Searched by repository. - Searched with `tagged(...)` for a project with no tagged repositories. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12322 Differential Revision: https://secure.phabricator.com/D17426 --- src/__phutil_library_map__.php | 4 ++-- .../audit/query/PhabricatorCommitSearchEngine.php | 2 +- .../query/DifferentialRevisionSearchEngine.php | 2 +- .../DiffusionRepositoryFunctionDatasource.php} | 2 +- .../DiffusionTaggedRepositoriesFunctionDatasource.php | 10 +++++++++- 5 files changed, 14 insertions(+), 6 deletions(-) rename src/applications/{differential/typeahead/DifferentialRepositoryDatasource.php => diffusion/typeahead/DiffusionRepositoryFunctionDatasource.php} (91%) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index eab57b7617..c370fbef75 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -482,7 +482,6 @@ phutil_register_library_map(array( 'DifferentialReleephRequestFieldSpecification' => 'applications/releeph/differential/DifferentialReleephRequestFieldSpecification.php', 'DifferentialRemarkupRule' => 'applications/differential/remarkup/DifferentialRemarkupRule.php', 'DifferentialReplyHandler' => 'applications/differential/mail/DifferentialReplyHandler.php', - 'DifferentialRepositoryDatasource' => 'applications/differential/typeahead/DifferentialRepositoryDatasource.php', 'DifferentialRepositoryField' => 'applications/differential/customfield/DifferentialRepositoryField.php', 'DifferentialRepositoryLookup' => 'applications/differential/query/DifferentialRepositoryLookup.php', 'DifferentialRequiredSignaturesField' => 'applications/differential/customfield/DifferentialRequiredSignaturesField.php', @@ -827,6 +826,7 @@ phutil_register_library_map(array( 'DiffusionRepositoryEditDeleteController' => 'applications/diffusion/controller/DiffusionRepositoryEditDeleteController.php', 'DiffusionRepositoryEditEngine' => 'applications/diffusion/editor/DiffusionRepositoryEditEngine.php', 'DiffusionRepositoryEditUpdateController' => 'applications/diffusion/controller/DiffusionRepositoryEditUpdateController.php', + 'DiffusionRepositoryFunctionDatasource' => 'applications/diffusion/typeahead/DiffusionRepositoryFunctionDatasource.php', 'DiffusionRepositoryHistoryManagementPanel' => 'applications/diffusion/management/DiffusionRepositoryHistoryManagementPanel.php', 'DiffusionRepositoryListController' => 'applications/diffusion/controller/DiffusionRepositoryListController.php', 'DiffusionRepositoryManageController' => 'applications/diffusion/controller/DiffusionRepositoryManageController.php', @@ -5211,7 +5211,6 @@ phutil_register_library_map(array( 'DifferentialReleephRequestFieldSpecification' => 'Phobject', 'DifferentialRemarkupRule' => 'PhabricatorObjectRemarkupRule', 'DifferentialReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', - 'DifferentialRepositoryDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 'DifferentialRepositoryField' => 'DifferentialCoreCustomField', 'DifferentialRepositoryLookup' => 'Phobject', 'DifferentialRequiredSignaturesField' => 'DifferentialCoreCustomField', @@ -5575,6 +5574,7 @@ phutil_register_library_map(array( 'DiffusionRepositoryEditDeleteController' => 'DiffusionRepositoryManageController', 'DiffusionRepositoryEditEngine' => 'PhabricatorEditEngine', 'DiffusionRepositoryEditUpdateController' => 'DiffusionRepositoryManageController', + 'DiffusionRepositoryFunctionDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 'DiffusionRepositoryHistoryManagementPanel' => 'DiffusionRepositoryManagementPanel', 'DiffusionRepositoryListController' => 'DiffusionController', 'DiffusionRepositoryManageController' => 'DiffusionController', diff --git a/src/applications/audit/query/PhabricatorCommitSearchEngine.php b/src/applications/audit/query/PhabricatorCommitSearchEngine.php index e1c1120608..52cfe1f94f 100644 --- a/src/applications/audit/query/PhabricatorCommitSearchEngine.php +++ b/src/applications/audit/query/PhabricatorCommitSearchEngine.php @@ -85,7 +85,7 @@ final class PhabricatorCommitSearchEngine ->setKey('repositoryPHIDs') ->setConduitKey('repositories') ->setAliases(array('repository', 'repositories', 'repositoryPHID')) - ->setDatasource(new DiffusionRepositoryDatasource()), + ->setDatasource(new DiffusionRepositoryFunctionDatasource()), id(new PhabricatorSearchDatasourceField()) ->setLabel(pht('Packages')) ->setKey('packagePHIDs') diff --git a/src/applications/differential/query/DifferentialRevisionSearchEngine.php b/src/applications/differential/query/DifferentialRevisionSearchEngine.php index 5fac0708fc..9212860292 100644 --- a/src/applications/differential/query/DifferentialRevisionSearchEngine.php +++ b/src/applications/differential/query/DifferentialRevisionSearchEngine.php @@ -75,7 +75,7 @@ final class DifferentialRevisionSearchEngine ->setLabel(pht('Repositories')) ->setKey('repositoryPHIDs') ->setAliases(array('repository', 'repositories', 'repositoryPHID')) - ->setDatasource(new DifferentialRepositoryDatasource()) + ->setDatasource(new DiffusionRepositoryFunctionDatasource()) ->setDescription( pht('Find revisions from specific repositories.')), id(new PhabricatorSearchSelectField()) diff --git a/src/applications/differential/typeahead/DifferentialRepositoryDatasource.php b/src/applications/diffusion/typeahead/DiffusionRepositoryFunctionDatasource.php similarity index 91% rename from src/applications/differential/typeahead/DifferentialRepositoryDatasource.php rename to src/applications/diffusion/typeahead/DiffusionRepositoryFunctionDatasource.php index 1decc9c1ca..5fb7d5f5ac 100644 --- a/src/applications/differential/typeahead/DifferentialRepositoryDatasource.php +++ b/src/applications/diffusion/typeahead/DiffusionRepositoryFunctionDatasource.php @@ -1,6 +1,6 @@ execute(); $results = array(); - foreach ($repositories as $repository) { $results[] = $repository->getPHID(); } + if (!$results) { + // TODO: This is a little hacky, but if you query for "tagged(x)" and + // there are no such repositories, we want to match nothing. If we + // just return `array()`, that gets evaluated as "no constraint" and + // we match everything. This works correctly for now, but should be + // replaced with some more elegant/general approach eventually. + $results[] = PhabricatorPHIDConstants::PHID_VOID; + } + return $results; }