@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Basic filename search support for Diffusion

Summary:
Ref T156. Adds basic filename search support for Diffusion,
currently only for Git repositories.

This is preliminary, and it's up for discussion:
- is the UI in the right place;
- what should the search query syntax be (e.g. whether
to put `*`s in the beginning and end of it);
- how to best approach it for Mercurial and/or SVN;
- what's the cleanest result format for `lsquery` (I went
for the minimum necessary change to `DiffusionBrowseSearchController`).

Test Plan:
Browse to a repository in Diffusion, and use both
`Search File Names` and `Search File Content`.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Maniphest Tasks: T156

Differential Revision: https://secure.phabricator.com/D8093

authored by

Vlad Albulescu and committed by
epriestley
2d27324b 99676e8e

+116 -12
+2
src/__phutil_library_map__.php
··· 169 169 'ConduitAPI_diffusion_looksoon_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_looksoon_Method.php', 170 170 'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_mergedcommitsquery_Method.php', 171 171 'ConduitAPI_diffusion_querycommits_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_querycommits_Method.php', 172 + 'ConduitAPI_diffusion_querypaths_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_querypaths_Method.php', 172 173 'ConduitAPI_diffusion_rawdiffquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_rawdiffquery_Method.php', 173 174 'ConduitAPI_diffusion_readmequery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_readmequery_Method.php', 174 175 'ConduitAPI_diffusion_refsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_refsquery_Method.php', ··· 2657 2658 'ConduitAPI_diffusion_looksoon_Method' => 'ConduitAPI_diffusion_Method', 2658 2659 'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 2659 2660 'ConduitAPI_diffusion_querycommits_Method' => 'ConduitAPI_diffusion_Method', 2661 + 'ConduitAPI_diffusion_querypaths_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 2660 2662 'ConduitAPI_diffusion_rawdiffquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 2661 2663 'ConduitAPI_diffusion_readmequery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 2662 2664 'ConduitAPI_diffusion_refsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
+87
src/applications/diffusion/conduit/ConduitAPI_diffusion_querypaths_Method.php
··· 1 + <?php 2 + 3 + final class ConduitAPI_diffusion_querypaths_Method 4 + extends ConduitAPI_diffusion_abstractquery_Method { 5 + 6 + public function getMethodDescription() { 7 + return pht('Filename search on a repository.'); 8 + } 9 + 10 + public function defineReturnType() { 11 + return 'list<string>'; 12 + } 13 + 14 + protected function defineCustomParamTypes() { 15 + return array( 16 + 'path' => 'required string', 17 + 'commit' => 'required string', 18 + 'pattern' => 'required string', 19 + 'limit' => 'optional int', 20 + 'offset' => 'optional int', 21 + ); 22 + } 23 + 24 + protected function getResult(ConduitAPIRequest $request) { 25 + $results = parent::getResult($request); 26 + $offset = $request->getValue('offset'); 27 + return array_slice($results, $offset); 28 + } 29 + 30 + protected function getGitResult(ConduitAPIRequest $request) { 31 + $drequest = $this->getDiffusionRequest(); 32 + $path = $drequest->getPath(); 33 + $commit = $request->getValue('commit'); 34 + $repository = $drequest->getRepository(); 35 + 36 + // http://comments.gmane.org/gmane.comp.version-control.git/197735 37 + 38 + $future = $repository->getLocalCommandFuture( 39 + 'ls-tree --name-only -r -z %s -- %s', 40 + $commit, 41 + $path); 42 + 43 + $lines = id(new LinesOfALargeExecFuture($future))->setDelimiter("\0"); 44 + return $this->filterResults($lines, $request); 45 + } 46 + 47 + protected function getMercurialResult(ConduitAPIRequest $request) { 48 + $drequest = $this->getDiffusionRequest(); 49 + $repository = $drequest->getRepository(); 50 + $path = $request->getValue('path'); 51 + $commit = $request->getValue('commit'); 52 + 53 + // Adapted from diffusion.browsequery. 54 + list($entire_manifest) = $repository->execxLocalCommand( 55 + 'manifest --rev %s', 56 + hgsprintf('%s', $commit)); 57 + $entire_manifest = explode("\n", $entire_manifest); 58 + 59 + $match_against = trim($path, '/'); 60 + $match_len = strlen($match_against); 61 + 62 + $lines = array(); 63 + foreach ($entire_manifest as $path) { 64 + if (strlen($path) && !strncmp($path, $match_against, $match_len)) { 65 + $lines[] = $path; 66 + } 67 + } 68 + return $this->filterResults($lines, $request); 69 + } 70 + 71 + protected function filterResults($lines, ConduitAPIRequest $request) { 72 + $pattern = $request->getValue('pattern'); 73 + $limit = $request->getValue('limit'); 74 + $offset = $request->getValue('offset'); 75 + 76 + $results = array(); 77 + foreach ($lines as $line) { 78 + if (preg_match('#'.str_replace('#', '\#', $pattern).'#', $line)) { 79 + $results[] = $line; 80 + if (count($results) >= $offset + $limit) { 81 + break; 82 + } 83 + } 84 + } 85 + return $results; 86 + } 87 + }
+3 -2
src/applications/diffusion/controller/DiffusionBrowseController.php
··· 26 26 ->setValue($this->getRequest()->getStr('grep')) 27 27 ->setCaption(pht('Enter a regular expression.'))) 28 28 ->appendChild( 29 - id(new AphrontFormSubmitControl()) 30 - ->setValue(pht('Search File Content'))); 29 + id(new PHUIFormMultiSubmitControl()) 30 + ->addButton('__ls__', pht('Search File Names')) 31 + ->addButton('__grep__', pht('Search File Content'))); 31 32 break; 32 33 } 33 34
+23 -10
src/applications/diffusion/controller/DiffusionBrowseSearchController.php
··· 53 53 $pager->setURI($this->getRequest()->getRequestURI(), 'page'); 54 54 55 55 try { 56 - 57 - $results = $this->callConduitWithDiffusionRequest( 58 - 'diffusion.searchquery', 59 - array( 60 - 'grep' => $this->getRequest()->getStr('grep'), 61 - 'stableCommitName' => $drequest->getStableCommitName(), 62 - 'path' => $drequest->getPath(), 63 - 'limit' => $limit + 1, 64 - 'offset' => $page)); 65 - 56 + if ($this->getRequest()->getStr('__grep__')) { 57 + $results = $this->callConduitWithDiffusionRequest( 58 + 'diffusion.searchquery', 59 + array( 60 + 'grep' => $this->getRequest()->getStr('grep'), 61 + 'stableCommitName' => $drequest->getStableCommitName(), 62 + 'path' => $drequest->getPath(), 63 + 'limit' => $limit + 1, 64 + 'offset' => $page)); 65 + } else { // Filename search. 66 + $results_raw = $this->callConduitWithDiffusionRequest( 67 + 'diffusion.querypaths', 68 + array( 69 + 'pattern' => $this->getRequest()->getStr('grep'), 70 + 'commit' => $drequest->getStableCommitName(), 71 + 'path' => $drequest->getPath(), 72 + 'limit' => $limit + 1, 73 + 'offset' => $page)); 74 + $results = []; 75 + foreach ($results_raw as $result) { 76 + $results[] = array($result, null, null); 77 + } 78 + } 66 79 } catch (ConduitException $ex) { 67 80 $err = $ex->getErrorDescription(); 68 81 if ($err != '') {
+1
src/view/form/control/PHUIFormMultiSubmitControl.php
··· 41 41 'class' => $class, 42 42 'disabled' => $this->getDisabled() ? 'disabled' : null, 43 43 )); 44 + return $this; 44 45 } 45 46 46 47 protected function getCustomControlClass() {