Page MenuHomePhabricator

D11581.diff
No OneTemporary

D11581.diff

diff --git a/src/applications/differential/query/DifferentialRevisionQuery.php b/src/applications/differential/query/DifferentialRevisionQuery.php
--- a/src/applications/differential/query/DifferentialRevisionQuery.php
+++ b/src/applications/differential/query/DifferentialRevisionQuery.php
@@ -32,6 +32,7 @@
private $reviewers = array();
private $revIDs = array();
private $commitHashes = array();
+ private $commitPHIDs = array();
private $phids = array();
private $responsibles = array();
private $branches = array();
@@ -154,6 +155,20 @@
}
/**
+ * Filter results to revisions that have one of the provided PHIDs as
+ * commits. Calling this function will clear anything set by previous calls
+ * to @{method:withCommitPHIDs}.
+ *
+ * @param array List of PHIDs of commits
+ * @return this
+ * @task config
+ */
+ public function withCommitPHIDs(array $commit_phids) {
+ $this->commitPHIDs = $commit_phids;
+ return $this;
+ }
+
+ /**
* Filter results to revisions with a given status. Provide a class constant,
* such as `DifferentialRevisionQuery::STATUS_OPEN`.
*
@@ -653,6 +668,13 @@
$this->draftAuthors);
}
+ if ($this->commitPHIDs) {
+ $joins[] = qsprintf(
+ $conn_r,
+ 'JOIN %T commits ON commits.revisionID = r.id',
+ DifferentialRevision::TABLE_COMMIT);
+ }
+
$joins = implode(' ', $joins);
return $joins;
@@ -714,6 +736,13 @@
$where[] = $hash_clauses;
}
+ if ($this->commitPHIDs) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'commits.commitPHID IN (%Ls)',
+ $this->commitPHIDs);
+ }
+
if ($this->phids) {
$where[] = qsprintf(
$conn_r,
diff --git a/src/applications/diffusion/conduit/DiffusionGetCommitsConduitAPIMethod.php b/src/applications/diffusion/conduit/DiffusionGetCommitsConduitAPIMethod.php
--- a/src/applications/diffusion/conduit/DiffusionGetCommitsConduitAPIMethod.php
+++ b/src/applications/diffusion/conduit/DiffusionGetCommitsConduitAPIMethod.php
@@ -135,7 +135,7 @@
}
$commits = $this->addRepositoryCommitDataInformation($commits);
- $commits = $this->addDifferentialInformation($commits);
+ $commits = $this->addDifferentialInformation($commits, $request);
$commits = $this->addManiphestInformation($commits);
foreach ($commits as $name => $commit) {
@@ -238,31 +238,29 @@
/**
* Enhance the commit list with Differential information.
*/
- private function addDifferentialInformation(array $commits) {
+ private function addDifferentialInformation(
+ array $commits,
+ ConduitAPIRequest $request) {
+
$commit_phids = ipull($commits, 'commitPHID');
- // TODO: (T603) This should be policy checked, either by moving to
- // DifferentialRevisionQuery or by doing a followup query to make sure
- // the matched objects are visible.
-
- $rev_conn_r = id(new DifferentialRevision())->establishConnection('r');
- $revs = queryfx_all(
- $rev_conn_r,
- 'SELECT r.id id, r.phid phid, c.commitPHID commitPHID FROM %T r JOIN %T c
- ON r.id = c.revisionID
- WHERE c.commitPHID in (%Ls)',
- id(new DifferentialRevision())->getTableName(),
- DifferentialRevision::TABLE_COMMIT,
- $commit_phids);
-
- $revs = ipull($revs, null, 'commitPHID');
- foreach ($commits as $name => $commit) {
- if (isset($revs[$commit['commitPHID']])) {
- $rev = $revs[$commit['commitPHID']];
- $commits[$name] += array(
- 'differentialRevisionID' => 'D'.$rev['id'],
- 'differentialRevisionPHID' => $rev['phid'],
- );
+ $revisions = id(new DifferentialRevisionQuery())
+ ->setViewer($request->getUser())
+ ->withCommitPHIDs($commit_phids)
+ ->needCommitPHIDs(true)
+ ->execute();
+ $rev_phid_commit_phids_map = mpull($revisions, 'getCommitPHIDs', 'getPHID');
+ $revisions = mpull($revisions, null, 'getPHID');
+ foreach ($rev_phid_commit_phids_map as $rev_phid => $commit_phids) {
+ foreach ($commits as $name => $commit) {
+ $commit_phid = $commit['commitPHID'];
+ if (in_array($commit_phid, $commit_phids)) {
+ $revision = $revisions[$rev_phid];
+ $commits[$name] += array(
+ 'differentialRevisionID' => 'D'.$revision->getID(),
+ 'differentialRevisionPHID' => $revision->getPHID(),
+ );
+ }
}
}

File Metadata

Mime Type
text/plain
Expires
Oct 17 2024, 7:50 PM (4 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6716878
Default Alt Text
D11581.diff (4 KB)

Event Timeline