mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 16:22:43 +01:00
Add "internal.commit.search" to replace the cache bypass mode of "diffusion.querycommits"
Summary: Ref T13552. Commit parsers currently invoke a special mode of "diffusion.querycommits", which is an older frozen method. The replacement, "diffusion.commit.search", is not really appropriate for low-level access. This mode of having a single method which operates in "cache" or "non-cache" modes also ends up in a lot of unnecessary field shuffling. Provide "internal.commit.search" as a modern equivalent that returns a "DiffusionCommitRef"-compatible structure. Test Plan: Executed "internal.commit.search", got sensible low-level commit results. Maniphest Tasks: T13552 Differential Revision: https://secure.phabricator.com/D21443
This commit is contained in:
parent
a745055813
commit
a9506097ea
6 changed files with 202 additions and 15 deletions
|
@ -873,6 +873,8 @@ phutil_register_library_map(array(
|
|||
'DiffusionIdentityViewController' => 'applications/diffusion/controller/DiffusionIdentityViewController.php',
|
||||
'DiffusionInlineCommentController' => 'applications/diffusion/controller/DiffusionInlineCommentController.php',
|
||||
'DiffusionInternalAncestorsConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionInternalAncestorsConduitAPIMethod.php',
|
||||
'DiffusionInternalCommitSearchConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionInternalCommitSearchConduitAPIMethod.php',
|
||||
'DiffusionInternalCommitSearchEngine' => 'applications/audit/query/DiffusionInternalCommitSearchEngine.php',
|
||||
'DiffusionInternalGitRawDiffQueryConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionInternalGitRawDiffQueryConduitAPIMethod.php',
|
||||
'DiffusionLastModifiedController' => 'applications/diffusion/controller/DiffusionLastModifiedController.php',
|
||||
'DiffusionLastModifiedQueryConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionLastModifiedQueryConduitAPIMethod.php',
|
||||
|
@ -6976,6 +6978,8 @@ phutil_register_library_map(array(
|
|||
'DiffusionIdentityViewController' => 'DiffusionController',
|
||||
'DiffusionInlineCommentController' => 'PhabricatorInlineCommentController',
|
||||
'DiffusionInternalAncestorsConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod',
|
||||
'DiffusionInternalCommitSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
|
||||
'DiffusionInternalCommitSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'DiffusionInternalGitRawDiffQueryConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod',
|
||||
'DiffusionLastModifiedController' => 'DiffusionController',
|
||||
'DiffusionLastModifiedQueryConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod',
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
final class DiffusionInternalCommitSearchEngine
|
||||
extends PhabricatorApplicationSearchEngine {
|
||||
|
||||
public function getResultTypeDescription() {
|
||||
return pht('Diffusion Raw Commits');
|
||||
}
|
||||
|
||||
public function getApplicationClassName() {
|
||||
return 'PhabricatorDiffusionApplication';
|
||||
}
|
||||
|
||||
public function newQuery() {
|
||||
return new DiffusionCommitQuery();
|
||||
}
|
||||
|
||||
protected function buildQueryFromParameters(array $map) {
|
||||
$query = $this->newQuery();
|
||||
|
||||
if ($map['repositoryPHIDs']) {
|
||||
$query->withRepositoryPHIDs($map['repositoryPHIDs']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function buildCustomSearchFields() {
|
||||
return array(
|
||||
id(new PhabricatorSearchDatasourceField())
|
||||
->setLabel(pht('Repositories'))
|
||||
->setKey('repositoryPHIDs')
|
||||
->setDatasource(new DiffusionRepositoryFunctionDatasource())
|
||||
->setDescription(pht('Find commits in particular repositories.')),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function renderResultList(
|
||||
array $commits,
|
||||
PhabricatorSavedQuery $query,
|
||||
array $handles) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function getObjectWireFieldsForConduit(
|
||||
$object,
|
||||
array $field_extensions,
|
||||
array $extension_data) {
|
||||
|
||||
$commit = $object;
|
||||
$viewer = $this->requireViewer();
|
||||
|
||||
$repository = $commit->getRepository();
|
||||
$identifier = $commit->getCommitIdentifier();
|
||||
|
||||
id(new DiffusionRepositoryClusterEngine())
|
||||
->setViewer($viewer)
|
||||
->setRepository($repository)
|
||||
->synchronizeWorkingCopyBeforeRead();
|
||||
|
||||
$ref = id(new DiffusionLowLevelCommitQuery())
|
||||
->setRepository($repository)
|
||||
->withIdentifier($identifier)
|
||||
->execute();
|
||||
|
||||
return array(
|
||||
'ref' => $ref->newDictionary(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
final class DiffusionInternalCommitSearchConduitAPIMethod
|
||||
extends PhabricatorSearchEngineAPIMethod {
|
||||
|
||||
public function getAPIMethodName() {
|
||||
return 'internal.commit.search';
|
||||
}
|
||||
|
||||
public function newSearchEngine() {
|
||||
return new DiffusionInternalCommitSearchEngine();
|
||||
}
|
||||
|
||||
public function getMethodSummary() {
|
||||
return pht('Read raw information about commits.');
|
||||
}
|
||||
|
||||
protected function newConduitCallProxyClient(ConduitAPIRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
|
||||
$constraints = $request->getValue('constraints');
|
||||
if (is_array($constraints)) {
|
||||
$repository_phids = idx($constraints, 'repositoryPHIDs');
|
||||
} else {
|
||||
$repository_phids = array();
|
||||
}
|
||||
|
||||
$repository_phid = null;
|
||||
if (is_array($repository_phids)) {
|
||||
if (phutil_is_natural_list($repository_phids)) {
|
||||
if (count($repository_phids) === 1) {
|
||||
$value = head($repository_phids);
|
||||
if (is_string($value)) {
|
||||
$repository_phid = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($repository_phid === null) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'This internal method must be invoked with a "repositoryPHIDs" '.
|
||||
'constraint with exactly one value.'));
|
||||
}
|
||||
|
||||
$repository = id(new PhabricatorRepositoryQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($repository_phid))
|
||||
->executeOne();
|
||||
if (!$repository) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return $repository->newConduitClientForRequest($request);
|
||||
}
|
||||
|
||||
}
|
|
@ -34,4 +34,21 @@ final class DiffusionCommitHash extends Phobject {
|
|||
}
|
||||
return $hash_objects;
|
||||
}
|
||||
|
||||
public static function newFromDictionary(array $map) {
|
||||
$hash_type = idx($map, 'type');
|
||||
$hash_value = idx($map, 'value');
|
||||
|
||||
return id(new self())
|
||||
->setHashType($hash_type)
|
||||
->setHashValue($hash_value);
|
||||
}
|
||||
|
||||
public function newDictionary() {
|
||||
return array(
|
||||
'type' => $this->hashType,
|
||||
'value' => $this->hashValue,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,28 +10,52 @@ final class DiffusionCommitRef extends Phobject {
|
|||
private $committerEmail;
|
||||
private $hashes = array();
|
||||
|
||||
public static function newFromConduitResult(array $result) {
|
||||
$ref = id(new DiffusionCommitRef())
|
||||
->setAuthorEpoch(idx($result, 'authorEpoch'))
|
||||
->setCommitterEmail(idx($result, 'committerEmail'))
|
||||
->setCommitterName(idx($result, 'committerName'))
|
||||
->setAuthorEmail(idx($result, 'authorEmail'))
|
||||
->setAuthorName(idx($result, 'authorName'))
|
||||
->setMessage(idx($result, 'message'));
|
||||
public function newDictionary() {
|
||||
$hashes = $this->getHashes();
|
||||
$hashes = mpull($hashes, 'newDictionary');
|
||||
$hashes = array_values($hashes);
|
||||
|
||||
$hashes = array();
|
||||
foreach (idx($result, 'hashes', array()) as $hash_result) {
|
||||
$hashes[] = id(new DiffusionCommitHash())
|
||||
->setHashType(idx($hash_result, 'type'))
|
||||
->setHashValue(idx($hash_result, 'value'));
|
||||
return array(
|
||||
'authorEpoch' => $this->authorEpoch,
|
||||
'authorName' => $this->authorName,
|
||||
'authorEmail' => $this->authorEmail,
|
||||
'committerName' => $this->committerName,
|
||||
'committerEmail' => $this->committerEmail,
|
||||
'message' => $this->message,
|
||||
'hashes' => $hashes,
|
||||
);
|
||||
}
|
||||
|
||||
$ref->setHashes($hashes);
|
||||
public static function newFromDictionary(array $map) {
|
||||
$hashes = idx($map, 'hashes', array());
|
||||
foreach ($hashes as $key => $hash_map) {
|
||||
$hashes[$key] = DiffusionCommitHash::newFromDictionary($hash_map);
|
||||
}
|
||||
$hashes = array_values($hashes);
|
||||
|
||||
return $ref;
|
||||
$author_epoch = idx($map, 'authorEpoch');
|
||||
$author_name = idx($map, 'authorName');
|
||||
$author_email = idx($map, 'authorEmail');
|
||||
$committer_name = idx($map, 'committerName');
|
||||
$committer_email = idx($map, 'committerEmail');
|
||||
$message = idx($map, 'message');
|
||||
|
||||
return id(new self())
|
||||
->setAuthorEpoch($author_epoch)
|
||||
->setAuthorName($author_name)
|
||||
->setAuthorEmail($author_email)
|
||||
->setCommitterName($committer_name)
|
||||
->setCommitterEmail($committer_email)
|
||||
->setMessage($message)
|
||||
->setHashes($hashes);
|
||||
}
|
||||
|
||||
public static function newFromConduitResult(array $result) {
|
||||
return self::newFromDictionary($result);
|
||||
}
|
||||
|
||||
public function setHashes(array $hashes) {
|
||||
assert_instances_of($hashes, 'DiffusionCommitHash');
|
||||
$this->hashes = $hashes;
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -92,4 +92,13 @@ final class PhabricatorRepositoryCommitData extends PhabricatorRepositoryDAO {
|
|||
return array_values($holds);
|
||||
}
|
||||
|
||||
public function setCommitRef(DiffusionCommitRef $ref) {
|
||||
$this->setCommitDetail('commitRef', $ref->newDictionary());
|
||||
}
|
||||
|
||||
public function newCommitRef() {
|
||||
$map = $this->getCommitDetail('commitRef', array());
|
||||
return DiffusionCommitRef::neWFromDictionary($map);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue