Differential D21864 Diff 52157 src/applications/diffusion/conduit/DiffusionBrowseQueryConduitAPIMethod.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/conduit/DiffusionBrowseQueryConduitAPIMethod.php
Show All 31 Lines | protected function getResult(ConduitAPIRequest $request) { | ||||
return $result->toDictionary(); | return $result->toDictionary(); | ||||
} | } | ||||
protected function getGitResult(ConduitAPIRequest $request) { | protected function getGitResult(ConduitAPIRequest $request) { | ||||
$drequest = $this->getDiffusionRequest(); | $drequest = $this->getDiffusionRequest(); | ||||
$repository = $drequest->getRepository(); | $repository = $drequest->getRepository(); | ||||
$path = $request->getValue('path'); | $path = $request->getValue('path'); | ||||
if (!strlen($path) || $path === '/') { | if ($path === null || !strlen($path) || $path === '/') { | ||||
cspeckmim: This felt weird but I wasn't sure how else to guard the strlen. Maybe `phutil_nonempty_string`… | |||||
$path = null; | $path = null; | ||||
} | } | ||||
$commit = $request->getValue('commit'); | $commit = $request->getValue('commit'); | ||||
$offset = (int)$request->getValue('offset'); | $offset = (int)$request->getValue('offset'); | ||||
$limit = (int)$request->getValue('limit'); | $limit = (int)$request->getValue('limit'); | ||||
$result = $this->getEmptyResultSet(); | $result = $this->getEmptyResultSet(); | ||||
▲ Show 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | protected function getMercurialResult(ConduitAPIRequest $request) { | ||||
$entire_manifest = id(new DiffusionLowLevelMercurialPathsQuery()) | $entire_manifest = id(new DiffusionLowLevelMercurialPathsQuery()) | ||||
->setRepository($repository) | ->setRepository($repository) | ||||
->withCommit($commit) | ->withCommit($commit) | ||||
->withPath($path) | ->withPath($path) | ||||
->execute(); | ->execute(); | ||||
$results = array(); | $results = array(); | ||||
if ($path !== null) { | |||||
$match_against = trim($path, '/'); | $match_against = trim($path, '/'); | ||||
$match_len = strlen($match_against); | $match_len = strlen($match_against); | ||||
} else { | |||||
$match_against = ''; | |||||
$match_len = 0; | |||||
} | |||||
// For the root, don't trim. For other paths, trim the "/" after we match. | // For the root, don't trim. For other paths, trim the "/" after we match. | ||||
// We need this because Mercurial's canonical paths have no leading "/", | // We need this because Mercurial's canonical paths have no leading "/", | ||||
// but ours do. | // but ours do. | ||||
$trim_len = $match_len ? $match_len + 1 : 0; | $trim_len = $match_len ? $match_len + 1 : 0; | ||||
$count = 0; | $count = 0; | ||||
foreach ($entire_manifest as $path) { | foreach ($entire_manifest as $path) { | ||||
if (strncmp($path, $match_against, $match_len)) { | if (strncmp($path, $match_against, $match_len)) { | ||||
continue; | continue; | ||||
} | } | ||||
if (!strlen($path)) { | if ($path === null || !strlen($path)) { | ||||
continue; | continue; | ||||
} | } | ||||
$remainder = substr($path, $trim_len); | $remainder = substr($path, $trim_len); | ||||
if (!strlen($remainder)) { | if (!strlen($remainder)) { | ||||
// There is a file with this exact name in the manifest, so clearly | // There is a file with this exact name in the manifest, so clearly | ||||
// it's a file. | // it's a file. | ||||
$result->setReasonForEmptyResultSet( | $result->setReasonForEmptyResultSet( | ||||
DiffusionBrowseResultSet::REASON_IS_FILE); | DiffusionBrowseResultSet::REASON_IS_FILE); | ||||
▲ Show 20 Lines • Show All 268 Lines • Show Last 20 Lines |
This felt weird but I wasn't sure how else to guard the strlen. Maybe phutil_nonempty_string would be appropriate here