Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git
new/index.php
$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';

Adds tree walking for directories

Author Dave Jarvis <email>
Date 2026-02-08 16:53:59 GMT-0800
Commit 017554fd0b0bcffee7a84a79044431a512cfed26
Parent 2c0dc88
Delta 19 lines added, 20 lines removed, 1-line decrease