Differential D21511 Diff 51200 src/applications/diffusion/conduit/DiffusionBrowseQueryConduitAPIMethod.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/conduit/DiffusionBrowseQueryConduitAPIMethod.php
| Show All 29 Lines | final class DiffusionBrowseQueryConduitAPIMethod | ||||
| protected function getResult(ConduitAPIRequest $request) { | protected function getResult(ConduitAPIRequest $request) { | ||||
| $result = parent::getResult($request); | $result = parent::getResult($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 = 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 == '') { | 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'; | $stdout = 'tree'; | ||||
| } else { | } else { | ||||
| try { | try { | ||||
| list($stdout) = $repository->execxLocalCommand( | list($stdout) = $repository->execxLocalCommand( | ||||
| 'cat-file -t -- %s:%s', | 'cat-file -t -- %s', | ||||
| $commit, | sprintf('%s:%s', $commit, $path)); | ||||
| $path); | |||||
| } 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 54 Lines • ▼ Show 20 Lines | if (trim($stdout) == 'blob') { | ||||
| 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) { | |||||
| list($stdout) = $repository->execxLocalCommand( | |||||
| 'ls-tree -z -l %s --', | |||||
| gitsprintf('%s', $commit)); | |||||
| } else { | |||||
| 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(); | ||||
| if (strlen($path)) { | if ($path !== null) { | ||||
| $prefix = rtrim($path, '/').'/'; | $prefix = rtrim($path, '/').'/'; | ||||
| } else { | } else { | ||||
| $prefix = ''; | $prefix = ''; | ||||
| } | } | ||||
| $count = 0; | $count = 0; | ||||
| $results = array(); | $results = array(); | ||||
| $lines = empty($stdout) | $lines = empty($stdout) | ||||
| ▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | if ($submodules) { | ||||
| $dict = array(); | $dict = array(); | ||||
| $lines = explode("\n", trim($module_info)); | $lines = explode("\n", trim($module_info)); | ||||
| foreach ($lines as $line) { | foreach ($lines as $line) { | ||||
| list($key, $value) = explode('=', $line, 2); | list($key, $value) = explode('=', $line, 2); | ||||
| $parts = explode('.', $key); | $parts = explode('.', $key); | ||||
| $dict[$key] = $value; | $dict[$key] = $value; | ||||
| } | } | ||||
| foreach ($submodules as $path) { | foreach ($submodules as $submodule_path) { | ||||
| $full_path = $path->getFullPath(); | $full_path = $submodule_path->getFullPath(); | ||||
| $key = 'submodule.'.$full_path.'.url'; | $key = 'submodule.'.$full_path.'.url'; | ||||
| if (isset($dict[$key])) { | if (isset($dict[$key])) { | ||||
| $path->setExternalURI($dict[$key]); | $path->setExternalURI($dict[$key]); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 311 Lines • Show Last 20 Lines | |||||