Differential D18831 Diff 45186 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 46 Lines • ▼ Show 20 Lines | if ($path == '') { | ||||
| $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:%s', | ||||
| $commit, | $commit, | ||||
| $path); | $path); | ||||
| } catch (CommandException $e) { | } catch (CommandException $e) { | ||||
| // 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 | |||||
| // produce either "Not a valid object name" or "could not get object | |||||
| // info". | |||||
| // 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". | |||||
| list($sub_err, $sub_stdout) = $repository->execLocalCommand( | |||||
| 'ls-tree %s -- %s', | |||||
| $commit, | |||||
| $path); | |||||
| if (!$sub_err) { | |||||
| // If the path failed "cat-file" but "ls-tree" worked, we assume it | |||||
| // must be a submodule. If it is, the output will look something | |||||
| // like this: | |||||
| // | |||||
| // 160000 commit <hash> <path> | |||||
| // | |||||
| // We make sure it has the 160000 mode mask to confirm that it's | |||||
| // definitely a submodule. | |||||
| $mode = (int)$sub_stdout; | |||||
| if ($mode & 160000) { | |||||
| $submodule_reason = DiffusionBrowseResultSet::REASON_IS_SUBMODULE; | |||||
| $result | |||||
| ->setReasonForEmptyResultSet($submodule_reason); | |||||
| return $result; | |||||
| } | |||||
| } | |||||
| $stderr = $e->getStderr(); | $stderr = $e->getStderr(); | ||||
| if (preg_match('/^fatal: Not a valid object name/', $stderr)) { | if (preg_match('/^fatal: Not a valid object name/', $stderr)) { | ||||
| // Grab two logs, since the first one is when the object was deleted. | // Grab two logs, since the first one is when the object was deleted. | ||||
| list($stdout) = $repository->execxLocalCommand( | list($stdout) = $repository->execxLocalCommand( | ||||
| 'log -n2 --format="%%H" %s -- %s', | 'log -n2 --format="%%H" %s -- %s', | ||||
| $commit, | $commit, | ||||
| $path); | $path); | ||||
| $stdout = trim($stdout); | $stdout = trim($stdout); | ||||
| ▲ Show 20 Lines • Show All 454 Lines • Show Last 20 Lines | |||||