| | $treeEntries = []; |
| | |
| | - if (!$hash) { |
| | - $git->walk($targetHash, function($entry) use (&$treeEntries) { |
| | - $treeEntries[] = (array)$entry; |
| | - }); |
| | + // Unified logic: Try to walk (works for Root and Subdir trees) |
| | + $git->walk($targetHash, function($entry) use (&$treeEntries) { |
| | + $e = (array)$entry; |
| | + // Git::walk provides 'sha', View expects 'hash' |
| | + $e['hash'] = $e['sha']; |
| | + // Normalize type for view |
| | + $e['type'] = $e['isDir'] ? 'tree' : 'blob'; |
| | + $treeEntries[] = $e; |
| | + }); |
| | |
| | + // If we have entries, it is a directory (Tree) |
| | + if (!empty($treeEntries)) { |
| | + $viewType = 'tree'; |
| | usort($treeEntries, function($a, $b) { |
| | if ($a['isDir'] !== $b['isDir']) return $a['isDir'] ? -1 : 1; |
| | return strcasecmp($a['name'], $b['name']); |
| | }); |
| | - |
| | - foreach ($treeEntries as &$e) { $e['type'] = $e['isDir'] ? 'tree' : 'blob'; } |
| | - |
| | - } else { |
| | - $content = null; |
| | - $git->stream($targetHash, function($data) use (&$content) { |
| | - $content = $data; |
| | + } |
| | + // If no entries and we have a specific hash, it is likely a file (Blob) |
| | + elseif ($hash) { |
| | + $viewType = 'blob'; |
| | + $git->stream($targetHash, function($data) use (&$blobContent) { |
| | + $blobContent = $data; |
| | }); |
| | |
| | - if ($content !== null) { |
| | - if (detectType($content) === 'tree') { |
| | - $viewType = 'tree'; |
| | - $treeEntries = parseTreeContent($content); |
| | - } else { |
| | - $viewType = 'blob'; |
| | - $blobContent = $content; |
| | - } |
| | - } else { |
| | + if ($blobContent === null) { |
| | echo '<div class="empty-state">Object not found</div>'; |
| | $viewType = 'error'; |