@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.

DiffusionFileContentQuery => Conduit

Summary: Ref T2784. This is probably pretty good except the fancy lint error saver now issue serial queries via Conduit.

Test Plan: reparsed commits on 3 repos - yay. viewed readme from diffusion UI on 3 repos - yay. viewed file content from diffusion UI on 3 repos - yay.

Reviewers: epriestley

Reviewed By: epriestley

CC: chad, aran, Korvin

Maniphest Tasks: T2784

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

+176 -37
+3
src/__phutil_library_map__.php
··· 147 147 'ConduitAPI_diffusion_abstractquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_abstractquery_Method.php', 148 148 'ConduitAPI_diffusion_branchquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_branchquery_Method.php', 149 149 'ConduitAPI_diffusion_existsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_existsquery_Method.php', 150 + 'ConduitAPI_diffusion_filecontentquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_filecontentquery_Method.php', 150 151 'ConduitAPI_diffusion_findsymbols_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_findsymbols_Method.php', 151 152 'ConduitAPI_diffusion_getcommits_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_getcommits_Method.php', 152 153 'ConduitAPI_diffusion_getlintmessages_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_getlintmessages_Method.php', ··· 1921 1922 'ConduitAPI_diffusion_abstractquery_Method' => 'ConduitAPI_diffusion_Method', 1922 1923 'ConduitAPI_diffusion_branchquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1923 1924 'ConduitAPI_diffusion_existsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1925 + 'ConduitAPI_diffusion_filecontentquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1924 1926 'ConduitAPI_diffusion_findsymbols_Method' => 'ConduitAPI_diffusion_Method', 1925 1927 'ConduitAPI_diffusion_getcommits_Method' => 'ConduitAPI_diffusion_Method', 1926 1928 'ConduitAPI_diffusion_getlintmessages_Method' => 'ConduitAPI_diffusion_Method', ··· 3475 3477 'ReleephDiffSizeFieldSpecification' => 'ReleephFieldSpecification', 3476 3478 'ReleephEvent' => 'ReleephDAO', 3477 3479 'ReleephFieldParseException' => 'Exception', 3480 + 'ReleephFieldSpecification' => 'PhabricatorMarkupInterface', 3478 3481 'ReleephFieldSpecificationIncompleteException' => 'Exception', 3479 3482 'ReleephInactiveProjectListView' => 'AphrontView', 3480 3483 'ReleephIntentFieldSpecification' => 'ReleephFieldSpecification',
+13 -1
src/applications/diffusion/conduit/ConduitAPI_diffusion_abstractquery_Method.php
··· 6 6 abstract class ConduitAPI_diffusion_abstractquery_Method 7 7 extends ConduitAPI_diffusion_Method { 8 8 9 + public function getMethodStatus() { 10 + return self::METHOD_STATUS_UNSTABLE; 11 + } 12 + public function getMethodStatusDescription() { 13 + return pht( 14 + 'See T2784 - migrating diffusion working copy calls to conduit methods. '. 15 + 'Until that task is completed (and possibly after) these methods are '. 16 + 'unstable.'); 17 + } 18 + 9 19 private $diffusionRequest; 10 20 protected function setDiffusionRequest(DiffusionRequest $request) { 11 21 $this->diffusionRequest = $request; ··· 71 81 final protected function execute(ConduitAPIRequest $request) { 72 82 $drequest = DiffusionRequest::newFromDictionary( 73 83 array( 74 - 'callsign' => $request->getValue('callsign'), 84 + 'callsign' => $request->getValue('callsign'), 85 + 'path' => $request->getValue('path'), 86 + 'commit' => $request->getValue('commit'), 75 87 )); 76 88 $this->setDiffusionRequest($drequest); 77 89
+45
src/applications/diffusion/conduit/ConduitAPI_diffusion_filecontentquery_Method.php
··· 1 + <?php 2 + 3 + /** 4 + * @group conduit 5 + */ 6 + final class ConduitAPI_diffusion_filecontentquery_Method 7 + extends ConduitAPI_diffusion_abstractquery_Method { 8 + 9 + public function getMethodDescription() { 10 + return 'Retrieve file content from a repository.'; 11 + } 12 + 13 + public function defineReturnType() { 14 + return 'array'; 15 + } 16 + 17 + protected function defineCustomParamTypes() { 18 + return array( 19 + 'path' => 'required string', 20 + 'commit' => 'required string', 21 + 'needsBlame' => 'optional bool', 22 + ); 23 + } 24 + 25 + protected function getResult(ConduitAPIRequest $request) { 26 + $drequest = $this->getDiffusionRequest(); 27 + $needs_blame = $request->getValue('needsBlame'); 28 + $file_query = DiffusionFileContentQuery::newFromDiffusionRequest( 29 + $drequest); 30 + $file_query 31 + ->setViewer($request->getUser()) 32 + ->setNeedsBlame($needs_blame); 33 + $file_content = $file_query->loadFileContent(); 34 + if ($needs_blame) { 35 + list($text_list, $rev_list, $blame_dict) = $file_query->getBlameData(); 36 + } else { 37 + $text_list = $rev_list = $blame_dict = array(); 38 + } 39 + $file_content 40 + ->setBlameDict($blame_dict) 41 + ->setRevList($rev_list) 42 + ->setTextList($text_list); 43 + return $file_content->toDictionary(); 44 + } 45 + }
+25 -21
src/applications/diffusion/controller/DiffusionBrowseFileController.php
··· 40 40 $needs_blame = true; 41 41 } 42 42 43 - $file_query = DiffusionFileContentQuery::newFromDiffusionRequest( 44 - $this->diffusionRequest); 45 - $file_query->setViewer($request->getUser()); 46 - $file_query->setNeedsBlame($needs_blame); 47 - $file_query->loadFileContent(); 48 - $data = $file_query->getRawData(); 43 + $file_content = DiffusionFileContent::newFromConduit( 44 + $this->callConduitWithDiffusionRequest( 45 + 'diffusion.filecontentquery', 46 + array( 47 + 'commit' => $drequest->getCommit(), 48 + 'path' => $drequest->getPath(), 49 + 'needsBlame' => $needs_blame, 50 + ))); 51 + $data = $file_content->getCorpus(); 49 52 50 53 if ($selected === 'raw') { 51 54 return $this->buildRawResponse($path, $data); ··· 56 59 // Build the content of the file. 57 60 $corpus = $this->buildCorpus( 58 61 $selected, 59 - $file_query, 62 + $file_content, 60 63 $needs_blame, 61 64 $drequest, 62 65 $path, ··· 160 163 '/'.$drequest->getPath()); 161 164 } 162 165 163 - private function buildCorpus($selected, 164 - DiffusionFileContentQuery $file_query, 165 - $needs_blame, 166 - DiffusionRequest $drequest, 167 - $path, 168 - $data) { 166 + private function buildCorpus( 167 + $selected, 168 + DiffusionFileContent $file_content, 169 + $needs_blame, 170 + DiffusionRequest $drequest, 171 + $path, 172 + $data) { 169 173 170 174 if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) { 171 175 $file = $this->loadFileForData($path, $data); ··· 189 193 array( 190 194 'style' => $style, 191 195 ), 192 - $file_query->getRawData()); 196 + $file_content->getCorpus()); 193 197 194 198 break; 195 199 196 200 case 'plainblame': 197 201 $style = 198 202 "margin: 1em 2em; width: 90%; height: 80em; font-family: monospace"; 199 - list($text_list, $rev_list, $blame_dict) = 200 - $file_query->getBlameData(); 203 + $text_list = $file_content->getTextList(); 204 + $rev_list = $file_content->getRevList(); 205 + $blame_dict = $file_content->getBlameDict(); 201 206 202 207 $rows = array(); 203 208 foreach ($text_list as $k => $line) { ··· 213 218 'style' => $style, 214 219 ), 215 220 implode("\n", $rows)); 216 - 217 221 break; 218 222 219 223 case 'highlighted': 220 224 case 'blame': 221 225 default: 222 226 require_celerity_resource('syntax-highlighting-css'); 223 - 224 - list($text_list, $rev_list, $blame_dict) = $file_query->getBlameData(); 227 + $text_list = $file_content->getTextList(); 228 + $rev_list = $file_content->getRevList(); 229 + $blame_dict = $file_content->getBlameDict(); 225 230 226 231 $text_list = implode("\n", $text_list); 227 232 $text_list = PhabricatorSyntaxHighlighter::highlightWithFilename( ··· 230 235 $text_list = explode("\n", $text_list); 231 236 232 237 $rows = $this->buildDisplayRows($text_list, $rev_list, $blame_dict, 233 - $needs_blame, $drequest, $file_query, $selected); 238 + $needs_blame, $drequest, $selected); 234 239 235 240 $corpus_table = javelin_tag( 236 241 'table', ··· 423 428 array $blame_dict, 424 429 $needs_blame, 425 430 DiffusionRequest $drequest, 426 - DiffusionFileContentQuery $file_query, 427 431 $selected) { 428 432 429 433 $handles = array();
+2 -2
src/applications/diffusion/data/DiffusionBranchInformation.php
··· 30 30 foreach ($dicts as $dict) { 31 31 $branches[] = id(new DiffusionBranchInformation()) 32 32 ->setName($dict['name']) 33 - ->setHeadCommitIdentifier($dict['head_commit_identifier']); 33 + ->setHeadCommitIdentifier($dict['headCommitIdentifier']); 34 34 } 35 35 return $branches; 36 36 } ··· 38 38 public function toDictionary() { 39 39 return array( 40 40 'name' => $this->getName(), 41 - 'head_commit_identifier' => $this->getHeadCommitIdentifier() 41 + 'headCommitIdentifier' => $this->getHeadCommitIdentifier() 42 42 ); 43 43 } 44 44
+46 -2
src/applications/diffusion/data/DiffusionFileContent.php
··· 3 3 final class DiffusionFileContent { 4 4 5 5 private $corpus; 6 + private $blameDict; 7 + private $revList; 8 + private $textList; 6 9 7 - final public function setCorpus($corpus) { 10 + public function setTextList(array $text_list) { 11 + $this->textList = $text_list; 12 + return $this; 13 + } 14 + public function getTextList() { 15 + return $this->textList; 16 + } 17 + 18 + public function setRevList(array $rev_list) { 19 + $this->revList = $rev_list; 20 + return $this; 21 + } 22 + public function getRevList() { 23 + return $this->revList; 24 + } 25 + 26 + public function setBlameDict(array $blame_dict) { 27 + $this->blameDict = $blame_dict; 28 + return $this; 29 + } 30 + public function getBlameDict() { 31 + return $this->blameDict; 32 + } 33 + 34 + public function setCorpus($corpus) { 8 35 $this->corpus = $corpus; 9 36 return $this; 10 37 } 11 38 12 - final public function getCorpus() { 39 + public function getCorpus() { 13 40 return $this->corpus; 41 + } 42 + 43 + public function toDictionary() { 44 + return array( 45 + 'corpus' => $this->getCorpus(), 46 + 'blameDict' => $this->getBlameDict(), 47 + 'revList' => $this->getRevList(), 48 + 'textList' => $this->getTextList() 49 + ); 50 + } 51 + 52 + public static function newFromConduit(array $dict) { 53 + return id(new DiffusionFileContent()) 54 + ->setCorpus($dict['corpus']) 55 + ->setBlameDict($dict['blameDict']) 56 + ->setRevList($dict['revList']) 57 + ->setTextList($dict['textList']); 14 58 } 15 59 16 60 }
+11 -5
src/applications/diffusion/query/browse/DiffusionBrowseQuery.php
··· 116 116 'path' => $readme->getFullPath(), 117 117 )); 118 118 119 - $content_query = DiffusionFileContentQuery::newFromDiffusionRequest( 120 - $readme_request); 121 - $content_query->setViewer($this->getViewer()); 122 - $content_query->loadFileContent(); 123 - $readme_content = $content_query->getRawData(); 119 + $file_content = DiffusionFileContent::newFromConduit( 120 + DiffusionQuery::callConduitWithDiffusionRequest( 121 + $this->getViewer(), 122 + $readme_request, 123 + 'diffusion.filecontentquery', 124 + array( 125 + 'commit' => $drequest->getStableCommitName(), 126 + 'path' => $readme->getFullPath(), 127 + 'needsBlame' => false, 128 + ))); 129 + $readme_content = $file_content->getCorpus(); 124 130 125 131 if (preg_match('/\\.txt$/', $readme->getPath())) { 126 132 $readme_content = phutil_escape_html_newlines($readme_content);
+31 -6
src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php
··· 1 1 <?php 2 2 3 + /** 4 + * NOTE: this class should only be used where local access to the repository 5 + * is guaranteed and NOT from within the Diffusion application. Diffusion 6 + * should use Conduit method 'diffusion.filecontentquery' to get this sort 7 + * of data. 8 + */ 3 9 abstract class DiffusionFileContentQuery extends DiffusionQuery { 4 10 5 11 private $needsBlame; ··· 40 46 return $this->fileContent->getCorpus(); 41 47 } 42 48 49 + /** 50 + * Pretty hairy function. If getNeedsBlame is false, this returns 51 + * 52 + * ($text_list, array(), array()) 53 + * 54 + * Where $text_list is the raw file content with trailing new lines stripped. 55 + * 56 + * If getNeedsBlame is true, this returns 57 + * 58 + * ($text_list, $line_rev_dict, $blame_dict) 59 + * 60 + * Where $text_list is just the lines of code -- the raw file content will 61 + * contain lots of blame data, $line_rev_dict is a dictionary of line number 62 + * => revision id, and $blame_dict is another complicated data structure. 63 + * In detail, $blame_dict contains [revision id][author] keys, as well 64 + * as [commit id][authorPhid] and [commit id][epoch] keys. 65 + * 66 + * @return ($text_list, $line_rev_dict, $blame_dict) 67 + */ 43 68 final public function getBlameData() { 44 69 $raw_data = preg_replace('/\n$/', '', $this->getRawData()); 45 70 46 71 $text_list = array(); 47 - $rev_list = array(); 72 + $line_rev_dict = array(); 48 73 $blame_dict = array(); 49 74 50 75 if (!$this->getNeedsBlame()) { ··· 56 81 57 82 list($rev_id, $author, $text) = $lines[$k]; 58 83 $text_list[$k] = $text; 59 - $rev_list[$k] = $rev_id; 84 + $line_rev_dict[$k] = $rev_id; 60 85 } 61 86 62 - $rev_list = $this->processRevList($rev_list); 87 + $line_rev_dict = $this->processRevList($line_rev_dict); 63 88 64 89 foreach ($lines as $k => $line) { 65 90 list($rev_id, $author, $text) = $line; 66 - $rev_id = $rev_list[$k]; 91 + $rev_id = $line_rev_dict[$k]; 67 92 68 93 if (!isset($blame_dict[$rev_id])) { 69 94 $blame_dict[$rev_id]['author'] = $author; ··· 75 100 $commits = id(new PhabricatorAuditCommitQuery()) 76 101 ->withIdentifiers( 77 102 $repository->getID(), 78 - array_unique($rev_list)) 103 + array_unique($line_rev_dict)) 79 104 ->execute(); 80 105 81 106 foreach ($commits as $commit) { ··· 101 126 102 127 } 103 128 104 - return array($text_list, $rev_list, $blame_dict); 129 + return array($text_list, $line_rev_dict, $blame_dict); 105 130 } 106 131 107 132 abstract protected function tokenizeLine($line);