2013-02-27 17:04:54 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DiffusionCommitQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
2013-05-17 12:51:33 +02:00
|
|
|
private $ids;
|
2013-02-27 19:54:39 +01:00
|
|
|
private $phids;
|
2014-04-27 18:43:05 +02:00
|
|
|
private $authorPHIDs;
|
2013-05-07 03:05:33 +02:00
|
|
|
private $defaultRepository;
|
2014-04-27 18:43:05 +02:00
|
|
|
private $identifiers;
|
2013-10-30 21:06:28 +01:00
|
|
|
private $repositoryIDs;
|
2014-08-14 22:04:38 +02:00
|
|
|
private $repositoryPHIDs;
|
2014-04-27 18:43:05 +02:00
|
|
|
private $identifierMap;
|
2017-01-12 17:49:36 +01:00
|
|
|
private $responsiblePHIDs;
|
|
|
|
private $statuses;
|
2017-01-30 19:39:35 +01:00
|
|
|
private $packagePHIDs;
|
2014-04-27 18:43:05 +02:00
|
|
|
|
|
|
|
private $needAuditRequests;
|
|
|
|
private $auditIDs;
|
|
|
|
private $auditorPHIDs;
|
2015-06-20 14:25:44 +02:00
|
|
|
private $epochMin;
|
|
|
|
private $epochMax;
|
|
|
|
private $importing;
|
2014-07-23 02:03:09 +02:00
|
|
|
|
2013-10-30 21:06:28 +01:00
|
|
|
private $needCommitData;
|
2017-01-14 18:22:51 +01:00
|
|
|
private $needDrafts;
|
2013-02-27 17:04:54 +01:00
|
|
|
|
2014-04-27 18:43:05 +02:00
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withAuthorPHIDs(array $phids) {
|
|
|
|
$this->authorPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-02-27 17:04:54 +01:00
|
|
|
/**
|
|
|
|
* Load commits by partial or full identifiers, e.g. "rXab82393", "rX1234",
|
|
|
|
* or "a9caf12". When an identifier matches multiple commits, they will all
|
|
|
|
* be returned; callers should be prepared to deal with more results than
|
|
|
|
* they queried for.
|
|
|
|
*/
|
|
|
|
public function withIdentifiers(array $identifiers) {
|
2016-01-07 00:34:05 +01:00
|
|
|
// Some workflows (like blame lookups) can pass in large numbers of
|
|
|
|
// duplicate identifiers. We only care about unique identifiers, so
|
|
|
|
// get rid of duplicates immediately.
|
|
|
|
$identifiers = array_fuse($identifiers);
|
|
|
|
|
2013-02-27 17:04:54 +01:00
|
|
|
$this->identifiers = $identifiers;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-04-27 18:43:05 +02:00
|
|
|
/**
|
|
|
|
* Look up commits in a specific repository. This is a shorthand for calling
|
|
|
|
* @{method:withDefaultRepository} and @{method:withRepositoryIDs}.
|
|
|
|
*/
|
|
|
|
public function withRepository(PhabricatorRepository $repository) {
|
|
|
|
$this->withDefaultRepository($repository);
|
|
|
|
$this->withRepositoryIDs(array($repository->getID()));
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-08-14 21:40:47 +02:00
|
|
|
/**
|
|
|
|
* Look up commits in a specific repository. Prefer
|
|
|
|
* @{method:withRepositoryIDs}; the underyling table is keyed by ID such
|
|
|
|
* that this method requires a separate initial query to map PHID to ID.
|
|
|
|
*/
|
|
|
|
public function withRepositoryPHIDs(array $phids) {
|
2014-08-14 22:04:38 +02:00
|
|
|
$this->repositoryPHIDs = $phids;
|
2015-10-29 00:25:41 +01:00
|
|
|
return $this;
|
2014-08-14 21:40:47 +02:00
|
|
|
}
|
|
|
|
|
2013-05-07 03:05:33 +02:00
|
|
|
/**
|
|
|
|
* If a default repository is provided, ambiguous commit identifiers will
|
|
|
|
* be assumed to belong to the default repository.
|
|
|
|
*
|
|
|
|
* For example, "r123" appearing in a commit message in repository X is
|
|
|
|
* likely to be unambiguously "rX123". Normally the reference would be
|
|
|
|
* considered ambiguous, but if you provide a default repository it will
|
|
|
|
* be correctly resolved.
|
|
|
|
*/
|
|
|
|
public function withDefaultRepository(PhabricatorRepository $repository) {
|
|
|
|
$this->defaultRepository = $repository;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-10-30 21:06:28 +01:00
|
|
|
public function withRepositoryIDs(array $repository_ids) {
|
|
|
|
$this->repositoryIDs = $repository_ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-04-27 18:43:05 +02:00
|
|
|
public function needCommitData($need) {
|
|
|
|
$this->needCommitData = $need;
|
2013-05-17 12:51:33 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-01-14 18:22:51 +01:00
|
|
|
public function needDrafts($need) {
|
|
|
|
$this->needDrafts = $need;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-04-27 18:43:05 +02:00
|
|
|
public function needAuditRequests($need) {
|
|
|
|
$this->needAuditRequests = $need;
|
2013-02-27 19:54:39 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-04-27 18:43:05 +02:00
|
|
|
public function withAuditIDs(array $ids) {
|
|
|
|
$this->auditIDs = $ids;
|
2013-11-07 21:10:43 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-04-27 18:43:05 +02:00
|
|
|
public function withAuditorPHIDs(array $auditor_phids) {
|
|
|
|
$this->auditorPHIDs = $auditor_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-01-12 17:49:36 +01:00
|
|
|
public function withResponsiblePHIDs(array $responsible_phids) {
|
|
|
|
$this->responsiblePHIDs = $responsible_phids;
|
2014-04-27 18:43:05 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-01-30 19:39:35 +01:00
|
|
|
public function withPackagePHIDs(array $package_phids) {
|
|
|
|
$this->packagePHIDs = $package_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-01-12 17:49:36 +01:00
|
|
|
public function withStatuses(array $statuses) {
|
|
|
|
$this->statuses = $statuses;
|
2013-10-30 21:06:28 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-06-20 14:25:44 +02:00
|
|
|
public function withEpochRange($min, $max) {
|
|
|
|
$this->epochMin = $min;
|
|
|
|
$this->epochMax = $max;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withImporting($importing) {
|
|
|
|
$this->importing = $importing;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-07-21 19:57:07 +02:00
|
|
|
public function getIdentifierMap() {
|
|
|
|
if ($this->identifierMap === null) {
|
|
|
|
throw new Exception(
|
2015-05-22 09:27:56 +02:00
|
|
|
pht(
|
|
|
|
'You must %s the query before accessing the identifier map.',
|
|
|
|
'execute()'));
|
2013-07-21 19:57:07 +02:00
|
|
|
}
|
|
|
|
return $this->identifierMap;
|
|
|
|
}
|
|
|
|
|
2015-04-12 05:50:57 +02:00
|
|
|
protected function getPrimaryTableAlias() {
|
|
|
|
return 'commit';
|
2014-04-27 18:43:05 +02:00
|
|
|
}
|
|
|
|
|
2013-12-31 20:08:08 +01:00
|
|
|
protected function willExecute() {
|
2013-07-21 19:57:07 +02:00
|
|
|
if ($this->identifierMap === null) {
|
|
|
|
$this->identifierMap = array();
|
|
|
|
}
|
2013-12-31 20:08:08 +01:00
|
|
|
}
|
2013-07-21 19:57:07 +02:00
|
|
|
|
2015-08-31 19:17:54 +02:00
|
|
|
public function newResultObject() {
|
|
|
|
return new PhabricatorRepositoryCommit();
|
|
|
|
}
|
2013-02-27 17:04:54 +01:00
|
|
|
|
2015-08-31 19:17:54 +02:00
|
|
|
protected function loadPage() {
|
|
|
|
return $this->loadStandardPage($this->newResultObject());
|
2013-02-27 17:04:54 +01:00
|
|
|
}
|
|
|
|
|
2013-10-30 21:06:28 +01:00
|
|
|
protected function willFilterPage(array $commits) {
|
2013-02-27 17:04:54 +01:00
|
|
|
$repository_ids = mpull($commits, 'getRepositoryID', 'getRepositoryID');
|
|
|
|
$repos = id(new PhabricatorRepositoryQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withIDs($repository_ids)
|
|
|
|
->execute();
|
|
|
|
|
2015-01-01 17:07:26 +01:00
|
|
|
$min_qualified = PhabricatorRepository::MINIMUM_QUALIFIED_HASH;
|
|
|
|
$result = array();
|
|
|
|
|
2013-02-27 17:04:54 +01:00
|
|
|
foreach ($commits as $key => $commit) {
|
|
|
|
$repo = idx($repos, $commit->getRepositoryID());
|
|
|
|
if ($repo) {
|
|
|
|
$commit->attachRepository($repo);
|
|
|
|
} else {
|
2015-06-15 00:35:32 +02:00
|
|
|
$this->didRejectResult($commit);
|
2013-02-27 17:04:54 +01:00
|
|
|
unset($commits[$key]);
|
2015-01-06 17:02:49 +01:00
|
|
|
continue;
|
2013-02-27 17:04:54 +01:00
|
|
|
}
|
2013-07-21 19:57:07 +02:00
|
|
|
|
2015-01-01 17:07:26 +01:00
|
|
|
// Build the identifierMap
|
|
|
|
if ($this->identifiers !== null) {
|
2016-01-07 00:34:05 +01:00
|
|
|
$ids = $this->identifiers;
|
2015-01-01 17:07:26 +01:00
|
|
|
$prefixes = array(
|
|
|
|
'r'.$commit->getRepository()->getCallsign(),
|
|
|
|
'r'.$commit->getRepository()->getCallsign().':',
|
|
|
|
'R'.$commit->getRepository()->getID().':',
|
|
|
|
'', // No prefix is valid too and will only match the commitIdentifier
|
|
|
|
);
|
2013-07-21 19:57:07 +02:00
|
|
|
$suffix = $commit->getCommitIdentifier();
|
|
|
|
|
|
|
|
if ($commit->getRepository()->isSVN()) {
|
2015-01-01 17:07:26 +01:00
|
|
|
foreach ($prefixes as $prefix) {
|
|
|
|
if (isset($ids[$prefix.$suffix])) {
|
|
|
|
$result[$prefix.$suffix][] = $commit;
|
|
|
|
}
|
2013-07-21 19:57:07 +02:00
|
|
|
}
|
|
|
|
} else {
|
2014-07-23 02:03:09 +02:00
|
|
|
// This awkward construction is so we can link the commits up in O(N)
|
2013-07-21 19:57:07 +02:00
|
|
|
// time instead of O(N^2).
|
|
|
|
for ($ii = $min_qualified; $ii <= strlen($suffix); $ii++) {
|
|
|
|
$part = substr($suffix, 0, $ii);
|
2015-01-01 17:07:26 +01:00
|
|
|
foreach ($prefixes as $prefix) {
|
|
|
|
if (isset($ids[$prefix.$part])) {
|
|
|
|
$result[$prefix.$part][] = $commit;
|
|
|
|
}
|
2013-07-21 19:57:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-01 17:07:26 +01:00
|
|
|
}
|
2013-07-21 19:57:07 +02:00
|
|
|
|
2015-01-01 17:07:26 +01:00
|
|
|
if ($result) {
|
2013-07-21 19:57:07 +02:00
|
|
|
foreach ($result as $identifier => $matching_commits) {
|
|
|
|
if (count($matching_commits) == 1) {
|
|
|
|
$result[$identifier] = head($matching_commits);
|
|
|
|
} else {
|
|
|
|
// This reference is ambiguous (it matches more than one commit) so
|
2014-07-10 19:16:26 +02:00
|
|
|
// don't link it.
|
2013-07-21 19:57:07 +02:00
|
|
|
unset($result[$identifier]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->identifierMap += $result;
|
|
|
|
}
|
|
|
|
|
2013-02-27 17:04:54 +01:00
|
|
|
return $commits;
|
|
|
|
}
|
|
|
|
|
2013-10-30 21:06:28 +01:00
|
|
|
protected function didFilterPage(array $commits) {
|
2017-01-14 18:22:51 +01:00
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
2013-10-30 21:06:28 +01:00
|
|
|
if ($this->needCommitData) {
|
|
|
|
$data = id(new PhabricatorRepositoryCommitData())->loadAllWhere(
|
|
|
|
'commitID in (%Ld)',
|
|
|
|
mpull($commits, 'getID'));
|
|
|
|
$data = mpull($data, null, 'getCommitID');
|
|
|
|
foreach ($commits as $commit) {
|
|
|
|
$commit_data = idx($data, $commit->getID());
|
2014-05-11 01:46:32 +02:00
|
|
|
if (!$commit_data) {
|
|
|
|
$commit_data = new PhabricatorRepositoryCommitData();
|
|
|
|
}
|
2013-10-30 21:06:28 +01:00
|
|
|
$commit->attachCommitData($commit_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-12 17:49:36 +01:00
|
|
|
if ($this->needAuditRequests) {
|
2014-07-10 19:16:26 +02:00
|
|
|
$requests = id(new PhabricatorRepositoryAuditRequest())->loadAllWhere(
|
|
|
|
'commitPHID IN (%Ls)',
|
|
|
|
mpull($commits, 'getPHID'));
|
2014-04-27 18:43:05 +02:00
|
|
|
|
|
|
|
$requests = mgroup($requests, 'getCommitPHID');
|
|
|
|
foreach ($commits as $commit) {
|
|
|
|
$audit_requests = idx($requests, $commit->getPHID(), array());
|
|
|
|
$commit->attachAudits($audit_requests);
|
|
|
|
foreach ($audit_requests as $audit_request) {
|
|
|
|
$audit_request->attachCommit($commit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-14 18:22:51 +01:00
|
|
|
if ($this->needDrafts) {
|
|
|
|
PhabricatorDraftEngine::attachDrafts(
|
|
|
|
$viewer,
|
|
|
|
$commits);
|
|
|
|
}
|
|
|
|
|
2013-10-30 21:06:28 +01:00
|
|
|
return $commits;
|
|
|
|
}
|
|
|
|
|
2015-08-31 19:17:54 +02:00
|
|
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
|
|
|
$where = parent::buildWhereClauseParts($conn);
|
2013-02-27 17:04:54 +01:00
|
|
|
|
2014-08-14 22:04:38 +02:00
|
|
|
if ($this->repositoryPHIDs !== null) {
|
2015-08-08 02:19:44 +02:00
|
|
|
$map_repositories = id(new PhabricatorRepositoryQuery())
|
2014-08-14 22:04:38 +02:00
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withPHIDs($this->repositoryPHIDs)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
if (!$map_repositories) {
|
|
|
|
throw new PhabricatorEmptyQueryException();
|
|
|
|
}
|
|
|
|
$repository_ids = mpull($map_repositories, 'getID');
|
|
|
|
if ($this->repositoryIDs !== null) {
|
|
|
|
$repository_ids = array_merge($repository_ids, $this->repositoryIDs);
|
|
|
|
}
|
|
|
|
$this->withRepositoryIDs($repository_ids);
|
|
|
|
}
|
|
|
|
|
2014-04-28 17:25:51 +02:00
|
|
|
if ($this->ids !== null) {
|
2014-04-27 18:43:05 +02:00
|
|
|
$where[] = qsprintf(
|
2015-08-31 19:17:54 +02:00
|
|
|
$conn,
|
2014-04-27 18:43:05 +02:00
|
|
|
'commit.id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
2014-04-28 17:25:51 +02:00
|
|
|
if ($this->phids !== null) {
|
2014-04-27 18:43:05 +02:00
|
|
|
$where[] = qsprintf(
|
2015-08-31 19:17:54 +02:00
|
|
|
$conn,
|
2014-04-27 18:43:05 +02:00
|
|
|
'commit.phid IN (%Ls)',
|
|
|
|
$this->phids);
|
|
|
|
}
|
|
|
|
|
2014-04-28 17:25:51 +02:00
|
|
|
if ($this->repositoryIDs !== null) {
|
2014-04-27 18:43:05 +02:00
|
|
|
$where[] = qsprintf(
|
2015-08-31 19:17:54 +02:00
|
|
|
$conn,
|
2014-04-27 18:43:05 +02:00
|
|
|
'commit.repositoryID IN (%Ld)',
|
|
|
|
$this->repositoryIDs);
|
|
|
|
}
|
|
|
|
|
2014-04-28 17:25:51 +02:00
|
|
|
if ($this->authorPHIDs !== null) {
|
2014-04-27 18:43:05 +02:00
|
|
|
$where[] = qsprintf(
|
2015-08-31 19:17:54 +02:00
|
|
|
$conn,
|
2014-04-27 18:43:05 +02:00
|
|
|
'commit.authorPHID IN (%Ls)',
|
|
|
|
$this->authorPHIDs);
|
|
|
|
}
|
|
|
|
|
2015-06-20 14:25:44 +02:00
|
|
|
if ($this->epochMin !== null) {
|
|
|
|
$where[] = qsprintf(
|
2015-08-31 19:17:54 +02:00
|
|
|
$conn,
|
2015-06-20 14:25:44 +02:00
|
|
|
'commit.epoch >= %d',
|
|
|
|
$this->epochMin);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->epochMax !== null) {
|
|
|
|
$where[] = qsprintf(
|
2015-08-31 19:17:54 +02:00
|
|
|
$conn,
|
2015-06-20 14:25:44 +02:00
|
|
|
'commit.epoch <= %d',
|
|
|
|
$this->epochMax);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->importing !== null) {
|
|
|
|
if ($this->importing) {
|
|
|
|
$where[] = qsprintf(
|
2015-08-31 19:17:54 +02:00
|
|
|
$conn,
|
2015-06-20 14:25:44 +02:00
|
|
|
'(commit.importStatus & %d) != %d',
|
|
|
|
PhabricatorRepositoryCommit::IMPORTED_ALL,
|
|
|
|
PhabricatorRepositoryCommit::IMPORTED_ALL);
|
|
|
|
} else {
|
|
|
|
$where[] = qsprintf(
|
2015-08-31 19:17:54 +02:00
|
|
|
$conn,
|
2015-06-20 14:25:44 +02:00
|
|
|
'(commit.importStatus & %d) = %d',
|
|
|
|
PhabricatorRepositoryCommit::IMPORTED_ALL,
|
|
|
|
PhabricatorRepositoryCommit::IMPORTED_ALL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-28 17:25:51 +02:00
|
|
|
if ($this->identifiers !== null) {
|
2013-02-27 17:04:54 +01:00
|
|
|
$min_unqualified = PhabricatorRepository::MINIMUM_UNQUALIFIED_HASH;
|
|
|
|
$min_qualified = PhabricatorRepository::MINIMUM_QUALIFIED_HASH;
|
|
|
|
|
|
|
|
$refs = array();
|
|
|
|
$bare = array();
|
|
|
|
foreach ($this->identifiers as $identifier) {
|
|
|
|
$matches = null;
|
2015-01-01 17:07:26 +01:00
|
|
|
preg_match('/^(?:[rR]([A-Z]+:?|[0-9]+:))?(.*)$/',
|
|
|
|
$identifier, $matches);
|
|
|
|
$repo = nonempty(rtrim($matches[1], ':'), null);
|
|
|
|
$commit_identifier = nonempty($matches[2], null);
|
2013-02-27 17:04:54 +01:00
|
|
|
|
2013-05-07 03:05:33 +02:00
|
|
|
if ($repo === null) {
|
|
|
|
if ($this->defaultRepository) {
|
2016-04-04 18:40:41 +02:00
|
|
|
$repo = $this->defaultRepository->getPHID();
|
2013-05-07 03:05:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-27 17:04:54 +01:00
|
|
|
if ($repo === null) {
|
2015-01-01 17:07:26 +01:00
|
|
|
if (strlen($commit_identifier) < $min_unqualified) {
|
2013-02-27 17:04:54 +01:00
|
|
|
continue;
|
|
|
|
}
|
2015-01-01 17:07:26 +01:00
|
|
|
$bare[] = $commit_identifier;
|
2013-02-27 17:04:54 +01:00
|
|
|
} else {
|
|
|
|
$refs[] = array(
|
2016-04-04 18:40:41 +02:00
|
|
|
'repository' => $repo,
|
2015-01-01 17:07:26 +01:00
|
|
|
'identifier' => $commit_identifier,
|
2013-02-27 17:04:54 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = array();
|
|
|
|
|
|
|
|
foreach ($bare as $identifier) {
|
|
|
|
$sql[] = qsprintf(
|
2015-08-31 19:17:54 +02:00
|
|
|
$conn,
|
2014-04-27 18:43:05 +02:00
|
|
|
'(commit.commitIdentifier LIKE %> AND '.
|
|
|
|
'LENGTH(commit.commitIdentifier) = 40)',
|
2013-02-27 17:04:54 +01:00
|
|
|
$identifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($refs) {
|
2016-04-04 18:40:41 +02:00
|
|
|
$repositories = ipull($refs, 'repository');
|
2015-01-01 17:07:26 +01:00
|
|
|
|
2013-02-27 17:04:54 +01:00
|
|
|
$repos = id(new PhabricatorRepositoryQuery())
|
|
|
|
->setViewer($this->getViewer())
|
2016-04-04 18:40:41 +02:00
|
|
|
->withIdentifiers($repositories);
|
2015-01-01 17:07:26 +01:00
|
|
|
$repos->execute();
|
|
|
|
|
|
|
|
$repos = $repos->getIdentifierMap();
|
2013-02-27 17:04:54 +01:00
|
|
|
foreach ($refs as $key => $ref) {
|
2016-04-04 18:40:41 +02:00
|
|
|
$repo = idx($repos, $ref['repository']);
|
2013-02-27 17:04:54 +01:00
|
|
|
if (!$repo) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($repo->isSVN()) {
|
2016-01-07 00:34:05 +01:00
|
|
|
if (!ctype_digit((string)$ref['identifier'])) {
|
2013-03-19 23:30:16 +01:00
|
|
|
continue;
|
|
|
|
}
|
2013-02-27 17:04:54 +01:00
|
|
|
$sql[] = qsprintf(
|
2015-08-31 19:17:54 +02:00
|
|
|
$conn,
|
2014-04-27 18:43:05 +02:00
|
|
|
'(commit.repositoryID = %d AND commit.commitIdentifier = %s)',
|
2013-02-27 17:04:54 +01:00
|
|
|
$repo->getID(),
|
2013-06-14 03:01:40 +02:00
|
|
|
// NOTE: Because the 'commitIdentifier' column is a string, MySQL
|
|
|
|
// ignores the index if we hand it an integer. Hand it a string.
|
|
|
|
// See T3377.
|
|
|
|
(int)$ref['identifier']);
|
2013-02-27 17:04:54 +01:00
|
|
|
} else {
|
|
|
|
if (strlen($ref['identifier']) < $min_qualified) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-01-07 00:34:05 +01:00
|
|
|
|
|
|
|
$identifier = $ref['identifier'];
|
|
|
|
if (strlen($identifier) == 40) {
|
|
|
|
// MySQL seems to do slightly better with this version if the
|
|
|
|
// clause, so issue it if we have a full commit hash.
|
|
|
|
$sql[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'(commit.repositoryID = %d
|
|
|
|
AND commit.commitIdentifier = %s)',
|
|
|
|
$repo->getID(),
|
|
|
|
$identifier);
|
|
|
|
} else {
|
|
|
|
$sql[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'(commit.repositoryID = %d
|
|
|
|
AND commit.commitIdentifier LIKE %>)',
|
|
|
|
$repo->getID(),
|
|
|
|
$identifier);
|
|
|
|
}
|
2013-02-27 17:04:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:28:02 +01:00
|
|
|
if (!$sql) {
|
2013-02-27 17:04:54 +01:00
|
|
|
// If we discarded all possible identifiers (e.g., they all referenced
|
|
|
|
// bogus repositories or were all too short), make sure the query finds
|
|
|
|
// nothing.
|
2014-01-28 02:14:21 +01:00
|
|
|
throw new PhabricatorEmptyQueryException(
|
|
|
|
pht('No commit identifiers.'));
|
2013-02-27 17:04:54 +01:00
|
|
|
}
|
2013-03-01 20:28:02 +01:00
|
|
|
|
|
|
|
$where[] = '('.implode(' OR ', $sql).')';
|
2013-02-27 17:04:54 +01:00
|
|
|
}
|
|
|
|
|
2014-04-28 17:25:51 +02:00
|
|
|
if ($this->auditIDs !== null) {
|
2013-05-17 12:51:33 +02:00
|
|
|
$where[] = qsprintf(
|
2015-08-31 19:17:54 +02:00
|
|
|
$conn,
|
2017-01-12 17:49:36 +01:00
|
|
|
'auditor.id IN (%Ld)',
|
2014-04-27 18:43:05 +02:00
|
|
|
$this->auditIDs);
|
2013-05-17 12:51:33 +02:00
|
|
|
}
|
|
|
|
|
2014-04-28 17:25:51 +02:00
|
|
|
if ($this->auditorPHIDs !== null) {
|
2013-02-27 19:54:39 +01:00
|
|
|
$where[] = qsprintf(
|
2015-08-31 19:17:54 +02:00
|
|
|
$conn,
|
2017-01-12 17:49:36 +01:00
|
|
|
'auditor.auditorPHID IN (%Ls)',
|
2014-04-27 18:43:05 +02:00
|
|
|
$this->auditorPHIDs);
|
2013-02-27 19:54:39 +01:00
|
|
|
}
|
|
|
|
|
2017-01-12 17:49:36 +01:00
|
|
|
if ($this->responsiblePHIDs !== null) {
|
2013-10-30 21:06:28 +01:00
|
|
|
$where[] = qsprintf(
|
2015-08-31 19:17:54 +02:00
|
|
|
$conn,
|
2017-01-12 17:49:36 +01:00
|
|
|
'(audit.auditorPHID IN (%Ls) OR commit.authorPHID IN (%Ls))',
|
|
|
|
$this->responsiblePHIDs,
|
|
|
|
$this->responsiblePHIDs);
|
2014-04-27 18:43:05 +02:00
|
|
|
}
|
|
|
|
|
2017-01-12 17:49:36 +01:00
|
|
|
if ($this->statuses !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'commit.auditStatus IN (%Ls)',
|
|
|
|
$this->statuses);
|
2013-10-30 21:06:28 +01:00
|
|
|
}
|
|
|
|
|
2017-01-30 19:39:35 +01:00
|
|
|
if ($this->packagePHIDs !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'package.dst IN (%Ls)',
|
|
|
|
$this->packagePHIDs);
|
|
|
|
}
|
|
|
|
|
2015-08-31 19:17:54 +02:00
|
|
|
return $where;
|
2013-02-27 17:04:54 +01:00
|
|
|
}
|
|
|
|
|
2015-01-13 20:56:07 +01:00
|
|
|
protected function didFilterResults(array $filtered) {
|
2013-07-21 19:57:07 +02:00
|
|
|
if ($this->identifierMap) {
|
|
|
|
foreach ($this->identifierMap as $name => $commit) {
|
|
|
|
if (isset($filtered[$commit->getPHID()])) {
|
|
|
|
unset($this->identifierMap[$name]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-12 17:49:36 +01:00
|
|
|
private function shouldJoinAuditor() {
|
|
|
|
return ($this->auditIDs || $this->auditorPHIDs);
|
2015-08-31 19:17:54 +02:00
|
|
|
}
|
|
|
|
|
2017-01-12 17:49:36 +01:00
|
|
|
private function shouldJoinAudit() {
|
|
|
|
return (bool)$this->responsiblePHIDs;
|
2015-08-31 19:17:54 +02:00
|
|
|
}
|
|
|
|
|
2017-01-30 19:39:35 +01:00
|
|
|
private function shouldJoinOwners() {
|
|
|
|
return (bool)$this->packagePHIDs;
|
|
|
|
}
|
|
|
|
|
2015-08-31 19:17:54 +02:00
|
|
|
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
|
|
|
|
$join = parent::buildJoinClauseParts($conn);
|
2014-04-27 18:43:05 +02:00
|
|
|
$audit_request = new PhabricatorRepositoryAuditRequest();
|
|
|
|
|
2017-01-12 17:49:36 +01:00
|
|
|
if ($this->shouldJoinAuditor()) {
|
2015-08-31 19:17:54 +02:00
|
|
|
$join[] = qsprintf(
|
|
|
|
$conn,
|
2017-01-12 17:49:36 +01:00
|
|
|
'JOIN %T auditor ON commit.phid = auditor.commitPHID',
|
2015-08-31 19:17:54 +02:00
|
|
|
$audit_request->getTableName());
|
|
|
|
}
|
|
|
|
|
2017-01-12 17:49:36 +01:00
|
|
|
if ($this->shouldJoinAudit()) {
|
2015-08-31 19:17:54 +02:00
|
|
|
$join[] = qsprintf(
|
|
|
|
$conn,
|
2017-01-12 17:49:36 +01:00
|
|
|
'LEFT JOIN %T audit ON commit.phid = audit.commitPHID',
|
2014-04-27 18:43:05 +02:00
|
|
|
$audit_request->getTableName());
|
|
|
|
}
|
|
|
|
|
2017-01-30 19:39:35 +01:00
|
|
|
if ($this->shouldJoinOwners()) {
|
|
|
|
$join[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'JOIN %T package ON commit.phid = package.src
|
|
|
|
AND package.type = %s',
|
|
|
|
PhabricatorEdgeConfig::TABLE_NAME_EDGE,
|
|
|
|
DiffusionCommitHasPackageEdgeType::EDGECONST);
|
|
|
|
}
|
|
|
|
|
2015-08-31 19:17:54 +02:00
|
|
|
return $join;
|
2014-04-27 18:43:05 +02:00
|
|
|
}
|
|
|
|
|
2015-08-31 19:17:54 +02:00
|
|
|
protected function shouldGroupQueryResultRows() {
|
2017-01-12 17:49:36 +01:00
|
|
|
if ($this->shouldJoinAuditor()) {
|
2015-08-31 19:17:54 +02:00
|
|
|
return true;
|
2014-07-10 19:16:26 +02:00
|
|
|
}
|
|
|
|
|
2017-01-12 17:49:36 +01:00
|
|
|
if ($this->shouldJoinAudit()) {
|
2015-08-31 19:17:54 +02:00
|
|
|
return true;
|
2014-07-10 19:16:26 +02:00
|
|
|
}
|
2015-08-31 19:17:54 +02:00
|
|
|
|
2017-01-30 19:39:35 +01:00
|
|
|
if ($this->shouldJoinOwners()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-31 19:17:54 +02:00
|
|
|
return parent::shouldGroupQueryResultRows();
|
2014-07-10 19:16:26 +02:00
|
|
|
}
|
|
|
|
|
Lock policy queries to their applications
Summary:
While we mostly have reasonable effective object accessibility when you lock a user out of an application, it's primarily enforced at the controller level. Users can still, e.g., load the handles of objects they can't actually see. Instead, lock the queries to the applications so that you can, e.g., never load a revision if you don't have access to Differential.
This has several parts:
- For PolicyAware queries, provide an application class name method.
- If the query specifies a class name and the user doesn't have permission to use it, fail the entire query unconditionally.
- For handles, simplify query construction and count all the PHIDs as "restricted" so we get a UI full of "restricted" instead of "unknown" handles.
Test Plan:
- Added a unit test to verify I got all the class names right.
- Browsed around, logged in/out as a normal user with public policies on and off.
- Browsed around, logged in/out as a restricted user with public policies on and off. With restrictions, saw all traces of restricted apps removed or restricted.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7367
2013-10-22 02:20:27 +02:00
|
|
|
public function getQueryApplicationClass() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorDiffusionApplication';
|
Lock policy queries to their applications
Summary:
While we mostly have reasonable effective object accessibility when you lock a user out of an application, it's primarily enforced at the controller level. Users can still, e.g., load the handles of objects they can't actually see. Instead, lock the queries to the applications so that you can, e.g., never load a revision if you don't have access to Differential.
This has several parts:
- For PolicyAware queries, provide an application class name method.
- If the query specifies a class name and the user doesn't have permission to use it, fail the entire query unconditionally.
- For handles, simplify query construction and count all the PHIDs as "restricted" so we get a UI full of "restricted" instead of "unknown" handles.
Test Plan:
- Added a unit test to verify I got all the class names right.
- Browsed around, logged in/out as a normal user with public policies on and off.
- Browsed around, logged in/out as a restricted user with public policies on and off. With restrictions, saw all traces of restricted apps removed or restricted.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7367
2013-10-22 02:20:27 +02:00
|
|
|
}
|
|
|
|
|
2015-08-31 19:17:54 +02:00
|
|
|
public function getOrderableColumns() {
|
|
|
|
return parent::getOrderableColumns() + array(
|
|
|
|
'epoch' => array(
|
|
|
|
'table' => $this->getPrimaryTableAlias(),
|
|
|
|
'column' => 'epoch',
|
|
|
|
'type' => 'int',
|
|
|
|
'reverse' => false,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getPagingValueMap($cursor, array $keys) {
|
|
|
|
$commit = $this->loadCursorObject($cursor);
|
|
|
|
return array(
|
|
|
|
'id' => $commit->getID(),
|
|
|
|
'epoch' => $commit->getEpoch(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBuiltinOrders() {
|
|
|
|
$parent = parent::getBuiltinOrders();
|
|
|
|
|
|
|
|
// Rename the default ID-based orders.
|
|
|
|
$parent['importnew'] = array(
|
|
|
|
'name' => pht('Import Date (Newest First)'),
|
|
|
|
) + $parent['newest'];
|
|
|
|
|
|
|
|
$parent['importold'] = array(
|
|
|
|
'name' => pht('Import Date (Oldest First)'),
|
|
|
|
) + $parent['oldest'];
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'newest' => array(
|
|
|
|
'vector' => array('epoch', 'id'),
|
|
|
|
'name' => pht('Commit Date (Newest First)'),
|
|
|
|
),
|
|
|
|
'oldest' => array(
|
|
|
|
'vector' => array('-epoch', '-id'),
|
|
|
|
'name' => pht('Commit Date (Oldest First)'),
|
|
|
|
),
|
|
|
|
) + $parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-27 17:04:54 +01:00
|
|
|
}
|