Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/query/DiffusionCommitQuery.php
| Show First 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | protected function willFilterPage(array $commits) { | ||||
| if ($this->identifiers !== null) { | if ($this->identifiers !== null) { | ||||
| $ids = array_fuse($this->identifiers); | $ids = array_fuse($this->identifiers); | ||||
| $min_qualified = PhabricatorRepository::MINIMUM_QUALIFIED_HASH; | $min_qualified = PhabricatorRepository::MINIMUM_QUALIFIED_HASH; | ||||
| $result = array(); | $result = array(); | ||||
| foreach ($commits as $commit) { | foreach ($commits as $commit) { | ||||
| $prefix = 'r'.$commit->getRepository()->getCallsign(); | $prefix = 'r'.$commit->getRepository()->getCallsign(); | ||||
| $prefix_id = 'r'.$commit->getRepository()->getID().':'; | |||||
| $suffix = $commit->getCommitIdentifier(); | $suffix = $commit->getCommitIdentifier(); | ||||
| if ($commit->getRepository()->isSVN()) { | if ($commit->getRepository()->isSVN()) { | ||||
| if (isset($ids[$prefix.$suffix])) { | if (isset($ids[$prefix.$suffix])) { | ||||
| $result[$prefix.$suffix][] = $commit; | $result[$prefix.$suffix][] = $commit; | ||||
| } | } | ||||
| if (isset($ids[$prefix.':'.$suffix])) { | |||||
| $result[$prefix.':'.$suffix][] = $commit; | |||||
| } | |||||
| if (isset($ids[$prefix_id.$suffix])) { | |||||
| $result[$prefix_id.$suffix][] = $commit; | |||||
| } | |||||
| } else { | } else { | ||||
| // This awkward construction is so we can link the commits up in O(N) | // This awkward construction is so we can link the commits up in O(N) | ||||
| // time instead of O(N^2). | // time instead of O(N^2). | ||||
| for ($ii = $min_qualified; $ii <= strlen($suffix); $ii++) { | for ($ii = $min_qualified; $ii <= strlen($suffix); $ii++) { | ||||
| $part = substr($suffix, 0, $ii); | $part = substr($suffix, 0, $ii); | ||||
| if (isset($ids[$prefix.$part])) { | if (isset($ids[$prefix.$part])) { | ||||
| $result[$prefix.$part][] = $commit; | $result[$prefix.$part][] = $commit; | ||||
| } | } | ||||
| if (isset($ids[$prefix.':'.$part])) { | |||||
| $result[$prefix.':'.$part][] = $commit; | |||||
| } | |||||
| if (isset($ids[$prefix_id.$part])) { | |||||
| $result[$prefix_id.$part][] = $commit; | |||||
| } | |||||
| if (isset($ids[$part])) { | if (isset($ids[$part])) { | ||||
| $result[$part][] = $commit; | $result[$part][] = $commit; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| foreach ($result as $identifier => $matching_commits) { | foreach ($result as $identifier => $matching_commits) { | ||||
| ▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | private function buildWhereClause(AphrontDatabaseConnection $conn_r) { | ||||
| if ($this->identifiers !== null) { | if ($this->identifiers !== null) { | ||||
| $min_unqualified = PhabricatorRepository::MINIMUM_UNQUALIFIED_HASH; | $min_unqualified = PhabricatorRepository::MINIMUM_UNQUALIFIED_HASH; | ||||
| $min_qualified = PhabricatorRepository::MINIMUM_QUALIFIED_HASH; | $min_qualified = PhabricatorRepository::MINIMUM_QUALIFIED_HASH; | ||||
| $refs = array(); | $refs = array(); | ||||
| $bare = array(); | $bare = array(); | ||||
| foreach ($this->identifiers as $identifier) { | foreach ($this->identifiers as $identifier) { | ||||
| $matches = null; | $matches = null; | ||||
| preg_match('/^(?:r([A-Z]+))?(.*)$/', $identifier, $matches); | // FIXME: Replace with CommitPHIDType::getCommitObjectNamePattern ?? | ||||
| $repo = nonempty($matches[1], null); | preg_match('/^(?:r([A-Z]+:?|[0-9]+:))?(.*)$/', $identifier, $matches); | ||||
| $repo = nonempty(rtrim($matches[1], ':'), null); | |||||
| $identifier = nonempty($matches[2], null); | $identifier = nonempty($matches[2], null); | ||||
| if ($repo === null) { | if ($repo === null) { | ||||
epriestley: Prefer `$commit_identifier`, for consistency.
This is actually a bug with lint, which should… | |||||
| if ($this->defaultRepository) { | if ($this->defaultRepository) { | ||||
| $repo = $this->defaultRepository->getCallsign(); | $repo = $this->defaultRepository->getCallsign(); | ||||
| } | } | ||||
| } | } | ||||
| if ($repo === null) { | if ($repo === null) { | ||||
| if (strlen($identifier) < $min_unqualified) { | if (strlen($identifier) < $min_unqualified) { | ||||
| continue; | continue; | ||||
| Show All 14 Lines | if ($this->identifiers !== null) { | ||||
| $conn_r, | $conn_r, | ||||
| '(commit.commitIdentifier LIKE %> AND '. | '(commit.commitIdentifier LIKE %> AND '. | ||||
| 'LENGTH(commit.commitIdentifier) = 40)', | 'LENGTH(commit.commitIdentifier) = 40)', | ||||
| $identifier); | $identifier); | ||||
| } | } | ||||
| if ($refs) { | if ($refs) { | ||||
| $callsigns = ipull($refs, 'callsign'); | $callsigns = ipull($refs, 'callsign'); | ||||
| $repos = id(new PhabricatorRepositoryQuery()) | |||||
| $repos = array(); | |||||
| $repos_by_callsign = id(new PhabricatorRepositoryQuery()) | |||||
| ->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
| ->withCallsigns($callsigns) | ->withCallsigns($callsigns) | ||||
| ->execute(); | ->execute(); | ||||
| $repos = mpull($repos, null, 'getCallsign'); | foreach ($repos_by_callsign as $obj) { | ||||
| $repos[$obj->getCallsign()] = $obj; | |||||
| } | |||||
epriestleyUnsubmitted Not Done Inline ActionsWe should check for if ($callsigns) and if ($ids) before issuing these queries. epriestley: We should check for `if ($callsigns)` and `if ($ids)` before issuing these queries. | |||||
| $ids = array_filter($callsigns, 'is_numeric'); | |||||
epriestleyUnsubmitted Not Done Inline ActionsConsider ctype_digit() instead of is_numeric because values like "0.0", "1e5", and "-3" satisfy is_numeric(). (I think it doesn't matter in this case, but it's nice to do the stricter check when we have stricter expectations about the input.) epriestley: Consider `ctype_digit()` instead of `is_numeric` because values like "0.0", "1e5", and "-3"… | |||||
| $repos_by_id = id(new PhabricatorRepositoryQuery()) | |||||
| ->setViewer($this->getViewer()) | |||||
| ->withIDs($ids) | |||||
| ->execute(); | |||||
| foreach ($repos_by_id as $obj) { | |||||
| $repos[$obj->getID()] = $obj; | |||||
| } | |||||
| foreach ($refs as $key => $ref) { | foreach ($refs as $key => $ref) { | ||||
| $repo = idx($repos, $ref['callsign']); | $repo = idx($repos, $ref['callsign']); | ||||
| if (!$repo) { | if (!$repo) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if ($repo->isSVN()) { | if ($repo->isSVN()) { | ||||
| if (!ctype_digit($ref['identifier'])) { | if (!ctype_digit($ref['identifier'])) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 175 Lines • Show Last 20 Lines | |||||
Prefer $commit_identifier, for consistency.
This is actually a bug with lint, which should have caught this automatically. D11087 should have a fix for it.