mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-30 02:32:42 +01:00
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
This commit is contained in:
parent
99676e8e33
commit
2d27324bef
5 changed files with 116 additions and 12 deletions
|
@ -169,6 +169,7 @@ phutil_register_library_map(array(
|
||||||
'ConduitAPI_diffusion_looksoon_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_looksoon_Method.php',
|
'ConduitAPI_diffusion_looksoon_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_looksoon_Method.php',
|
||||||
'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_mergedcommitsquery_Method.php',
|
'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_mergedcommitsquery_Method.php',
|
||||||
'ConduitAPI_diffusion_querycommits_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_querycommits_Method.php',
|
'ConduitAPI_diffusion_querycommits_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_querycommits_Method.php',
|
||||||
|
'ConduitAPI_diffusion_querypaths_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_querypaths_Method.php',
|
||||||
'ConduitAPI_diffusion_rawdiffquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_rawdiffquery_Method.php',
|
'ConduitAPI_diffusion_rawdiffquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_rawdiffquery_Method.php',
|
||||||
'ConduitAPI_diffusion_readmequery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_readmequery_Method.php',
|
'ConduitAPI_diffusion_readmequery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_readmequery_Method.php',
|
||||||
'ConduitAPI_diffusion_refsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_refsquery_Method.php',
|
'ConduitAPI_diffusion_refsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_refsquery_Method.php',
|
||||||
|
@ -2657,6 +2658,7 @@ phutil_register_library_map(array(
|
||||||
'ConduitAPI_diffusion_looksoon_Method' => 'ConduitAPI_diffusion_Method',
|
'ConduitAPI_diffusion_looksoon_Method' => 'ConduitAPI_diffusion_Method',
|
||||||
'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
||||||
'ConduitAPI_diffusion_querycommits_Method' => 'ConduitAPI_diffusion_Method',
|
'ConduitAPI_diffusion_querycommits_Method' => 'ConduitAPI_diffusion_Method',
|
||||||
|
'ConduitAPI_diffusion_querypaths_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
||||||
'ConduitAPI_diffusion_rawdiffquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
'ConduitAPI_diffusion_rawdiffquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
||||||
'ConduitAPI_diffusion_readmequery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
'ConduitAPI_diffusion_readmequery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
||||||
'ConduitAPI_diffusion_refsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
'ConduitAPI_diffusion_refsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class ConduitAPI_diffusion_querypaths_Method
|
||||||
|
extends ConduitAPI_diffusion_abstractquery_Method {
|
||||||
|
|
||||||
|
public function getMethodDescription() {
|
||||||
|
return pht('Filename search on a repository.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defineReturnType() {
|
||||||
|
return 'list<string>';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function defineCustomParamTypes() {
|
||||||
|
return array(
|
||||||
|
'path' => 'required string',
|
||||||
|
'commit' => 'required string',
|
||||||
|
'pattern' => 'required string',
|
||||||
|
'limit' => 'optional int',
|
||||||
|
'offset' => 'optional int',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getResult(ConduitAPIRequest $request) {
|
||||||
|
$results = parent::getResult($request);
|
||||||
|
$offset = $request->getValue('offset');
|
||||||
|
return array_slice($results, $offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getGitResult(ConduitAPIRequest $request) {
|
||||||
|
$drequest = $this->getDiffusionRequest();
|
||||||
|
$path = $drequest->getPath();
|
||||||
|
$commit = $request->getValue('commit');
|
||||||
|
$repository = $drequest->getRepository();
|
||||||
|
|
||||||
|
// http://comments.gmane.org/gmane.comp.version-control.git/197735
|
||||||
|
|
||||||
|
$future = $repository->getLocalCommandFuture(
|
||||||
|
'ls-tree --name-only -r -z %s -- %s',
|
||||||
|
$commit,
|
||||||
|
$path);
|
||||||
|
|
||||||
|
$lines = id(new LinesOfALargeExecFuture($future))->setDelimiter("\0");
|
||||||
|
return $this->filterResults($lines, $request);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getMercurialResult(ConduitAPIRequest $request) {
|
||||||
|
$drequest = $this->getDiffusionRequest();
|
||||||
|
$repository = $drequest->getRepository();
|
||||||
|
$path = $request->getValue('path');
|
||||||
|
$commit = $request->getValue('commit');
|
||||||
|
|
||||||
|
// Adapted from diffusion.browsequery.
|
||||||
|
list($entire_manifest) = $repository->execxLocalCommand(
|
||||||
|
'manifest --rev %s',
|
||||||
|
hgsprintf('%s', $commit));
|
||||||
|
$entire_manifest = explode("\n", $entire_manifest);
|
||||||
|
|
||||||
|
$match_against = trim($path, '/');
|
||||||
|
$match_len = strlen($match_against);
|
||||||
|
|
||||||
|
$lines = array();
|
||||||
|
foreach ($entire_manifest as $path) {
|
||||||
|
if (strlen($path) && !strncmp($path, $match_against, $match_len)) {
|
||||||
|
$lines[] = $path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->filterResults($lines, $request);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function filterResults($lines, ConduitAPIRequest $request) {
|
||||||
|
$pattern = $request->getValue('pattern');
|
||||||
|
$limit = $request->getValue('limit');
|
||||||
|
$offset = $request->getValue('offset');
|
||||||
|
|
||||||
|
$results = array();
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
if (preg_match('#'.str_replace('#', '\#', $pattern).'#', $line)) {
|
||||||
|
$results[] = $line;
|
||||||
|
if (count($results) >= $offset + $limit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,8 +26,9 @@ abstract class DiffusionBrowseController extends DiffusionController {
|
||||||
->setValue($this->getRequest()->getStr('grep'))
|
->setValue($this->getRequest()->getStr('grep'))
|
||||||
->setCaption(pht('Enter a regular expression.')))
|
->setCaption(pht('Enter a regular expression.')))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new PHUIFormMultiSubmitControl())
|
||||||
->setValue(pht('Search File Content')));
|
->addButton('__ls__', pht('Search File Names'))
|
||||||
|
->addButton('__grep__', pht('Search File Content')));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,16 +53,29 @@ final class DiffusionBrowseSearchController extends DiffusionBrowseController {
|
||||||
$pager->setURI($this->getRequest()->getRequestURI(), 'page');
|
$pager->setURI($this->getRequest()->getRequestURI(), 'page');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if ($this->getRequest()->getStr('__grep__')) {
|
||||||
$results = $this->callConduitWithDiffusionRequest(
|
$results = $this->callConduitWithDiffusionRequest(
|
||||||
'diffusion.searchquery',
|
'diffusion.searchquery',
|
||||||
array(
|
array(
|
||||||
'grep' => $this->getRequest()->getStr('grep'),
|
'grep' => $this->getRequest()->getStr('grep'),
|
||||||
'stableCommitName' => $drequest->getStableCommitName(),
|
'stableCommitName' => $drequest->getStableCommitName(),
|
||||||
'path' => $drequest->getPath(),
|
'path' => $drequest->getPath(),
|
||||||
'limit' => $limit + 1,
|
'limit' => $limit + 1,
|
||||||
'offset' => $page));
|
'offset' => $page));
|
||||||
|
} else { // Filename search.
|
||||||
|
$results_raw = $this->callConduitWithDiffusionRequest(
|
||||||
|
'diffusion.querypaths',
|
||||||
|
array(
|
||||||
|
'pattern' => $this->getRequest()->getStr('grep'),
|
||||||
|
'commit' => $drequest->getStableCommitName(),
|
||||||
|
'path' => $drequest->getPath(),
|
||||||
|
'limit' => $limit + 1,
|
||||||
|
'offset' => $page));
|
||||||
|
$results = [];
|
||||||
|
foreach ($results_raw as $result) {
|
||||||
|
$results[] = array($result, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (ConduitException $ex) {
|
} catch (ConduitException $ex) {
|
||||||
$err = $ex->getErrorDescription();
|
$err = $ex->getErrorDescription();
|
||||||
if ($err != '') {
|
if ($err != '') {
|
||||||
|
|
|
@ -41,6 +41,7 @@ final class PHUIFormMultiSubmitControl extends AphrontFormControl {
|
||||||
'class' => $class,
|
'class' => $class,
|
||||||
'disabled' => $this->getDisabled() ? 'disabled' : null,
|
'disabled' => $this->getDisabled() ? 'disabled' : null,
|
||||||
));
|
));
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getCustomControlClass() {
|
protected function getCustomControlClass() {
|
||||||
|
|
Loading…
Reference in a new issue