Differential D14943 Diff 36119 src/applications/diffusion/conduit/DiffusionSearchQueryConduitAPIMethod.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/conduit/DiffusionSearchQueryConduitAPIMethod.php
| Show All 19 Lines | return array( | ||||
| 'path' => 'required string', | 'path' => 'required string', | ||||
| 'commit' => 'optional string', | 'commit' => 'optional string', | ||||
| 'grep' => 'required string', | 'grep' => 'required string', | ||||
| 'limit' => 'optional int', | 'limit' => 'optional int', | ||||
| 'offset' => 'optional int', | 'offset' => 'optional int', | ||||
| ); | ); | ||||
| } | } | ||||
| protected function defineCustomErrorTypes() { | |||||
| return array( | |||||
| 'ERR-GREP-COMMAND' => pht('Grep command failed.'), | |||||
| ); | |||||
| } | |||||
| protected function getResult(ConduitAPIRequest $request) { | protected function getResult(ConduitAPIRequest $request) { | ||||
| try { | try { | ||||
| $results = parent::getResult($request); | $results = parent::getResult($request); | ||||
| } catch (CommandException $ex) { | } catch (CommandException $ex) { | ||||
| throw id(new ConduitException('ERR-GREP-COMMAND')) | $err = $ex->getError(); | ||||
| ->setErrorDescription($ex->getStderr()); | |||||
| if ($err === 1) { | |||||
| // `git grep` and `hg grep` exit with 1 if there are no matches; | |||||
| // assume we just didn't get any hits. | |||||
| return array(); | |||||
| } | |||||
| throw $ex; | |||||
| } | } | ||||
| $offset = $request->getValue('offset'); | $offset = $request->getValue('offset'); | ||||
| $results = array_slice($results, $offset); | $results = array_slice($results, $offset); | ||||
| return $results; | return $results; | ||||
| } | } | ||||
| Show All 10 Lines | $future = $repository->getLocalCommandFuture( | ||||
| // NOTE: --perl-regexp is available only with libpcre compiled in. | // NOTE: --perl-regexp is available only with libpcre compiled in. | ||||
| 'grep --extended-regexp --null -n --no-color -e %s %s -- %s', | 'grep --extended-regexp --null -n --no-color -e %s %s -- %s', | ||||
| $grep, | $grep, | ||||
| $drequest->getStableCommit(), | $drequest->getStableCommit(), | ||||
| $path); | $path); | ||||
| $binary_pattern = '/Binary file [^:]*:(.+) matches/'; | $binary_pattern = '/Binary file [^:]*:(.+) matches/'; | ||||
| $lines = new LinesOfALargeExecFuture($future); | $lines = new LinesOfALargeExecFuture($future); | ||||
| foreach ($lines as $line) { | foreach ($lines as $line) { | ||||
| $result = null; | $result = null; | ||||
| if (preg_match('/[^:]*:(.+)\0(.+)\0(.*)/', $line, $result)) { | if (preg_match('/[^:]*:(.+)\0(.+)\0(.*)/', $line, $result)) { | ||||
| $results[] = array_slice($result, 1); | $results[] = array_slice($result, 1); | ||||
| } else if (preg_match($binary_pattern, $line, $result)) { | } else if (preg_match($binary_pattern, $line, $result)) { | ||||
| list(, $path) = $result; | list(, $path) = $result; | ||||
| $results[] = array($path, null, pht('Binary file')); | $results[] = array($path, null, pht('Binary file')); | ||||
| } else { | } else { | ||||
| ▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines | |||||