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

Use Conduit in PhabricatorRepositoryGitCommitChangeParserWorker

Summary:
Ref T2783. This allows this worker to run on a machine different to the one that stores the repository, by routing the execution of Git over Conduit calls.

This API method is super gross, but fixing it isn't straightforward and it runs into other complicated considerations. We can fix it later; for now, just define it as "internal" to limit how much mess this creates.

"Internal" methods do not appear on the console.

Test Plan: Ran `bin/repository reparse --change <commit> --trace` on several commits, saw daemons make a Conduit call instead of running a `git` command.

Reviewers: hach-que, chad

Reviewed By: chad

Subscribers: joshuaspence, Korvin, epriestley

Maniphest Tasks: T2783

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

authored by

June Rhodes and committed by
epriestley
7150aa8e 0379cc10

+106 -32
+2
src/__phutil_library_map__.php
··· 650 650 'DiffusionHovercardEngineExtension' => 'applications/diffusion/engineextension/DiffusionHovercardEngineExtension.php', 651 651 'DiffusionInlineCommentController' => 'applications/diffusion/controller/DiffusionInlineCommentController.php', 652 652 'DiffusionInlineCommentPreviewController' => 'applications/diffusion/controller/DiffusionInlineCommentPreviewController.php', 653 + 'DiffusionInternalGitRawDiffQueryConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionInternalGitRawDiffQueryConduitAPIMethod.php', 653 654 'DiffusionLastModifiedController' => 'applications/diffusion/controller/DiffusionLastModifiedController.php', 654 655 'DiffusionLastModifiedQueryConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionLastModifiedQueryConduitAPIMethod.php', 655 656 'DiffusionLintController' => 'applications/diffusion/controller/DiffusionLintController.php', ··· 4836 4837 'DiffusionHovercardEngineExtension' => 'PhabricatorHovercardEngineExtension', 4837 4838 'DiffusionInlineCommentController' => 'PhabricatorInlineCommentController', 4838 4839 'DiffusionInlineCommentPreviewController' => 'PhabricatorInlineCommentPreviewController', 4840 + 'DiffusionInternalGitRawDiffQueryConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod', 4839 4841 'DiffusionLastModifiedController' => 'DiffusionController', 4840 4842 'DiffusionLastModifiedQueryConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod', 4841 4843 'DiffusionLintController' => 'DiffusionController',
+3
src/applications/conduit/method/ConduitAPIMethod.php
··· 52 52 53 53 abstract protected function execute(ConduitAPIRequest $request); 54 54 55 + public function isInternalAPI() { 56 + return false; 57 + } 55 58 56 59 public function getParamTypes() { 57 60 $types = $this->defineParamTypes();
+14
src/applications/conduit/query/PhabricatorConduitMethodQuery.php
··· 9 9 private $applicationNames; 10 10 private $nameContains; 11 11 private $methods; 12 + private $isInternal; 12 13 13 14 public function withMethods(array $methods) { 14 15 $this->methods = $methods; ··· 37 38 38 39 public function withIsDeprecated($is_deprecated) { 39 40 $this->isDeprecated = $is_deprecated; 41 + return $this; 42 + } 43 + 44 + public function withIsInternal($is_internal) { 45 + $this->isInternal = $is_internal; 40 46 return $this; 41 47 } 42 48 ··· 107 113 foreach ($methods as $key => $method) { 108 114 $needle = $method->getAPIMethodName(); 109 115 if (empty($map[$needle])) { 116 + unset($methods[$key]); 117 + } 118 + } 119 + } 120 + 121 + if ($this->isInternal !== null) { 122 + foreach ($methods as $key => $method) { 123 + if ($method->isInternalAPI() !== $this->isInternal) { 110 124 unset($methods[$key]); 111 125 } 112 126 }
+1
src/applications/conduit/query/PhabricatorConduitSearchEngine.php
··· 37 37 $query->withIsStable($saved->getParameter('isStable')); 38 38 $query->withIsUnstable($saved->getParameter('isUnstable')); 39 39 $query->withIsDeprecated($saved->getParameter('isDeprecated')); 40 + $query->withIsInternal(false); 40 41 41 42 $names = $saved->getParameter('applicationNames', array()); 42 43 if ($names) {
+74
src/applications/diffusion/conduit/DiffusionInternalGitRawDiffQueryConduitAPIMethod.php
··· 1 + <?php 2 + 3 + final class DiffusionInternalGitRawDiffQueryConduitAPIMethod 4 + extends DiffusionQueryConduitAPIMethod { 5 + 6 + public function isInternalAPI() { 7 + return true; 8 + } 9 + 10 + public function getAPIMethodName() { 11 + return 'diffusion.internal.gitrawdiffquery'; 12 + } 13 + 14 + public function getMethodDescription() { 15 + return pht('Internal method for getting raw diff information.'); 16 + } 17 + 18 + protected function defineReturnType() { 19 + return 'string'; 20 + } 21 + 22 + protected function defineCustomParamTypes() { 23 + return array( 24 + 'commit' => 'required string', 25 + ); 26 + } 27 + 28 + protected function getResult(ConduitAPIRequest $request) { 29 + $drequest = $this->getDiffusionRequest(); 30 + $repository = $drequest->getRepository(); 31 + 32 + if (!$repository->isGit()) { 33 + throw new Exception( 34 + pht( 35 + 'This API method can only be called on Git repositories.')); 36 + } 37 + 38 + // Check if the commit has parents. We're testing to see whether it is the 39 + // first commit in history (in which case we must use "git log") or some 40 + // other commit (in which case we can use "git diff"). We'd rather use 41 + // "git diff" because it has the right behavior for merge commits, but 42 + // it requires the commit to have a parent that we can diff against. The 43 + // first commit doesn't, so "commit^" is not a valid ref. 44 + list($parents) = $repository->execxLocalCommand( 45 + 'log -n1 --format=%s %s', 46 + '%P', 47 + $request->getValue('commit')); 48 + 49 + $use_log = !strlen(trim($parents)); 50 + if ($use_log) { 51 + // This is the first commit so we need to use "log". We know it's not a 52 + // merge commit because it couldn't be merging anything, so this is safe. 53 + 54 + // NOTE: "--pretty=format: " is to disable diff output, we only want the 55 + // part we get from "--raw". 56 + list($raw) = $repository->execxLocalCommand( 57 + 'log -n1 -M -C -B --find-copies-harder --raw -t '. 58 + '--pretty=format: --abbrev=40 %s', 59 + $request->getValue('commit')); 60 + } else { 61 + // Otherwise, we can use "diff", which will give us output for merges. 62 + // We diff against the first parent, as this is generally the expectation 63 + // and results in sensible behavior. 64 + list($raw) = $repository->execxLocalCommand( 65 + 'diff -n1 -M -C -B --find-copies-harder --raw -t '. 66 + '--abbrev=40 %s^1 %s', 67 + $request->getValue('commit'), 68 + $request->getValue('commit')); 69 + } 70 + 71 + return $raw; 72 + } 73 + 74 + }
+12 -32
src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryGitCommitChangeParserWorker.php
··· 7 7 PhabricatorRepository $repository, 8 8 PhabricatorRepositoryCommit $commit) { 9 9 10 - // Check if the commit has parents. We're testing to see whether it is the 11 - // first commit in history (in which case we must use "git log") or some 12 - // other commit (in which case we can use "git diff"). We'd rather use 13 - // "git diff" because it has the right behavior for merge commits, but 14 - // it requires the commit to have a parent that we can diff against. The 15 - // first commit doesn't, so "commit^" is not a valid ref. 16 - list($parents) = $repository->execxLocalCommand( 17 - 'log -n1 --format=%s %s', 18 - '%P', 19 - $commit->getCommitIdentifier()); 20 - 21 - $use_log = !strlen(trim($parents)); 22 - if ($use_log) { 23 - // This is the first commit so we need to use "log". We know it's not a 24 - // merge commit because it couldn't be merging anything, so this is safe. 25 - 26 - // NOTE: "--pretty=format: " is to disable diff output, we only want the 27 - // part we get from "--raw". 28 - list($raw) = $repository->execxLocalCommand( 29 - 'log -n1 -M -C -B --find-copies-harder --raw -t '. 30 - '--pretty=format: --abbrev=40 %s', 31 - $commit->getCommitIdentifier()); 32 - } else { 33 - // Otherwise, we can use "diff", which will give us output for merges. 34 - // We diff against the first parent, as this is generally the expectation 35 - // and results in sensible behavior. 36 - list($raw) = $repository->execxLocalCommand( 37 - 'diff -n1 -M -C -B --find-copies-harder --raw -t '. 38 - '--abbrev=40 %s^1 %s', 39 - $commit->getCommitIdentifier(), 40 - $commit->getCommitIdentifier()); 41 - } 10 + $viewer = PhabricatorUser::getOmnipotentUser(); 11 + $raw = DiffusionQuery::callConduitWithDiffusionRequest( 12 + $viewer, 13 + DiffusionRequest::newFromDictionary( 14 + array( 15 + 'repository' => $repository, 16 + 'user' => $viewer, 17 + )), 18 + 'diffusion.internal.gitrawdiffquery', 19 + array( 20 + 'commit' => $commit->getCommitIdentifier(), 21 + )); 42 22 43 23 $changes = array(); 44 24 $move_away = array();