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

Diffusion - move commit parents query to conduit

Summary:
Ref T2784. Relatively complicated one as this bad boy is used in a repository daemon.

While testing, I noticed bugs in the expandshortname query stuff. Those variables are private to the parent class so they need some setX love.

Also, was unable to find links to the "before" stuff, but made them by hand by looking at some of these T2784 diffs, browsing a file at a specific revision, then hacking the "before" variable to be some known commit that also touched the file. This produced sensical results. On the process of doing that I upgraded a query to use the proper policy query.

Test Plan: In git, mercurial, svn, verified on a commit page the "parents" showed up correctly. played around with ?before parameter on specific file browse page, with commits known to have interesting history and stuff looked good

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T2784

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

+72 -16
+2
src/__phutil_library_map__.php
··· 148 148 'ConduitAPI_diffusion_branchquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_branchquery_Method.php', 149 149 'ConduitAPI_diffusion_browsequery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_browsequery_Method.php', 150 150 'ConduitAPI_diffusion_commitbranchesquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_commitbranchesquery_Method.php', 151 + 'ConduitAPI_diffusion_commitparentsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_commitparentsquery_Method.php', 151 152 'ConduitAPI_diffusion_diffquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_diffquery_Method.php', 152 153 'ConduitAPI_diffusion_existsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_existsquery_Method.php', 153 154 'ConduitAPI_diffusion_expandshortcommitquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_expandshortcommitquery_Method.php', ··· 1957 1958 'ConduitAPI_diffusion_branchquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1958 1959 'ConduitAPI_diffusion_browsequery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1959 1960 'ConduitAPI_diffusion_commitbranchesquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1961 + 'ConduitAPI_diffusion_commitparentsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1960 1962 'ConduitAPI_diffusion_diffquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1961 1963 'ConduitAPI_diffusion_existsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1962 1964 'ConduitAPI_diffusion_expandshortcommitquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
+31
src/applications/diffusion/conduit/ConduitAPI_diffusion_commitparentsquery_Method.php
··· 1 + <?php 2 + 3 + /** 4 + * @group conduit 5 + */ 6 + final class ConduitAPI_diffusion_commitparentsquery_Method 7 + extends ConduitAPI_diffusion_abstractquery_Method { 8 + 9 + public function getMethodDescription() { 10 + return 11 + 'Commit parent(s) information for a commit in a repository.'; 12 + } 13 + 14 + public function defineReturnType() { 15 + return 'array'; 16 + } 17 + 18 + protected function defineCustomParamTypes() { 19 + return array( 20 + 'commit' => 'required string', 21 + ); 22 + } 23 + 24 + protected function getResult(ConduitAPIRequest $request) { 25 + $drequest = $this->getDiffusionRequest(); 26 + 27 + $query = DiffusionCommitParentsQuery::newFromDiffusionRequest($drequest); 28 + $parents = $query->loadParents(); 29 + return $parents; 30 + } 31 + }
+9 -3
src/applications/diffusion/controller/DiffusionBrowseFileController.php
··· 866 866 $rename_query = new DiffusionRenameHistoryQuery(); 867 867 $rename_query->setRequest($drequest); 868 868 $rename_query->setOldCommit($grandparent->getCommitIdentifier()); 869 + $rename_query->setViewer($request->getUser()); 869 870 $old_filename = $rename_query->loadOldFilename(); 870 871 $was_created = $rename_query->getWasCreated(); 871 872 } ··· 954 955 955 956 private function loadParentRevisionOf($commit) { 956 957 $drequest = $this->getDiffusionRequest(); 958 + $user = $this->getRequest()->getUser(); 957 959 958 960 $before_req = DiffusionRequest::newFromDictionary( 959 961 array( 960 - 'user' => $this->getRequest()->getUser(), 962 + 'user' => $user, 961 963 'repository' => $drequest->getRepository(), 962 964 'commit' => $commit, 963 965 )); 964 966 965 - $query = DiffusionCommitParentsQuery::newFromDiffusionRequest($before_req); 966 - $parents = $query->loadParents(); 967 + $parents = DiffusionQuery::callConduitWithDiffusionRequest( 968 + $user, 969 + $before_req, 970 + 'diffusion.commitparentsquery', 971 + array( 972 + 'commit' => $commit)); 967 973 968 974 return head($parents); 969 975 }
+4 -3
src/applications/diffusion/controller/DiffusionCommitController.php
··· 74 74 require_celerity_resource('diffusion-commit-view-css'); 75 75 require_celerity_resource('phabricator-remarkup-css'); 76 76 77 - $parent_query = DiffusionCommitParentsQuery::newFromDiffusionRequest( 78 - $drequest); 77 + $parents = $this->callConduitWithDiffusionRequest( 78 + 'diffusion.commitparentsquery', 79 + array('commit' => $drequest->getCommit())); 79 80 80 81 $headsup_view = id(new PhabricatorHeaderView()) 81 82 ->setHeader(nonempty($commit->getSummary(), pht('Commit Detail'))); ··· 85 86 $commit_properties = $this->loadCommitProperties( 86 87 $commit, 87 88 $commit_data, 88 - $parent_query->loadParents()); 89 + $parents); 89 90 $property_list = id(new PhabricatorPropertyListView()) 90 91 ->setHasKeyboardShortcuts(true) 91 92 ->setUser($user)
+11 -4
src/applications/diffusion/query/DiffusionRenameHistoryQuery.php
··· 5 5 private $oldCommit; 6 6 private $wasCreated; 7 7 private $request; 8 + private $viewer; 9 + 10 + public function setViewer(PhabricatorUser $viewer) { 11 + $this->viewer = $viewer; 12 + return $this; 13 + } 8 14 9 15 public function getWasCreated() { 10 16 return $this->wasCreated; ··· 72 78 } 73 79 74 80 private function loadCommitId($commit_identifier) { 75 - $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( 76 - 'repositoryID = %d AND commitIdentifier = %s', 77 - $this->request->getRepository()->getID(), 78 - $commit_identifier); 81 + $commit = id(new DiffusionCommitQuery()) 82 + ->setViewer($this->viewer) 83 + ->withIdentifiers(array($commit_identifier)) 84 + ->withDefaultRepository($this->request->getRepository()) 85 + ->executeOne(); 79 86 return $commit->getID(); 80 87 } 81 88
+9
src/applications/diffusion/query/expandshortname/DiffusionExpandShortNameQuery.php
··· 22 22 return $this->repository; 23 23 } 24 24 25 + protected function setCommitType($type) { 26 + $this->commitType = $type; 27 + return $this; 28 + } 29 + protected function setTagContent($content) { 30 + $this->tagContent = $content; 31 + return $this; 32 + } 33 + 25 34 final public static function newFromRepository( 26 35 PhabricatorRepository $repository) { 27 36
+5 -5
src/applications/diffusion/query/expandshortname/DiffusionGitExpandShortNameQuery.php
··· 16 16 if ($type == 'missing') { 17 17 throw new DiffusionExpandCommitQueryException( 18 18 DiffusionExpandCommitQueryException::CODE_MISSING, 19 - "Bad commit '{$this->commit}'."); 19 + "Bad commit '{$commit}'."); 20 20 } 21 21 22 22 switch ($type) { 23 23 case 'tag': 24 - $this->commitType = 'tag'; 24 + $this->setCommitType('tag'); 25 25 26 26 $matches = null; 27 27 $ok = preg_match( ··· 35 35 } 36 36 37 37 $hash = $matches[1]; 38 - $this->tagContent = trim($matches[2]); 38 + $this->setTagContent(trim($matches[2])); 39 39 break; 40 40 case 'commit': 41 41 break; 42 42 default: 43 43 throw new DiffusionExpandCommitQueryException( 44 44 DiffusionExpandCommitQueryException::CODE_INVALID, 45 - "The reference '{$this->commit}' does not name a valid ". 45 + "The reference '{$commit}' does not name a valid ". 46 46 'commit or a tag in this repository.'); 47 47 break; 48 48 } 49 49 50 - $this->commit = $hash; 50 + $this->setCommit($hash); 51 51 } 52 52 }
+1 -1
src/applications/diffusion/query/expandshortname/DiffusionMercurialExpandShortNameQuery.php
··· 17 17 // TODO: Show "multiple matching commits" if count is larger than 1. For 18 18 // now, pick the first one. 19 19 20 - $this->commit = head($full_hash); 20 + $this->setCommit(head($full_hash)); 21 21 } 22 22 23 23 }