Skip to content
Browse files

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
  • Loading branch information...
1 parent b43eb5a commit 97820b2ff75851d3fde83eae382ce65769db8e2f @epriestley epriestley committed Jan 24, 2012
View
6 src/applications/conduit/method/differential/query/ConduitAPI_differential_query_Method.php
@@ -58,6 +58,7 @@ public function defineParamTypes() {
'phids' => 'optional list<phid>',
'subscribers' => 'optional list<phid>',
'responsibleUsers' => 'optional list<phid>',
+ 'branches' => 'optional list<string>',
);
}
@@ -84,6 +85,7 @@ protected function execute(ConduitAPIRequest $request) {
$phids = $request->getValue('phids');
$subscribers = $request->getValue('subscribers');
$responsible_users = $request->getValue('responsibleUsers');
+ $branches = $request->getValue('branches');
$query = new DifferentialRevisionQuery();
if ($authors) {
@@ -143,6 +145,9 @@ protected function execute(ConduitAPIRequest $request) {
if ($subscribers) {
$query->withSubscribers($subscribers);
}
+ if ($branches) {
+ $query->withBranches($branches);
+ }
$query->needRelationships(true);
$query->needCommitPHIDs(true);
@@ -172,6 +177,7 @@ protected function execute(ConduitAPIRequest $request) {
ArcanistDifferentialRevisionStatus::getNameForRevisionStatus(
$revision->getStatus()),
'sourcePath' => $diff->getSourcePath(),
+ 'branch' => $diff->getBranch(),
'summary' => $revision->getSummary(),
'testPlan' => $revision->getTestPlan(),
'lineCount' => $revision->getLineCount(),
View
50 src/applications/differential/query/revision/DifferentialRevisionQuery.php
@@ -47,6 +47,7 @@
private $phids = array();
private $subscribers = array();
private $responsibles = array();
+ private $branches = array();
private $order = 'order-modified';
const ORDER_MODIFIED = 'order-modified';
@@ -162,6 +163,19 @@ public function withStatus($status_constant) {
/**
+ * 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.
*
* @param array List of revision ids
@@ -339,13 +353,45 @@ public function execute() {
$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);
}
- if ($this->needActiveDiffs) {
+ if ($need_active) {
$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;

0 comments on commit 97820b2

Please sign in to comment.
Something went wrong with that request. Please try again.