1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00

Diffusion - move some DiffusionRequest queries to occur over Conduit

Summary: Ref T2784. This one was a wee bit complicated. Had to add PhabricatorUser and concept of initFromConduit (or not) to DiffusionRequest.

Test Plan: foreach repo, visited CALLSIGN and clicked a commit and verified they laoded correctly. Hacked code to hit NOT via Conduit and repeated tests to great success.

Reviewers: epriestley

Reviewed By: epriestley

CC: chad, aran, Korvin

Maniphest Tasks: T2784

Differential Revision: https://secure.phabricator.com/D5928
This commit is contained in:
Bob Trahan 2013-05-14 15:32:19 -07:00
parent b10b1fc65f
commit 016b62a7ef
36 changed files with 418 additions and 104 deletions

View file

@ -149,6 +149,7 @@ phutil_register_library_map(array(
'ConduitAPI_diffusion_browsequery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_browsequery_Method.php', 'ConduitAPI_diffusion_browsequery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_browsequery_Method.php',
'ConduitAPI_diffusion_diffquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_diffquery_Method.php', 'ConduitAPI_diffusion_diffquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_diffquery_Method.php',
'ConduitAPI_diffusion_existsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_existsquery_Method.php', 'ConduitAPI_diffusion_existsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_existsquery_Method.php',
'ConduitAPI_diffusion_expandshortcommitquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_expandshortcommitquery_Method.php',
'ConduitAPI_diffusion_filecontentquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_filecontentquery_Method.php', 'ConduitAPI_diffusion_filecontentquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_filecontentquery_Method.php',
'ConduitAPI_diffusion_findsymbols_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_findsymbols_Method.php', 'ConduitAPI_diffusion_findsymbols_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_findsymbols_Method.php',
'ConduitAPI_diffusion_getcommits_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_getcommits_Method.php', 'ConduitAPI_diffusion_getcommits_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_getcommits_Method.php',
@ -429,6 +430,8 @@ phutil_register_library_map(array(
'DiffusionController' => 'applications/diffusion/controller/DiffusionController.php', 'DiffusionController' => 'applications/diffusion/controller/DiffusionController.php',
'DiffusionDiffController' => 'applications/diffusion/controller/DiffusionDiffController.php', 'DiffusionDiffController' => 'applications/diffusion/controller/DiffusionDiffController.php',
'DiffusionEmptyResultView' => 'applications/diffusion/view/DiffusionEmptyResultView.php', 'DiffusionEmptyResultView' => 'applications/diffusion/view/DiffusionEmptyResultView.php',
'DiffusionExpandCommitQueryException' => 'applications/diffusion/exception/DiffusionExpandCommitQueryException.php',
'DiffusionExpandShortNameQuery' => 'applications/diffusion/query/expandshortname/DiffusionExpandShortNameQuery.php',
'DiffusionExternalController' => 'applications/diffusion/controller/DiffusionExternalController.php', 'DiffusionExternalController' => 'applications/diffusion/controller/DiffusionExternalController.php',
'DiffusionFileContent' => 'applications/diffusion/data/DiffusionFileContent.php', 'DiffusionFileContent' => 'applications/diffusion/data/DiffusionFileContent.php',
'DiffusionFileContentQuery' => 'applications/diffusion/query/filecontent/DiffusionFileContentQuery.php', 'DiffusionFileContentQuery' => 'applications/diffusion/query/filecontent/DiffusionFileContentQuery.php',
@ -436,6 +439,7 @@ phutil_register_library_map(array(
'DiffusionGitBranchTestCase' => 'applications/diffusion/data/__tests__/DiffusionGitBranchTestCase.php', 'DiffusionGitBranchTestCase' => 'applications/diffusion/data/__tests__/DiffusionGitBranchTestCase.php',
'DiffusionGitCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionGitCommitParentsQuery.php', 'DiffusionGitCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionGitCommitParentsQuery.php',
'DiffusionGitContainsQuery' => 'applications/diffusion/query/contains/DiffusionGitContainsQuery.php', 'DiffusionGitContainsQuery' => 'applications/diffusion/query/contains/DiffusionGitContainsQuery.php',
'DiffusionGitExpandShortNameQuery' => 'applications/diffusion/query/expandshortname/DiffusionGitExpandShortNameQuery.php',
'DiffusionGitFileContentQuery' => 'applications/diffusion/query/filecontent/DiffusionGitFileContentQuery.php', 'DiffusionGitFileContentQuery' => 'applications/diffusion/query/filecontent/DiffusionGitFileContentQuery.php',
'DiffusionGitHistoryQuery' => 'applications/diffusion/query/history/DiffusionGitHistoryQuery.php', 'DiffusionGitHistoryQuery' => 'applications/diffusion/query/history/DiffusionGitHistoryQuery.php',
'DiffusionGitMergedCommitsQuery' => 'applications/diffusion/query/mergedcommits/DiffusionGitMergedCommitsQuery.php', 'DiffusionGitMergedCommitsQuery' => 'applications/diffusion/query/mergedcommits/DiffusionGitMergedCommitsQuery.php',
@ -454,6 +458,7 @@ phutil_register_library_map(array(
'DiffusionLintSaveRunner' => 'applications/diffusion/DiffusionLintSaveRunner.php', 'DiffusionLintSaveRunner' => 'applications/diffusion/DiffusionLintSaveRunner.php',
'DiffusionMercurialCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php', 'DiffusionMercurialCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php',
'DiffusionMercurialContainsQuery' => 'applications/diffusion/query/contains/DiffusionMercurialContainsQuery.php', 'DiffusionMercurialContainsQuery' => 'applications/diffusion/query/contains/DiffusionMercurialContainsQuery.php',
'DiffusionMercurialExpandShortNameQuery' => 'applications/diffusion/query/expandshortname/DiffusionMercurialExpandShortNameQuery.php',
'DiffusionMercurialFileContentQuery' => 'applications/diffusion/query/filecontent/DiffusionMercurialFileContentQuery.php', 'DiffusionMercurialFileContentQuery' => 'applications/diffusion/query/filecontent/DiffusionMercurialFileContentQuery.php',
'DiffusionMercurialHistoryQuery' => 'applications/diffusion/query/history/DiffusionMercurialHistoryQuery.php', 'DiffusionMercurialHistoryQuery' => 'applications/diffusion/query/history/DiffusionMercurialHistoryQuery.php',
'DiffusionMercurialMergedCommitsQuery' => 'applications/diffusion/query/mergedcommits/DiffusionMercurialMergedCommitsQuery.php', 'DiffusionMercurialMergedCommitsQuery' => 'applications/diffusion/query/mergedcommits/DiffusionMercurialMergedCommitsQuery.php',
@ -1940,6 +1945,7 @@ phutil_register_library_map(array(
'ConduitAPI_diffusion_browsequery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 'ConduitAPI_diffusion_browsequery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
'ConduitAPI_diffusion_diffquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 'ConduitAPI_diffusion_diffquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
'ConduitAPI_diffusion_existsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 'ConduitAPI_diffusion_existsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
'ConduitAPI_diffusion_expandshortcommitquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
'ConduitAPI_diffusion_filecontentquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 'ConduitAPI_diffusion_filecontentquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
'ConduitAPI_diffusion_findsymbols_Method' => 'ConduitAPI_diffusion_Method', 'ConduitAPI_diffusion_findsymbols_Method' => 'ConduitAPI_diffusion_Method',
'ConduitAPI_diffusion_getcommits_Method' => 'ConduitAPI_diffusion_Method', 'ConduitAPI_diffusion_getcommits_Method' => 'ConduitAPI_diffusion_Method',
@ -2210,11 +2216,14 @@ phutil_register_library_map(array(
'DiffusionController' => 'PhabricatorController', 'DiffusionController' => 'PhabricatorController',
'DiffusionDiffController' => 'DiffusionController', 'DiffusionDiffController' => 'DiffusionController',
'DiffusionEmptyResultView' => 'DiffusionView', 'DiffusionEmptyResultView' => 'DiffusionView',
'DiffusionExpandCommitQueryException' => 'Exception',
'DiffusionExpandShortNameQuery' => 'DiffusionQuery',
'DiffusionExternalController' => 'DiffusionController', 'DiffusionExternalController' => 'DiffusionController',
'DiffusionFileContentQuery' => 'DiffusionQuery', 'DiffusionFileContentQuery' => 'DiffusionQuery',
'DiffusionGitBranchTestCase' => 'PhabricatorTestCase', 'DiffusionGitBranchTestCase' => 'PhabricatorTestCase',
'DiffusionGitCommitParentsQuery' => 'DiffusionCommitParentsQuery', 'DiffusionGitCommitParentsQuery' => 'DiffusionCommitParentsQuery',
'DiffusionGitContainsQuery' => 'DiffusionContainsQuery', 'DiffusionGitContainsQuery' => 'DiffusionContainsQuery',
'DiffusionGitExpandShortNameQuery' => 'DiffusionExpandShortNameQuery',
'DiffusionGitFileContentQuery' => 'DiffusionFileContentQuery', 'DiffusionGitFileContentQuery' => 'DiffusionFileContentQuery',
'DiffusionGitHistoryQuery' => 'DiffusionHistoryQuery', 'DiffusionGitHistoryQuery' => 'DiffusionHistoryQuery',
'DiffusionGitMergedCommitsQuery' => 'DiffusionMergedCommitsQuery', 'DiffusionGitMergedCommitsQuery' => 'DiffusionMergedCommitsQuery',
@ -2232,6 +2241,7 @@ phutil_register_library_map(array(
'DiffusionLintDetailsController' => 'DiffusionController', 'DiffusionLintDetailsController' => 'DiffusionController',
'DiffusionMercurialCommitParentsQuery' => 'DiffusionCommitParentsQuery', 'DiffusionMercurialCommitParentsQuery' => 'DiffusionCommitParentsQuery',
'DiffusionMercurialContainsQuery' => 'DiffusionContainsQuery', 'DiffusionMercurialContainsQuery' => 'DiffusionContainsQuery',
'DiffusionMercurialExpandShortNameQuery' => 'DiffusionExpandShortNameQuery',
'DiffusionMercurialFileContentQuery' => 'DiffusionFileContentQuery', 'DiffusionMercurialFileContentQuery' => 'DiffusionFileContentQuery',
'DiffusionMercurialHistoryQuery' => 'DiffusionHistoryQuery', 'DiffusionMercurialHistoryQuery' => 'DiffusionHistoryQuery',
'DiffusionMercurialMergedCommitsQuery' => 'DiffusionMergedCommitsQuery', 'DiffusionMercurialMergedCommitsQuery' => 'DiffusionMergedCommitsQuery',

View file

@ -263,6 +263,7 @@ final class DifferentialChangesetListView extends AphrontView {
try { try {
$meta['diffusionURI'] = $meta['diffusionURI'] =
(string)$repository->getDiffusionBrowseURIForPath( (string)$repository->getDiffusionBrowseURIForPath(
$this->user,
$changeset->getAbsoluteRepositoryPath($repository, $this->diff), $changeset->getAbsoluteRepositoryPath($repository, $this->diff),
idx($changeset->getMetadata(), 'line:first'), idx($changeset->getMetadata(), 'line:first'),
$this->getBranch()); $this->getBranch());

View file

@ -235,6 +235,8 @@ final class DiffusionLintSaveRunner {
$futures = array(); $futures = array();
foreach ($this->blame as $path => $lines) { foreach ($this->blame as $path => $lines) {
$drequest = DiffusionRequest::newFromDictionary(array( $drequest = DiffusionRequest::newFromDictionary(array(
'user' => PhabricatorUser::getOmnipotentUser(),
'initFromConduit' => false,
'repository' => $repository, 'repository' => $repository,
'branch' => $this->branch->getName(), 'branch' => $this->branch->getName(),
'path' => $path, 'path' => $path,

View file

@ -17,6 +17,9 @@ abstract class ConduitAPI_diffusion_abstractquery_Method
} }
private $diffusionRequest; private $diffusionRequest;
private $repository;
private $shouldCreateDiffusionRequest = true;
protected function setDiffusionRequest(DiffusionRequest $request) { protected function setDiffusionRequest(DiffusionRequest $request) {
$this->diffusionRequest = $request; $this->diffusionRequest = $request;
return $this; return $this;
@ -25,10 +28,54 @@ abstract class ConduitAPI_diffusion_abstractquery_Method
return $this->diffusionRequest; return $this->diffusionRequest;
} }
/**
* A wee bit of magic here. If @{method:shouldCreateDiffusionRequest}
* returns false, this function grabs a repository object based on the
* callsign directly. Otherwise, the repository was loaded when we created a
* @{class:DiffusionRequest}, so this function just pulls it out of the
* @{class:DiffusionRequest}.
*
* @return @{class:PhabricatorRepository} $repository
*/
protected function getRepository(ConduitAPIRequest $request) {
if (!$this->repository) {
if ($this->shouldCreateDiffusionRequest()) {
$this->repository = $this->getDiffusionRequest()->getRepository();
} else {
$callsign = $request->getValue('callsign');
$repository = id(new PhabricatorRepository())->loadOneWhere(
'callsign = %s',
$callsign);
if (!$repository) {
throw new ConduitException('ERR-UNKNOWN-REPOSITORY');
}
$this->repository = $repository;
}
}
return $this->repository;
}
/**
* You should probably not mess with this unless your conduit method is
* involved with the creation / validation / etc. of
* @{class:DiffusionRequest}s. If you are dealing with
* @{class:DiffusionRequest}, setting this to false should help avoid
* infinite loops.
*/
protected function setShouldCreateDiffusionRequest($should) {
$this->shouldCreateDiffusionRequest = $should;
return $this;
}
private function shouldCreateDiffusionRequest() {
return $this->shouldCreateDiffusionRequest;
}
final public function defineErrorTypes() { final public function defineErrorTypes() {
return $this->defineCustomErrorTypes() + return $this->defineCustomErrorTypes() +
array( array(
'ERR-UNKNOWN-REPOSITORY-VCS' => 'ERR-UNKNOWN-REPOSITORY' =>
pht('There is no repository with that callsign.'),
'ERR-UNKNOWN-VCS-TYPE' =>
pht('Unknown repository VCS type.'), pht('Unknown repository VCS type.'),
'ERR-UNSUPPORTED-VCS' => 'ERR-UNSUPPORTED-VCS' =>
pht('VCS is not supported for this method.')); pht('VCS is not supported for this method.'));
@ -70,29 +117,39 @@ abstract class ConduitAPI_diffusion_abstractquery_Method
} }
/** /**
* This method is final because each query will need to construct a * This method is final because most queries will need to construct a
* @{class:DiffusionRequest} and use it. Consolidating this codepath and * @{class:DiffusionRequest} and use it. Consolidating this codepath and
* enforcing @{method:getDiffusionRequest} works when we need it is good. * enforcing @{method:getDiffusionRequest} works when we need it is good.
* *
* @{method:getResult} should be overridden by subclasses as necessary, e.g. * @{method:getResult} should be overridden by subclasses as necessary, e.g.
* there is a common operation across all version control systems that * there is a common operation across all version control systems that
* should occur after @{method:getResult}, like formatting a timestamp. * should occur after @{method:getResult}, like formatting a timestamp.
*
* In the rare cases where one does not want to create a
* @{class:DiffusionRequest} - suppose to avoid infinite loops in the
* creation of a @{class:DiffusionRequest} - make sure to call
*
* $this->setShouldCreateDiffusionRequest(false);
*
* in the constructor of the pertinent Conduit method.
*/ */
final protected function execute(ConduitAPIRequest $request) { final protected function execute(ConduitAPIRequest $request) {
$drequest = DiffusionRequest::newFromDictionary( if ($this->shouldCreateDiffusionRequest()) {
array( $drequest = DiffusionRequest::newFromDictionary(
'callsign' => $request->getValue('callsign'), array(
'path' => $request->getValue('path'), 'user' => $request->getUser(),
'commit' => $request->getValue('commit'), 'callsign' => $request->getValue('callsign'),
)); 'path' => $request->getValue('path'),
$this->setDiffusionRequest($drequest); 'commit' => $request->getValue('commit'),
));
$this->setDiffusionRequest($drequest);
}
return $this->getResult($request); return $this->getResult($request);
} }
protected function getResult(ConduitAPIRequest $request) { protected function getResult(ConduitAPIRequest $request) {
$drequest = $this->getDiffusionRequest(); $repository = $this->getRepository($request);
$repository = $drequest->getRepository();
$result = null; $result = null;
switch ($repository->getVersionControlSystem()) { switch ($repository->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
@ -105,7 +162,7 @@ abstract class ConduitAPI_diffusion_abstractquery_Method
$result = $this->getSVNResult($request); $result = $this->getSVNResult($request);
break; break;
default: default:
throw new ConduitException('ERR-UNKNOWN-REPOSITORY-VCS'); throw new ConduitException('ERR-UNKNOWN-VCS-TYPE');
break; break;
} }
return $result; return $result;

View file

@ -61,9 +61,10 @@ final class ConduitAPI_diffusion_browsequery_Method
$readme_request = DiffusionRequest::newFromDictionary( $readme_request = DiffusionRequest::newFromDictionary(
array( array(
'repository' => $drequest->getRepository(), 'user' => $request->getUser(),
'commit' => $drequest->getStableCommitName(), 'repository' => $drequest->getRepository(),
'path' => $readme->getFullPath(), 'commit' => $drequest->getStableCommitName(),
'path' => $readme->getFullPath(),
)); ));
$file_content = DiffusionFileContent::newFromConduit( $file_content = DiffusionFileContent::newFromConduit(

View file

@ -0,0 +1,70 @@
<?php
/**
* @group conduit
*/
final class ConduitAPI_diffusion_expandshortcommitquery_Method
extends ConduitAPI_diffusion_abstractquery_Method {
public function __construct() {
$this->setShouldCreateDiffusionRequest(false);
}
public function getMethodDescription() {
return
'Expands a short commit name to its full glory.';
}
public function defineReturnType() {
return 'array';
}
protected function defineCustomParamTypes() {
return array(
'commit' => 'required string',
);
}
protected function defineCustomErrorTypes() {
return array(
'ERR-MISSING-COMMIT' => pht(
'Bad commit.'),
'ERR-INVALID-COMMIT' => pht(
'Invalid object name.'),
'ERR-UNPARSEABLE-OUTPUT' => pht(
'Unparseable output from cat-file.')
);
}
protected function getGitResult(ConduitAPIRequest $request) {
return $this->getGitOrMercurialResult($request);
}
protected function getMercurialResult(ConduitAPIRequest $request) {
return $this->getGitOrMercurialResult($request);
}
private function getGitOrMercurialResult(ConduitAPIRequest $request) {
$repository = $this->getRepository($request);
$query = DiffusionExpandShortNameQuery::newFromRepository($repository);
$query->setCommit($request->getValue('commit'));
try {
$result = $query->expand();
return $result;
} catch (DiffusionExpandCommitQueryException $e) {
switch ($e->getStatusCode()) {
case DiffusionExpandCommitQueryException::CODE_INVALID:
throw id(new ConduitException('ERR-INVALID-COMMIT'))
->setErrorDescription($e->getMessage());
break;
case DiffusionExpandCommitQueryException::CODE_MISSING:
throw id(new ConduitException('ERR-MISSING-COMMIT'))
->setErrorDescription($e->getMessage());
break;
case DiffusionExpandCommitQueryException::CODE_UNPARSEABLE:
throw id(new ConduitException('ERR-UNPARSEABLE-OUTPUT'))
->setErrorDescription($e->getMessage());
break;
}
}
}
}

View file

@ -32,8 +32,9 @@ final class ConduitAPI_diffusion_getrecentcommitsbypath_Method
protected function execute(ConduitAPIRequest $request) { protected function execute(ConduitAPIRequest $request) {
$drequest = DiffusionRequest::newFromDictionary( $drequest = DiffusionRequest::newFromDictionary(
array( array(
'callsign' => $request->getValue('callsign'), 'user' => $request->getUser(),
'path' => $request->getValue('path'), 'callsign' => $request->getValue('callsign'),
'path' => $request->getValue('path'),
)); ));
$limit = nonempty( $limit = nonempty(

View file

@ -957,6 +957,7 @@ final class DiffusionBrowseFileController extends DiffusionController {
$before_req = DiffusionRequest::newFromDictionary( $before_req = DiffusionRequest::newFromDictionary(
array( array(
'user' => $this->getRequest()->getUser(),
'repository' => $drequest->getRepository(), 'repository' => $drequest->getRepository(),
'commit' => $commit, 'commit' => $commit,
)); ));

View file

@ -3,6 +3,7 @@
final class DiffusionCommitBranchesController extends DiffusionController { final class DiffusionCommitBranchesController extends DiffusionController {
public function willProcessRequest(array $data) { public function willProcessRequest(array $data) {
$data['user'] = $this->getRequest()->getUser();
$this->diffusionRequest = DiffusionRequest::newFromDictionary($data); $this->diffusionRequest = DiffusionRequest::newFromDictionary($data);
} }

View file

@ -10,6 +10,7 @@ final class DiffusionCommitController extends DiffusionController {
public function willProcessRequest(array $data) { public function willProcessRequest(array $data) {
// This controller doesn't use blob/path stuff, just pass the dictionary // This controller doesn't use blob/path stuff, just pass the dictionary
// in directly instead of using the AphrontRequest parsing mechanism. // in directly instead of using the AphrontRequest parsing mechanism.
$data['user'] = $this->getRequest()->getUser();
$drequest = DiffusionRequest::newFromDictionary($data); $drequest = DiffusionRequest::newFromDictionary($data);
$this->diffusionRequest = $drequest; $this->diffusionRequest = $drequest;
} }

View file

@ -3,6 +3,7 @@
final class DiffusionCommitEditController extends DiffusionController { final class DiffusionCommitEditController extends DiffusionController {
public function willProcessRequest(array $data) { public function willProcessRequest(array $data) {
$data['user'] = $this->getRequest()->getUser();
$this->diffusionRequest = DiffusionRequest::newFromDictionary($data); $this->diffusionRequest = DiffusionRequest::newFromDictionary($data);
} }

View file

@ -3,6 +3,7 @@
final class DiffusionCommitTagsController extends DiffusionController { final class DiffusionCommitTagsController extends DiffusionController {
public function willProcessRequest(array $data) { public function willProcessRequest(array $data) {
$data['user'] = $this->getRequest()->getUser();
$this->diffusionRequest = DiffusionRequest::newFromDictionary($data); $this->diffusionRequest = DiffusionRequest::newFromDictionary($data);
} }

View file

@ -40,6 +40,7 @@ final class DiffusionLintController extends DiffusionController {
$drequests = array(); $drequests = array();
foreach ($branches as $id => $branch) { foreach ($branches as $id => $branch) {
$drequests[$id] = DiffusionRequest::newFromDictionary(array( $drequests[$id] = DiffusionRequest::newFromDictionary(array(
'user' => $user,
'repository' => $repositories[$branch->getRepositoryID()], 'repository' => $repositories[$branch->getRepositoryID()],
'branch' => $branch->getName(), 'branch' => $branch->getName(),
)); ));

View file

@ -27,8 +27,9 @@ final class DiffusionPathCompleteController extends DiffusionController {
$drequest = DiffusionRequest::newFromDictionary( $drequest = DiffusionRequest::newFromDictionary(
array( array(
'repository' => $repository, 'user' => $request->getUser(),
'path' => $query_dir, 'repository' => $repository,
'path' => $query_dir,
)); ));
$this->setDiffusionRequest($drequest); $this->setDiffusionRequest($drequest);

View file

@ -22,8 +22,9 @@ final class DiffusionPathValidateController extends DiffusionController {
$drequest = DiffusionRequest::newFromDictionary( $drequest = DiffusionRequest::newFromDictionary(
array( array(
'repository' => $repository, 'user' => $request->getUser(),
'path' => $path, 'repository' => $repository,
'path' => $path,
)); ));
$this->setDiffusionRequest($drequest); $this->setDiffusionRequest($drequest);

View file

@ -0,0 +1,21 @@
<?php
final class DiffusionExpandCommitQueryException extends Exception {
const CODE_UNPARSEABLE = 'unparseable';
const CODE_MISSING = 'missing';
const CODE_INVALID = 'invalid';
private $statusCode;
public function getStatusCode() {
return $this->statusCode;
}
public function __construct($status_code /* ... */) {
$args = func_get_args();
$this->statusCode = $args[0];
$args = array_slice($args, 1);
call_user_func_array(array('parent', '__construct'), $args);
}
}

View file

@ -14,6 +14,16 @@ abstract class DiffusionQuery extends PhabricatorQuery {
$repository = $request->getRepository(); $repository = $request->getRepository();
$obj = self::initQueryObject($base_class, $repository);
$obj->request = $request;
return $obj;
}
final protected static function initQueryObject(
$base_class,
PhabricatorRepository $repository) {
$map = array( $map = array(
PhabricatorRepositoryType::REPOSITORY_TYPE_GIT => 'Git', PhabricatorRepositoryType::REPOSITORY_TYPE_GIT => 'Git',
PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL => 'Mercurial', PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL => 'Mercurial',
@ -27,8 +37,6 @@ abstract class DiffusionQuery extends PhabricatorQuery {
$class = str_replace('Diffusion', 'Diffusion'.$name, $base_class); $class = str_replace('Diffusion', 'Diffusion'.$name, $base_class);
$obj = new $class(); $obj = new $class();
$obj->request = $request;
return $obj; return $obj;
} }

View file

@ -0,0 +1,42 @@
<?php
abstract class DiffusionExpandShortNameQuery extends DiffusionQuery {
private $commit;
private $commitType = 'commit';
private $tagContent;
private $repository;
public function setCommit($commit) {
$this->commit = $commit;
}
public function getCommit() {
return $this->commit;
}
public function setRepository(PhabricatorRepository $repository) {
$this->repository = $repository;
return $this;
}
public function getRepository() {
return $this->repository;
}
final public static function newFromRepository(
PhabricatorRepository $repository) {
$obj = parent::initQueryObject(__CLASS__, $repository);
$obj->setRepository($repository);
return $obj;
}
final public function expand() {
$this->executeQuery();
return array(
'commit' => $this->commit,
'commitType' => $this->commitType,
'tagContent' => $this->tagContent);
}
}

View file

@ -0,0 +1,52 @@
<?php
final class DiffusionGitExpandShortNameQuery
extends DiffusionExpandShortNameQuery {
protected function executeQuery() {
$repository = $this->getRepository();
$commit = $this->getCommit();
$future = $repository->getLocalCommandFuture(
'cat-file --batch');
$future->write($commit);
list($stdout) = $future->resolvex();
list($hash, $type) = explode(' ', $stdout);
if ($type == 'missing') {
throw new DiffusionExpandCommitQueryException(
DiffusionExpandCommitQueryException::CODE_MISSING,
"Bad commit '{$this->commit}'.");
}
switch ($type) {
case 'tag':
$this->commitType = 'tag';
$matches = null;
$ok = preg_match(
'/^object ([a-f0-9]+)$.*?\n\n(.*)$/sm',
$stdout,
$matches);
if (!$ok) {
throw new DiffusionExpandCommitQueryException(
DiffusionExpandCommitQueryException::CODE_UNPARSEABLE,
"Unparseable output from cat-file: {$stdout}");
}
$hash = $matches[1];
$this->tagContent = trim($matches[2]);
break;
case 'commit':
break;
default:
throw new DiffusionExpandCommitQueryException(
DiffusionExpandCommitQueryException::CODE_INVALID,
"The reference '{$this->commit}' does not name a valid ".
'commit or a tag in this repository.');
break;
}
$this->commit = $hash;
}
}

View file

@ -0,0 +1,23 @@
<?php
final class DiffusionMercurialExpandShortNameQuery
extends DiffusionExpandShortNameQuery {
protected function executeQuery() {
$repository = $this->getRepository();
$commit = $this->getCommit();
list($full_hash) = $repository->execxLocalCommand(
'log --template=%s --rev %s',
'{node}',
$commit);
$full_hash = explode("\n", trim($full_hash));
// TODO: Show "multiple matching commits" if count is larger than 1. For
// now, pick the first one.
$this->commit = head($full_hash);
}
}

View file

@ -10,54 +10,11 @@ final class DiffusionGitRequest extends DiffusionRequest {
} }
protected function didInitialize() { protected function didInitialize() {
$repository = $this->getRepository();
$this->validateWorkingCopy($repository->getLocalPath());
if (!$this->commit) { if (!$this->commit) {
return; return;
} }
// Expand short commit names and verify $this->expandCommitName();
$future = $repository->getLocalCommandFuture(
'cat-file --batch');
$future->write($this->commit);
list($stdout) = $future->resolvex();
list($hash, $type) = explode(' ', $stdout);
if ($type == 'missing') {
throw new Exception("Bad commit '{$this->commit}'.");
}
switch ($type) {
case 'tag':
$this->commitType = 'tag';
$matches = null;
$ok = preg_match(
'/^object ([a-f0-9]+)$.*?\n\n(.*)$/sm',
$stdout,
$matches);
if (!$ok) {
throw new Exception(
"Unparseable output from cat-file: {$stdout}");
}
$hash = $matches[1];
$this->tagContent = trim($matches[2]);
break;
case 'commit':
break;
default:
throw new AphrontUsageException(
"Invalid Object Name",
"The reference '{$this->commit}' does not name a valid ".
"commit or a tag in this repository.");
break;
}
$this->commit = $hash;
} }
public function getBranch() { public function getBranch() {

View file

@ -10,10 +10,6 @@ final class DiffusionMercurialRequest extends DiffusionRequest {
} }
protected function didInitialize() { protected function didInitialize() {
$repository = $this->getRepository();
$this->validateWorkingCopy($repository->getLocalPath());
// Expand abbreviated hashes to full hashes so "/rXnnnn" (i.e., fewer than // Expand abbreviated hashes to full hashes so "/rXnnnn" (i.e., fewer than
// 40 characters) works correctly. // 40 characters) works correctly.
if (!$this->commit) { if (!$this->commit) {
@ -24,21 +20,8 @@ final class DiffusionMercurialRequest extends DiffusionRequest {
return; return;
} }
list($full_hash) = $this->repository->execxLocalCommand( $this->expandCommitName();
'log --template=%s --rev %s', }
'{node}',
$this->commit);
$full_hash = explode("\n", trim($full_hash));
// TODO: Show "multiple matching commits" if count is larger than 1. For
// now, pick the first one.
$this->commit = head($full_hash);
return;
}
public function getBranch() { public function getBranch() {
if ($this->branch) { if ($this->branch) {

View file

@ -17,9 +17,9 @@ abstract class DiffusionRequest {
protected $line; protected $line;
protected $symbolicCommit; protected $symbolicCommit;
protected $commit; protected $commit;
protected $branch;
protected $commitType = 'commit'; protected $commitType = 'commit';
protected $tagContent; protected $tagContent;
protected $branch;
protected $lint; protected $lint;
protected $repository; protected $repository;
@ -28,6 +28,9 @@ abstract class DiffusionRequest {
protected $stableCommitName; protected $stableCommitName;
protected $arcanistProjects; protected $arcanistProjects;
private $initFromConduit = true;
private $user;
abstract protected function getSupportsBranches(); abstract protected function getSupportsBranches();
abstract protected function didInitialize(); abstract protected function didInitialize();
@ -91,6 +94,7 @@ abstract class DiffusionRequest {
$use_branches = $object->getSupportsBranches(); $use_branches = $object->getSupportsBranches();
$parsed = self::parseRequestBlob(idx($data, 'dblob'), $use_branches); $parsed = self::parseRequestBlob(idx($data, 'dblob'), $use_branches);
$object->setUser($request->getUser());
$object->initializeFromDictionary($parsed); $object->initializeFromDictionary($parsed);
$object->lint = $request->getStr('lint'); $object->lint = $request->getStr('lint');
return $object; return $object;
@ -167,18 +171,39 @@ abstract class DiffusionRequest {
* @task new * @task new
*/ */
final private function initializeFromDictionary(array $data) { final private function initializeFromDictionary(array $data) {
$this->path = idx($data, 'path'); $this->path = idx($data, 'path');
$this->symbolicCommit = idx($data, 'commit'); $this->symbolicCommit = idx($data, 'commit');
$this->commit = idx($data, 'commit'); $this->commit = idx($data, 'commit');
$this->line = idx($data, 'line'); $this->line = idx($data, 'line');
$this->initFromConduit = idx($data, 'initFromConduit', true);
if ($this->getSupportsBranches()) { if ($this->getSupportsBranches()) {
$this->branch = idx($data, 'branch'); $this->branch = idx($data, 'branch');
} }
if (!$this->getUser()) {
$user = idx($data, 'user');
if (!$user) {
throw new Exception(
'You must provide a PhabricatorUser in the dictionary!');
}
$this->setUser($user);
}
$this->didInitialize(); $this->didInitialize();
} }
final protected function shouldInitFromConduit() {
return $this->initFromConduit;
}
final public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
final public function getUser() {
return $this->user;
}
public function getRepository() { public function getRepository() {
return $this->repository; return $this->repository;
@ -580,4 +605,27 @@ abstract class DiffusionRequest {
"Guide' in the documentation for help setting up repositories."); "Guide' in the documentation for help setting up repositories.");
} }
final protected function expandCommitName() {
if ($this->shouldInitFromConduit()) {
$commit_data = DiffusionQuery::callConduitWithDiffusionRequest(
$this->getUser(),
$this,
'diffusion.expandshortcommitquery',
array(
'commit' => $this->commit
));
} else {
$repository = $this->getRepository();
$this->validateWorkingCopy($repository->getLocalPath());
$query = DiffusionExpandShortNameQuery::newFromRepository(
$repository);
$query->setCommit($this->commit);
$commit_data = $query->expand();
}
$this->commit = $commit_data['commit'];
$this->commitType = $commit_data['commitType'];
$this->tagContent = $commit_data['tagContent'];
}
} }

View file

@ -106,6 +106,7 @@ final class HeraldCommitAdapter extends HeraldObjectAdapter {
private function loadCommitDiff() { private function loadCommitDiff() {
$drequest = DiffusionRequest::newFromDictionary( $drequest = DiffusionRequest::newFromDictionary(
array( array(
'user' => PhabricatorUser::getOmnipotentUser(),
'repository' => $this->repository, 'repository' => $this->repository,
'commit' => $this->commit->getCommitIdentifier(), 'commit' => $this->commit->getCommitIdentifier(),
)); ));

View file

@ -309,6 +309,7 @@ final class PhabricatorOwnersPackage extends PhabricatorOwnersDAO
// build query to validate path // build query to validate path
$drequest = DiffusionRequest::newFromDictionary( $drequest = DiffusionRequest::newFromDictionary(
array( array(
'user' => $this->getActor(),
'repository' => $repository, 'repository' => $repository,
'path' => $path, 'path' => $path,
)); ));

View file

@ -3,6 +3,15 @@
final class ReleephCommitFinder { final class ReleephCommitFinder {
private $releephProject; private $releephProject;
private $user;
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function getUser() {
return $this->user;
}
public function setReleephProject(ReleephProject $rp) { public function setReleephProject(ReleephProject $rp) {
$this->releephProject = $rp; $this->releephProject = $rp;
@ -55,6 +64,7 @@ final class ReleephCommitFinder {
} }
try { try {
$dr_data['user'] = $this->getUser();
$dr = DiffusionRequest::newFromDictionary($dr_data); $dr = DiffusionRequest::newFromDictionary($dr_data);
} catch (Exception $ex) { } catch (Exception $ex) {
$message = "No commit matches {$partial_string}: ".$ex->getMessage(); $message = "No commit matches {$partial_string}: ".$ex->getMessage();

View file

@ -43,6 +43,7 @@ final class ConduitAPI_releeph_request_Method
$requested_commits = array(); $requested_commits = array();
$things = $request->getValue('things'); $things = $request->getValue('things');
$finder = id(new ReleephCommitFinder()) $finder = id(new ReleephCommitFinder())
->setUser($user)
->setReleephProject($releeph_project); ->setReleephProject($releeph_project);
foreach ($things as $thing) { foreach ($things as $thing) {
try { try {

View file

@ -41,6 +41,7 @@ final class ReleephBranchCreateController extends ReleephController {
} else { } else {
try { try {
$finder = id(new ReleephCommitFinder()) $finder = id(new ReleephCommitFinder())
->setUser($request->getUser())
->setReleephProject($releeph_project); ->setReleephProject($releeph_project);
$cut_commit = $finder->fromPartial($cut_point); $cut_commit = $finder->fromPartial($cut_point);
} catch (Exception $e) { } catch (Exception $e) {

View file

@ -71,6 +71,7 @@ final class ReleephRequestEditController extends ReleephController {
} else { } else {
$pr_commit = null; $pr_commit = null;
$finder = id(new ReleephCommitFinder()) $finder = id(new ReleephCommitFinder())
->setUser($user)
->setReleephProject($releeph_project); ->setReleephProject($releeph_project);
try { try {
$pr_commit = $finder->fromPartial($request_identifier); $pr_commit = $finder->fromPartial($request_identifier);
@ -186,7 +187,7 @@ final class ReleephRequestEditController extends ReleephController {
} }
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($request->getUser()); ->setUser($user);
if ($is_edit) { if ($is_edit) {
$form $form

View file

@ -327,8 +327,9 @@ final class DifferentialReleephRequestFieldSpecification
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$change_query = DiffusionPathChangeQuery::newFromDiffusionRequest( $change_query = DiffusionPathChangeQuery::newFromDiffusionRequest(
DiffusionRequest::newFromDictionary(array( DiffusionRequest::newFromDictionary(array(
'repository' => $repo, 'user' => $this->getUser(),
'commit' => $commit->getCommitIdentifier(), 'repository' => $repo,
'commit' => $commit->getCommitIdentifier(),
))); )));
$path_changes = $change_query->loadChanges(); $path_changes = $change_query->loadChanges();
$commit_paths = mpull($path_changes, 'getPath'); $commit_paths = mpull($path_changes, 'getPath');

View file

@ -167,6 +167,7 @@ final class ReleephBranchBoxView extends AphrontView {
"Diffusion \xE2\x86\x97"); "Diffusion \xE2\x86\x97");
} else { } else {
$diffusion_request = DiffusionRequest::newFromDictionary(array( $diffusion_request = DiffusionRequest::newFromDictionary(array(
'user' => $this->getUser(),
'repository' => $repo, 'repository' => $repo,
)); ));
$diffusion_branch_uri = $diffusion_request->generateURI(array( $diffusion_branch_uri = $diffusion_request->generateURI(array(

View file

@ -69,14 +69,18 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
return $this; return $this;
} }
public function getDiffusionBrowseURIForPath($path, public function getDiffusionBrowseURIForPath(
$line = null, PhabricatorUser $user,
$branch = null) { $path,
$line = null,
$branch = null) {
$drequest = DiffusionRequest::newFromDictionary( $drequest = DiffusionRequest::newFromDictionary(
array( array(
'user' => $user,
'repository' => $this, 'repository' => $this,
'path' => $path, 'path' => $path,
'branch' => $branch, 'branch' => $branch,
)); ));
return $drequest->generateURI( return $drequest->generateURI(

View file

@ -39,7 +39,8 @@ final class PhabricatorRepositorySymbol extends PhabricatorRepositoryDAO {
$request = DiffusionRequest::newFromDictionary( $request = DiffusionRequest::newFromDictionary(
array( array(
'repository' => $this->getRepository(), 'user' => PhabricatorUser::getOmnipotentUser(),
'repository' => $this->getRepository(),
)); ));
return $request->generateURI( return $request->generateURI(
array( array(

View file

@ -363,8 +363,10 @@ final class PhabricatorRepositoryCommitHeraldWorker
$drequest = DiffusionRequest::newFromDictionary( $drequest = DiffusionRequest::newFromDictionary(
array( array(
'repository' => $repository, 'user' => PhabricatorUser::getOmnipotentUser(),
'commit' => $commit->getCommitIdentifier(), 'initFromConduit' => false,
'repository' => $repository,
'commit' => $commit->getCommitIdentifier(),
)); ));
$raw_query = DiffusionRawDiffQuery::newFromDiffusionRequest($drequest); $raw_query = DiffusionRawDiffQuery::newFromDiffusionRequest($drequest);

View file

@ -85,8 +85,10 @@ final class PhabricatorOwnersPackagePathValidator {
$repository = $repository =
id(new PhabricatorRepository())->load($commit->getRepositoryID()); id(new PhabricatorRepository())->load($commit->getRepositoryID());
$data = array( $data = array(
'repository'=>$repository, 'user' => PhabricatorUser::getOmnipotentUser(),
'commit'=>$commit->getCommitIdentifier() 'initFromConduit' => false,
'repository' => $repository,
'commit' => $commit->getCommitIdentifier()
); );
$drequest = DiffusionRequest::newFromDictionary($data); $drequest = DiffusionRequest::newFromDictionary($data);
$change_query = $change_query =

View file

@ -230,6 +230,8 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
$actor_phid) { $actor_phid) {
$drequest = DiffusionRequest::newFromDictionary(array( $drequest = DiffusionRequest::newFromDictionary(array(
'user' => PhabricatorUser::getOmnipotentUser(),
'initFromConduit' => false,
'repository' => $this->repository, 'repository' => $this->repository,
'commit' => $this->commit->getCommitIdentifier(), 'commit' => $this->commit->getCommitIdentifier(),
)); ));
@ -333,6 +335,8 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
return $vs_diff; return $vs_diff;
} }
$drequest = DiffusionRequest::newFromDictionary(array( $drequest = DiffusionRequest::newFromDictionary(array(
'user' => PhabricatorUser::getOmnipotentUser(),
'initFromConduit' => false,
'repository' => $this->repository, 'repository' => $this->repository,
'commit' => $this->commit->getCommitIdentifier(), 'commit' => $this->commit->getCommitIdentifier(),
'path' => $path, 'path' => $path,