@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Return no results from `grep` repository queries on error

Summary: Fixes T7852. Although `1` could also indicate other kinds of problems, assume it means "no results".

Test Plan: Searched for nonsense strings in Git and Mercurial. Searched for valid strings in Git and Mercurial.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T7852

Differential Revision: https://secure.phabricator.com/D14943

+27 -31
+7 -9
src/applications/diffusion/conduit/DiffusionQueryPathsConduitAPIMethod.php
··· 44 44 $commit, 45 45 $path); 46 46 47 - 48 47 $lines = id(new LinesOfALargeExecFuture($future))->setDelimiter("\0"); 49 48 return $this->filterResults($lines, $request); 50 49 } ··· 86 85 $results = array(); 87 86 $count = 0; 88 87 foreach ($lines as $line) { 89 - if (!$pattern || preg_match($pattern, $line)) { 90 - if ($count >= $offset) { 91 - $results[] = $line; 92 - } 88 + if (strlen($pattern) && !preg_match($pattern, $line)) { 89 + continue; 90 + } 93 91 94 - $count++; 92 + $results[] = $line; 93 + $count++; 95 94 96 - if ($limit && ($count >= ($offset + $limit))) { 97 - break; 98 - } 95 + if ($limit && ($count >= ($offset + $limit))) { 96 + break; 99 97 } 100 98 } 101 99
+10 -8
src/applications/diffusion/conduit/DiffusionSearchQueryConduitAPIMethod.php
··· 25 25 ); 26 26 } 27 27 28 - protected function defineCustomErrorTypes() { 29 - return array( 30 - 'ERR-GREP-COMMAND' => pht('Grep command failed.'), 31 - ); 32 - } 33 - 34 28 protected function getResult(ConduitAPIRequest $request) { 35 29 try { 36 30 $results = parent::getResult($request); 37 31 } catch (CommandException $ex) { 38 - throw id(new ConduitException('ERR-GREP-COMMAND')) 39 - ->setErrorDescription($ex->getStderr()); 32 + $err = $ex->getError(); 33 + 34 + if ($err === 1) { 35 + // `git grep` and `hg grep` exit with 1 if there are no matches; 36 + // assume we just didn't get any hits. 37 + return array(); 38 + } 39 + 40 + throw $ex; 40 41 } 41 42 42 43 $offset = $request->getValue('offset'); ··· 63 64 64 65 $binary_pattern = '/Binary file [^:]*:(.+) matches/'; 65 66 $lines = new LinesOfALargeExecFuture($future); 67 + 66 68 foreach ($lines as $line) { 67 69 $result = null; 68 70 if (preg_match('/[^:]*:(.+)\0(.+)\0(.*)/', $line, $result)) {
+10 -14
src/applications/diffusion/controller/DiffusionBrowseController.php
··· 351 351 } 352 352 353 353 private function renderSearchResults() { 354 + $request = $this->getRequest(); 355 + 354 356 $drequest = $this->getDiffusionRequest(); 355 357 $repository = $drequest->getRepository(); 356 358 $results = array(); 357 359 358 - $limit = 100; 359 - $page = $this->getRequest()->getInt('page', 0); 360 - $pager = new PHUIPagerView(); 361 - $pager->setPageSize($limit); 362 - $pager->setOffset($page); 363 - $pager->setURI($this->getRequest()->getRequestURI(), 'page'); 360 + $pager = id(new PHUIPagerView()) 361 + ->readFromRequest($request); 364 362 365 363 $search_mode = null; 366 - 367 364 switch ($repository->getVersionControlSystem()) { 368 365 case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 369 366 $results = array(); ··· 371 368 default: 372 369 if (strlen($this->getRequest()->getStr('grep'))) { 373 370 $search_mode = 'grep'; 374 - $query_string = $this->getRequest()->getStr('grep'); 371 + $query_string = $request->getStr('grep'); 375 372 $results = $this->callConduitWithDiffusionRequest( 376 373 'diffusion.searchquery', 377 374 array( 378 375 'grep' => $query_string, 379 376 'commit' => $drequest->getStableCommit(), 380 377 'path' => $drequest->getPath(), 381 - 'limit' => $limit + 1, 382 - 'offset' => $page, 378 + 'limit' => $pager->getPageSize() + 1, 379 + 'offset' => $pager->getOffset(), 383 380 )); 384 381 } else { // Filename search. 385 382 $search_mode = 'find'; 386 - $query_string = $this->getRequest()->getStr('find'); 383 + $query_string = $request->getStr('find'); 387 384 $results = $this->callConduitWithDiffusionRequest( 388 385 'diffusion.querypaths', 389 386 array( 390 387 'pattern' => $query_string, 391 388 'commit' => $drequest->getStableCommit(), 392 389 'path' => $drequest->getPath(), 393 - 'limit' => $limit + 1, 394 - 'offset' => $page, 390 + 'limit' => $pager->getPageSize() + 1, 391 + 'offset' => $pager->getOffset(), 395 392 )); 396 393 } 397 394 break; 398 395 } 399 - 400 396 $results = $pager->sliceResults($results); 401 397 402 398 if ($search_mode == 'grep') {