From 358f53c2aaed434e6f10fa1b518af8a56446acb4 Mon Sep 17 00:00:00 2001 From: Heikki Hokkanen Date: Sat, 3 May 2008 19:38:04 +0300 Subject: [PATCH] Added crude tree page. --- index.php | 23 ++++++++++++++++++++++- templates/tree.php | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 templates/tree.php diff --git a/index.php b/index.php index ff77a93..bb2b303 100644 --- a/index.php +++ b/index.php @@ -74,6 +74,20 @@ function git_get_rev_list($project) return run_git($project, 'git-rev-list HEAD'); } +function git_ls_tree($project, $tree) +{ + $entries = array(); + $output = run_git($project, "git-ls-tree $tree"); + // 100644 blob 493b7fc4296d64af45dac64bceac2d9a96c958c1 .gitignore + // 040000 tree 715c78b1011dc58106da2a1af2fe0aa4c829542f doc + foreach ($output as $line) { + $parts = preg_split('/\s+/', $line, 4); + $entries[] = array('name' => $parts[3], 'mode' => $parts[0], 'type' => $parts[1], 'hash' => $parts[2]); + } + + return $entries; +} + function makelink($dict) { $params = array(); @@ -118,7 +132,7 @@ if ($action === 'index') { elseif ($action === 'commit') { $template = 'commit'; $page['project'] = strtolower($_REQUEST['p']); // TODO validate - $page['commit_id'] = strtolower($_REQUEST['h']); + $page['commit_id'] = strtolower($_REQUEST['h']); // TODO validate $info = git_get_commit_info($page['project'], $page['commit_id']); @@ -162,6 +176,13 @@ elseif ($action === 'summary') { ); } } +elseif ($action === 'tree') { + $template = 'tree'; + $page['project'] = strtolower($_REQUEST['p']); // TODO validate + $page['tree'] = $_REQUEST['h']; // TODO validate + + $page['entries'] = git_ls_tree($page['project'], $page['tree']); +} else { die('Invalid action'); } diff --git a/templates/tree.php b/templates/tree.php new file mode 100644 index 0000000..5c5814a --- /dev/null +++ b/templates/tree.php @@ -0,0 +1,18 @@ +

Tree for project

+ +
+ 'blob', 'p' => $page['project'], 'h' => $e['hash'])) ."\">$e[name]";
+	}
+	else {
+		echo " 'tree', 'p' => $page['project'], 'h' => $e['hash'])) ."\">$e[name]/";
+	}
+	
+	echo "\n";
+}
+?>
+
+ -- 2.11.4.GIT