1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 16:52:41 +01:00

Return attached hashes from differential.query

Summary: See T693. To do "arc branch" performantly in immutable history repositories, we need to be able to do a single query to identify revisions related by hash. Return hash information to enable this.

Test Plan: Ran `differential.query`.

Reviewers: btrahan, vrana

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T693

Differential Revision: https://secure.phabricator.com/D2859
This commit is contained in:
epriestley 2012-06-26 09:07:52 -07:00
parent ee6c6943b3
commit c0d48d0b2d
3 changed files with 57 additions and 0 deletions

View file

@ -200,6 +200,7 @@ final class ConduitAPI_differential_query_Method
$query->needCommitPHIDs(true);
$query->needDiffIDs(true);
$query->needActiveDiffs(true);
$query->needHashes(true);
$revisions = $query->execute();
@ -231,6 +232,7 @@ final class ConduitAPI_differential_query_Method
'commits' => $revision->getCommitPHIDs(),
'reviewers' => array_values($revision->getReviewers()),
'ccs' => array_values($revision->getCCPHIDs()),
'hashes' => $revision->getHashes(),
);
// TODO: This is a hacky way to put permissions on this field until we

View file

@ -73,6 +73,7 @@ final class DifferentialRevisionQuery {
private $needActiveDiffs = false;
private $needDiffIDs = false;
private $needCommitPHIDs = false;
private $needHashes = false;
/* -( Query Configuration )------------------------------------------------ */
@ -353,6 +354,20 @@ final class DifferentialRevisionQuery {
}
/**
* Set whether or not the query should load associated commit hashes for each
* revision.
*
* @param bool True to load and attach commit hashes.
* @return this
* @task config
*/
public function needHashes($need_hashes) {
$this->needHashes = $need_hashes;
return $this;
}
/* -( Query Execution )---------------------------------------------------- */
@ -395,6 +410,10 @@ final class DifferentialRevisionQuery {
if ($need_active) {
$this->loadActiveDiffs($conn_r, $revisions);
}
if ($this->needHashes) {
$this->loadHashes($conn_r, $revisions);
}
}
return $revisions;
@ -837,6 +856,28 @@ final class DifferentialRevisionQuery {
}
}
private function loadHashes(
AphrontDatabaseConnection $conn_r,
array $revisions) {
assert_instances_of($revisions, 'DifferentialRevision');
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T WHERE revisionID IN (%Ld)',
'differential_revisionhash',
mpull($revisions, 'getID'));
$data = igroup($data, 'revisionID');
foreach ($revisions as $revision) {
$hashes = idx($data, $revision->getID(), array());
$list = array();
foreach ($hashes as $hash) {
$list[] = array($hash['type'], $hash['hash']);
}
$revision->attachHashes($list);
}
}
public static function splitResponsible(array $revisions, $user_phid) {
$active = array();
$waiting = array();

View file

@ -43,6 +43,7 @@ final class DifferentialRevision extends DifferentialDAO {
private $commits;
private $activeDiff = false;
private $diffIDs;
private $hashes;
const RELATIONSHIP_TABLE = 'differential_relationship';
@ -308,4 +309,17 @@ final class DifferentialRevision extends DifferentialDAO {
return $reviewer;
}
public function getHashes() {
if ($this->hashes === null) {
throw new Exception("Call attachHashes() before getHashes()!");
}
return $this->hashes;
}
public function attachHashes(array $hashes) {
$this->hashes = $hashes;
return $this;
}
}