Differential D21519 Diff 51219 src/applications/diffusion/conduit/DiffusionBrowseQueryConduitAPIMethod.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/conduit/DiffusionBrowseQueryConduitAPIMethod.php
| Show First 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | if ($path === null) { | ||||
| 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 ($path !== null) { | |||||
| $prefix = rtrim($path, '/').'/'; | |||||
| } else { | |||||
| $prefix = ''; | |||||
| } | |||||
| $count = 0; | $count = 0; | ||||
| $results = array(); | $results = array(); | ||||
| $lines = empty($stdout) | $lines = empty($stdout) | ||||
| ? array() | ? array() | ||||
| : explode("\0", rtrim($stdout)); | : explode("\0", rtrim($stdout)); | ||||
| foreach ($lines as $line) { | foreach ($lines as $line) { | ||||
| // NOTE: Limit to 5 components so we parse filenames with spaces in them | // NOTE: Limit to 5 components so we parse filenames with spaces in them | ||||
| // correctly. | // correctly. | ||||
| // NOTE: The output uses a mixture of tabs and one-or-more spaces to | // NOTE: The output uses a mixture of tabs and one-or-more spaces to | ||||
| // delimit fields. | // delimit fields. | ||||
| $parts = preg_split('/\s+/', $line, 5); | $parts = preg_split('/\s+/', $line, 5); | ||||
| if (count($parts) < 5) { | if (count($parts) < 5) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Expected "<mode> <type> <hash> <size>\t<name>", for ls-tree of '. | 'Expected "<mode> <type> <hash> <size>\t<name>", for ls-tree of '. | ||||
| '"%s:%s", got: %s', | '"%s:%s", got: %s', | ||||
| $commit, | $commit, | ||||
| $path, | $path, | ||||
| $line)); | $line)); | ||||
| } | } | ||||
| list($mode, $type, $hash, $size, $name) = $parts; | list($mode, $type, $hash, $size, $full_path) = $parts; | ||||
| $path_result = new DiffusionRepositoryPath(); | $path_result = new DiffusionRepositoryPath(); | ||||
| if ($type == 'tree') { | if ($type == 'tree') { | ||||
| $file_type = DifferentialChangeType::FILE_DIRECTORY; | $file_type = DifferentialChangeType::FILE_DIRECTORY; | ||||
| } else if ($type == 'commit') { | } else if ($type == 'commit') { | ||||
| $file_type = DifferentialChangeType::FILE_SUBMODULE; | $file_type = DifferentialChangeType::FILE_SUBMODULE; | ||||
| $submodules[] = $path_result; | $submodules[] = $path_result; | ||||
| } else { | } else { | ||||
| $mode = intval($mode, 8); | $mode = intval($mode, 8); | ||||
| if (($mode & 0120000) == 0120000) { | if (($mode & 0120000) == 0120000) { | ||||
| $file_type = DifferentialChangeType::FILE_SYMLINK; | $file_type = DifferentialChangeType::FILE_SYMLINK; | ||||
| } else { | } else { | ||||
| $file_type = DifferentialChangeType::FILE_NORMAL; | $file_type = DifferentialChangeType::FILE_NORMAL; | ||||
| } | } | ||||
| } | } | ||||
| $path_result->setFullPath($prefix.$name); | if ($path === null) { | ||||
| $path_result->setPath($name); | $local_path = $full_path; | ||||
| } else { | |||||
| $local_path = basename($full_path); | |||||
| } | |||||
| $path_result->setFullPath($full_path); | |||||
| $path_result->setPath($local_path); | |||||
| $path_result->setHash($hash); | $path_result->setHash($hash); | ||||
| $path_result->setFileType($file_type); | $path_result->setFileType($file_type); | ||||
| $path_result->setFileSize($size); | $path_result->setFileSize($size); | ||||
| if ($count >= $offset) { | if ($count >= $offset) { | ||||
| $results[] = $path_result; | $results[] = $path_result; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 363 Lines • Show Last 20 Lines | |||||