[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DiffusionQueryPathsConduitAPIMethod 4 extends DiffusionQueryConduitAPIMethod { 5 6 public function getAPIMethodName() { 7 return 'diffusion.querypaths'; 8 } 9 10 public function getMethodDescription() { 11 return pht('Filename search on a repository.'); 12 } 13 14 public function defineReturnType() { 15 return 'list<string>'; 16 } 17 18 protected function defineCustomParamTypes() { 19 return array( 20 'path' => 'required string', 21 'commit' => 'required string', 22 'pattern' => 'optional string', 23 'limit' => 'optional int', 24 'offset' => 'optional int', 25 ); 26 } 27 28 protected function getResult(ConduitAPIRequest $request) { 29 $results = parent::getResult($request); 30 $offset = $request->getValue('offset'); 31 return array_slice($results, $offset); 32 } 33 34 protected function getGitResult(ConduitAPIRequest $request) { 35 $drequest = $this->getDiffusionRequest(); 36 $path = $drequest->getPath(); 37 $commit = $request->getValue('commit'); 38 $repository = $drequest->getRepository(); 39 40 // http://comments.gmane.org/gmane.comp.version-control.git/197735 41 42 $future = $repository->getLocalCommandFuture( 43 'ls-tree --name-only -r -z %s -- %s', 44 $commit, 45 $path); 46 47 48 $lines = id(new LinesOfALargeExecFuture($future))->setDelimiter("\0"); 49 return $this->filterResults($lines, $request); 50 } 51 52 protected function getMercurialResult(ConduitAPIRequest $request) { 53 $drequest = $this->getDiffusionRequest(); 54 $repository = $drequest->getRepository(); 55 $path = $request->getValue('path'); 56 $commit = $request->getValue('commit'); 57 58 $entire_manifest = id(new DiffusionLowLevelMercurialPathsQuery()) 59 ->setRepository($repository) 60 ->withCommit($commit) 61 ->withPath($path) 62 ->execute(); 63 64 $match_against = trim($path, '/'); 65 $match_len = strlen($match_against); 66 67 $lines = array(); 68 foreach ($entire_manifest as $path) { 69 if (strlen($path) && !strncmp($path, $match_against, $match_len)) { 70 $lines[] = $path; 71 } 72 } 73 74 return $this->filterResults($lines, $request); 75 } 76 77 protected function filterResults($lines, ConduitAPIRequest $request) { 78 $pattern = $request->getValue('pattern'); 79 $limit = (int)$request->getValue('limit'); 80 $offset = (int)$request->getValue('offset'); 81 82 if (strlen($pattern)) { 83 $pattern = '/'.preg_quote($pattern, '/').'/'; 84 } 85 86 $results = array(); 87 $count = 0; 88 foreach ($lines as $line) { 89 if (!$pattern || preg_match($pattern, $line)) { 90 if ($count >= $offset) { 91 $results[] = $line; 92 } 93 94 $count++; 95 96 if ($limit && ($count >= ($offset + $limit))) { 97 break; 98 } 99 } 100 } 101 102 return $results; 103 } 104 105 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |