2014-02-01 17:32:23 +01:00
|
|
|
<?php
|
|
|
|
|
Rename Conduit classes
Summary: Ref T5655. Rename Conduit classes and provide a `getAPIMethodName` method to declare the API method.
Test Plan:
```
> echo '{}' | arc --conduit-uri='http://phabricator.joshuaspence.com' call-conduit user.whoami
Waiting for JSON parameters on stdin...
{"error":null,"errorMessage":null,"response":{"phid":"PHID-USER-lioqffnwn6y475mu5ndb","userName":"josh","realName":"Joshua Spence","image":"http:\/\/phabricator.joshuaspence.com\/res\/1404425321T\/phabricator\/3eb28cd9\/rsrc\/image\/avatar.png","uri":"http:\/\/phabricator.joshuaspence.com\/p\/josh\/","roles":["admin","verified","approved","activated"]}}
```
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin, hach-que
Maniphest Tasks: T5655
Differential Revision: https://secure.phabricator.com/D9991
2014-07-25 02:54:15 +02:00
|
|
|
final class DiffusionQueryPathsConduitAPIMethod
|
|
|
|
extends DiffusionQueryConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'diffusion.querypaths';
|
|
|
|
}
|
2014-02-01 17:32:23 +01:00
|
|
|
|
|
|
|
public function getMethodDescription() {
|
|
|
|
return pht('Filename search on a repository.');
|
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineReturnType() {
|
2014-02-01 17:32:23 +01:00
|
|
|
return 'list<string>';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function defineCustomParamTypes() {
|
|
|
|
return array(
|
|
|
|
'path' => 'required string',
|
|
|
|
'commit' => 'required string',
|
2014-05-13 23:08:21 +02:00
|
|
|
'pattern' => 'optional string',
|
2014-02-01 17:32:23 +01:00
|
|
|
'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);
|
|
|
|
|
2014-05-13 23:08:21 +02:00
|
|
|
|
2014-02-01 17:32:23 +01:00
|
|
|
$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');
|
|
|
|
|
2014-08-28 22:08:42 +02:00
|
|
|
$entire_manifest = id(new DiffusionLowLevelMercurialPathsQuery())
|
|
|
|
->setRepository($repository)
|
|
|
|
->withCommit($commit)
|
|
|
|
->withPath($path)
|
|
|
|
->execute();
|
2014-02-01 17:32:23 +01:00
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
2014-05-13 23:08:21 +02:00
|
|
|
|
2014-02-01 17:32:23 +01:00
|
|
|
return $this->filterResults($lines, $request);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function filterResults($lines, ConduitAPIRequest $request) {
|
|
|
|
$pattern = $request->getValue('pattern');
|
2014-05-13 23:08:21 +02:00
|
|
|
$limit = (int)$request->getValue('limit');
|
|
|
|
$offset = (int)$request->getValue('offset');
|
|
|
|
|
|
|
|
if (strlen($pattern)) {
|
|
|
|
$pattern = '/'.preg_quote($pattern, '/').'/';
|
|
|
|
}
|
2014-02-01 17:32:23 +01:00
|
|
|
|
|
|
|
$results = array();
|
2014-05-13 23:08:21 +02:00
|
|
|
$count = 0;
|
2014-02-01 17:32:23 +01:00
|
|
|
foreach ($lines as $line) {
|
2014-05-13 23:08:21 +02:00
|
|
|
if (!$pattern || preg_match($pattern, $line)) {
|
|
|
|
if ($count >= $offset) {
|
|
|
|
$results[] = $line;
|
|
|
|
}
|
|
|
|
|
|
|
|
$count++;
|
|
|
|
|
|
|
|
if ($limit && ($count >= ($offset + $limit))) {
|
2014-02-01 17:32:23 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-13 23:08:21 +02:00
|
|
|
|
2014-02-01 17:32:23 +01:00
|
|
|
return $results;
|
|
|
|
}
|
Rename Conduit classes
Summary: Ref T5655. Rename Conduit classes and provide a `getAPIMethodName` method to declare the API method.
Test Plan:
```
> echo '{}' | arc --conduit-uri='http://phabricator.joshuaspence.com' call-conduit user.whoami
Waiting for JSON parameters on stdin...
{"error":null,"errorMessage":null,"response":{"phid":"PHID-USER-lioqffnwn6y475mu5ndb","userName":"josh","realName":"Joshua Spence","image":"http:\/\/phabricator.joshuaspence.com\/res\/1404425321T\/phabricator\/3eb28cd9\/rsrc\/image\/avatar.png","uri":"http:\/\/phabricator.joshuaspence.com\/p\/josh\/","roles":["admin","verified","approved","activated"]}}
```
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin, hach-que
Maniphest Tasks: T5655
Differential Revision: https://secure.phabricator.com/D9991
2014-07-25 02:54:15 +02:00
|
|
|
|
2014-02-01 17:32:23 +01:00
|
|
|
}
|