Differential D21528 Diff 51243 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)) { | if (!strlen($path) || $path === '/') { | ||||
| $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(); | ||||
| if ($path === null) { | if ($path === null) { | ||||
| // Fast path to improve the performance of the repository view; we know | // Fast path to improve the performance of the repository view; we know | ||||
| // the root is always a tree at any commit and always exists. | // the root is always a tree at any commit and always exists. | ||||
| $stdout = 'tree'; | $path_type = 'tree'; | ||||
| } else { | } else { | ||||
| try { | try { | ||||
| list($stdout) = $repository->execxLocalCommand( | list($stdout) = $repository->execxLocalCommand( | ||||
| 'cat-file -t -- %s', | 'cat-file -t -- %s', | ||||
| sprintf('%s:%s', $commit, $path)); | sprintf('%s:%s', $commit, $path)); | ||||
| $path_type = trim($stdout); | |||||
| } catch (CommandException $e) { | } catch (CommandException $e) { | ||||
| // The "cat-file" command may fail if the path legitimately does not | // The "cat-file" command may fail if the path legitimately does not | ||||
| // exist, but it may also fail if the path is a submodule. This can | // exist, but it may also fail if the path is a submodule. This can | ||||
| // produce either "Not a valid object name" or "could not get object | // produce either "Not a valid object name" or "could not get object | ||||
| // info". | // info". | ||||
| // To detect if we have a submodule, use `git ls-tree`. If the path | // To detect if we have a submodule, use `git ls-tree`. If the path | ||||
| // is a submodule, we'll get a "160000" mode mask with type "commit". | // is a submodule, we'll get a "160000" mode mask with type "commit". | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if ($path === null) { | ||||
| DiffusionBrowseResultSet::REASON_IS_NONEXISTENT); | DiffusionBrowseResultSet::REASON_IS_NONEXISTENT); | ||||
| return $result; | return $result; | ||||
| } else { | } else { | ||||
| throw $e; | throw $e; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (trim($stdout) == 'blob') { | if ($path_type === 'blob') { | ||||
| $result->setReasonForEmptyResultSet( | $result->setReasonForEmptyResultSet( | ||||
| DiffusionBrowseResultSet::REASON_IS_FILE); | DiffusionBrowseResultSet::REASON_IS_FILE); | ||||
| return $result; | return $result; | ||||
| } | } | ||||
| $result->setIsValidResults(true); | $result->setIsValidResults(true); | ||||
| if ($this->shouldOnlyTestValidity($request)) { | if ($this->shouldOnlyTestValidity($request)) { | ||||
| return $result; | return $result; | ||||
| } | } | ||||
| if ($path === null) { | if ($path === null) { | ||||
| list($stdout) = $repository->execxLocalCommand( | list($stdout) = $repository->execxLocalCommand( | ||||
| 'ls-tree -z -l %s --', | 'ls-tree -z -l %s --', | ||||
| gitsprintf('%s', $commit)); | gitsprintf('%s', $commit)); | ||||
| } else { | } else { | ||||
| if ($path_type === 'tree') { | |||||
| $path = rtrim($path, '/').'/'; | |||||
| } else { | |||||
| $path = rtrim($path, '/'); | |||||
| } | |||||
| list($stdout) = $repository->execxLocalCommand( | list($stdout) = $repository->execxLocalCommand( | ||||
| 'ls-tree -z -l %s -- %s', | 'ls-tree -z -l %s -- %s', | ||||
| gitsprintf('%s', $commit), | gitsprintf('%s', $commit), | ||||
| $path); | $path); | ||||
| } | } | ||||
| $submodules = array(); | $submodules = array(); | ||||
| ▲ Show 20 Lines • Show All 419 Lines • Show Last 20 Lines | |||||