From c0d48d0b2db97211cedc1fc5dee695f0b5fbc9de Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 26 Jun 2012 09:07:52 -0700 Subject: [PATCH] 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 --- .../ConduitAPI_differential_query_Method.php | 2 + .../query/DifferentialRevisionQuery.php | 41 +++++++++++++++++++ .../storage/DifferentialRevision.php | 14 +++++++ 3 files changed, 57 insertions(+) diff --git a/src/applications/conduit/method/differential/ConduitAPI_differential_query_Method.php b/src/applications/conduit/method/differential/ConduitAPI_differential_query_Method.php index 5ff4d52c40..83097017be 100644 --- a/src/applications/conduit/method/differential/ConduitAPI_differential_query_Method.php +++ b/src/applications/conduit/method/differential/ConduitAPI_differential_query_Method.php @@ -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 diff --git a/src/applications/differential/query/DifferentialRevisionQuery.php b/src/applications/differential/query/DifferentialRevisionQuery.php index 12a8978f90..17a7cf93c7 100644 --- a/src/applications/differential/query/DifferentialRevisionQuery.php +++ b/src/applications/differential/query/DifferentialRevisionQuery.php @@ -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(); diff --git a/src/applications/differential/storage/DifferentialRevision.php b/src/applications/differential/storage/DifferentialRevision.php index 6ef71276be..7e39fed499 100644 --- a/src/applications/differential/storage/DifferentialRevision.php +++ b/src/applications/differential/storage/DifferentialRevision.php @@ -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; + } + }