1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 05:12:41 +01:00

Add branch queries to differential.query

Summary: This enables some improvements in D1478. Allow revisons to be queried
by the branch which they appear on.

Test Plan: Queried revisions by branch. Ran "arc which" branch queries in SVN
and Mercurial.

Reviewers: btrahan, cpiro, jungejason

Reviewed By: btrahan

CC: aran, epriestley

Maniphest Tasks: T787

Differential Revision: https://secure.phabricator.com/D1479
This commit is contained in:
epriestley 2012-01-24 08:31:45 -08:00
parent b43eb5aa7c
commit 97820b2ff7
2 changed files with 54 additions and 2 deletions

View file

@ -58,6 +58,7 @@ class ConduitAPI_differential_query_Method extends ConduitAPIMethod {
'phids' => 'optional list<phid>', 'phids' => 'optional list<phid>',
'subscribers' => 'optional list<phid>', 'subscribers' => 'optional list<phid>',
'responsibleUsers' => 'optional list<phid>', 'responsibleUsers' => 'optional list<phid>',
'branches' => 'optional list<string>',
); );
} }
@ -84,6 +85,7 @@ class ConduitAPI_differential_query_Method extends ConduitAPIMethod {
$phids = $request->getValue('phids'); $phids = $request->getValue('phids');
$subscribers = $request->getValue('subscribers'); $subscribers = $request->getValue('subscribers');
$responsible_users = $request->getValue('responsibleUsers'); $responsible_users = $request->getValue('responsibleUsers');
$branches = $request->getValue('branches');
$query = new DifferentialRevisionQuery(); $query = new DifferentialRevisionQuery();
if ($authors) { if ($authors) {
@ -143,6 +145,9 @@ class ConduitAPI_differential_query_Method extends ConduitAPIMethod {
if ($subscribers) { if ($subscribers) {
$query->withSubscribers($subscribers); $query->withSubscribers($subscribers);
} }
if ($branches) {
$query->withBranches($branches);
}
$query->needRelationships(true); $query->needRelationships(true);
$query->needCommitPHIDs(true); $query->needCommitPHIDs(true);
@ -172,6 +177,7 @@ class ConduitAPI_differential_query_Method extends ConduitAPIMethod {
ArcanistDifferentialRevisionStatus::getNameForRevisionStatus( ArcanistDifferentialRevisionStatus::getNameForRevisionStatus(
$revision->getStatus()), $revision->getStatus()),
'sourcePath' => $diff->getSourcePath(), 'sourcePath' => $diff->getSourcePath(),
'branch' => $diff->getBranch(),
'summary' => $revision->getSummary(), 'summary' => $revision->getSummary(),
'testPlan' => $revision->getTestPlan(), 'testPlan' => $revision->getTestPlan(),
'lineCount' => $revision->getLineCount(), 'lineCount' => $revision->getLineCount(),

View file

@ -47,6 +47,7 @@ final class DifferentialRevisionQuery {
private $phids = array(); private $phids = array();
private $subscribers = array(); private $subscribers = array();
private $responsibles = array(); private $responsibles = array();
private $branches = array();
private $order = 'order-modified'; private $order = 'order-modified';
const ORDER_MODIFIED = 'order-modified'; const ORDER_MODIFIED = 'order-modified';
@ -161,6 +162,19 @@ final class DifferentialRevisionQuery {
} }
/**
* Filter results to revisions on given branches.
*
* @param list List of branch names.
* @return this
* @task config
*/
public function withBranches(array $branches) {
$this->branches = $branches;
return $this;
}
/** /**
* Filter results to only return revisions whose ids are in the given set. * Filter results to only return revisions whose ids are in the given set.
* *
@ -339,13 +353,45 @@ final class DifferentialRevisionQuery {
$this->loadCommitPHIDs($conn_r, $revisions); $this->loadCommitPHIDs($conn_r, $revisions);
} }
if ($this->needActiveDiffs || $this->needDiffIDs) { $need_active = $this->needActiveDiffs ||
$this->branches;
$need_ids = $need_active ||
$this->needDiffIDs;
if ($need_ids) {
$this->loadDiffIDs($conn_r, $revisions); $this->loadDiffIDs($conn_r, $revisions);
} }
if ($this->needActiveDiffs) { if ($need_active) {
$this->loadActiveDiffs($conn_r, $revisions); $this->loadActiveDiffs($conn_r, $revisions);
} }
if ($this->branches) {
// TODO: We could filter this in SQL instead and might get better
// performance in some cases.
$branch_map = array_fill_keys($this->branches, true);
foreach ($revisions as $key => $revision) {
$diff = $revision->getActiveDiff();
if (!$diff) {
unset($revisions[$key]);
continue;
}
// TODO: Old arc uploaded the wrong branch name for Mercurial (i.e.,
// with a trailing "\n"). Once the arc version gets bumped, do a
// migration and remove this.
$branch = trim($diff->getBranch());
if (!$diff || empty($branch_map[$branch])) {
unset($revisions[$key]);
continue;
}
}
}
} }
return $revisions; return $revisions;