mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-30 18:52:42 +01:00
156b156e77
Summary: Ref T7803. Ref T5873. I want to drive Conduit through more shared infrastructure, but can't currently add parameters automatically. Put a `getX()` around the `defineX()` methods so the parent can provide default behaviors. Also like 60% of methods don't define any special error types; don't require them to implement this method. I want to move away from this in general. Test Plan: - Ran `arc unit --everything`. - Called `conduit.query`. - Browsed Conduit UI. Reviewers: btrahan Reviewed By: btrahan Subscribers: hach-que, epriestley Maniphest Tasks: T5873, T7803 Differential Revision: https://secure.phabricator.com/D12380
105 lines
2.7 KiB
PHP
105 lines
2.7 KiB
PHP
<?php
|
|
|
|
final class DiffusionQueryPathsConduitAPIMethod
|
|
extends DiffusionQueryConduitAPIMethod {
|
|
|
|
public function getAPIMethodName() {
|
|
return 'diffusion.querypaths';
|
|
}
|
|
|
|
public function getMethodDescription() {
|
|
return pht('Filename search on a repository.');
|
|
}
|
|
|
|
protected function defineReturnType() {
|
|
return 'list<string>';
|
|
}
|
|
|
|
protected function defineCustomParamTypes() {
|
|
return array(
|
|
'path' => 'required string',
|
|
'commit' => 'required string',
|
|
'pattern' => 'optional 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');
|
|
|
|
$entire_manifest = id(new DiffusionLowLevelMercurialPathsQuery())
|
|
->setRepository($repository)
|
|
->withCommit($commit)
|
|
->withPath($path)
|
|
->execute();
|
|
|
|
$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 = (int)$request->getValue('limit');
|
|
$offset = (int)$request->getValue('offset');
|
|
|
|
if (strlen($pattern)) {
|
|
$pattern = '/'.preg_quote($pattern, '/').'/';
|
|
}
|
|
|
|
$results = array();
|
|
$count = 0;
|
|
foreach ($lines as $line) {
|
|
if (!$pattern || preg_match($pattern, $line)) {
|
|
if ($count >= $offset) {
|
|
$results[] = $line;
|
|
}
|
|
|
|
$count++;
|
|
|
|
if ($limit && ($count >= ($offset + $limit))) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $results;
|
|
}
|
|
|
|
}
|