Initial path tree link support
Initial path tree link support

--- a/include/display.git_blob.php
+++ b/include/display.git_blob.php
@@ -11,13 +11,14 @@
  require_once('gitutil.git_get_hash_by_path.php');
  require_once('gitutil.git_cat_file.php');
  require_once('gitutil.git_read_commit.php');
+ require_once('gitutil.git_path_trees.php');
  require_once('util.file_mime.php');
 
 function git_blob($projectroot, $project, $hash, $file, $hashbase)
 {
 	global $gitphp_conf,$tpl;
+	$base = $hashbase ? $hashbase : git_read_head($projectroot . $project);
 	if (!isset($hash) && isset($file)) {
-		$base = $hashbase ? $hashbase : git_read_head($projectroot . $project);
 		$hash = git_get_hash_by_path($projectroot . $project, $base,$file,"blob");
 	}
 	$catout = git_cat_file($projectroot . $project, $hash);
@@ -37,8 +38,10 @@
 		$tpl->display("blob_emptynav.tpl");
 	}
 	$tpl->clear_all_assign();
-	if (isset($file))
-		$tpl->assign("file",$file);
+	$tpl->assign("project",$project);
+	$tpl->assign("hashbase",$base);
+	$paths = git_path_trees($projectroot . $project, $base, $file);
+	$tpl->assign("paths",$paths);
 	$tpl->display("blob_header.tpl");
 
 	if ($gitphp_conf['filemimetype']) {

--- a/include/display.git_tree.php
+++ b/include/display.git_tree.php
@@ -13,6 +13,7 @@
  require_once('gitutil.git_ls_tree.php');
  require_once('gitutil.read_info_ref.php');
  require_once('gitutil.git_read_commit.php');
+ require_once('gitutil.git_path_trees.php');
 
 function git_tree($projectroot,$project,$hash,$file,$hashbase)
 {
@@ -40,8 +41,10 @@
 		$tpl->display("tree_emptynav.tpl");
 	}
 	$tpl->clear_all_assign();
-	if (isset($file))
-		$tpl->assign("filename",$file);
+	$tpl->assign("project",$project);
+	$tpl->assign("hashbase",$hashbase);
+	$paths = git_path_trees($projectroot . $project, $hashbase, $file);
+	$tpl->assign("paths",$paths);
 	$tpl->display("tree_filelist_header.tpl");
 
 	$tok = strtok($lsout,"\0");

--- /dev/null
+++ b/include/gitutil.git_path_tree.php
@@ -1,1 +1,28 @@
+<?php
+/*
+ *  gitutil.git_path_tree.php
+ *  gitphp: A PHP git repository browser
+ *  Component: Git utility - path tree
+ *
+ *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
+ */
 
+require_once('gitutil.git_get_hash_by_path.php');
+
+function git_path_tree($project,$base,$filename)
+{
+	if (strlen($filename) < 1)
+		return null;
+	$path = array();
+	$path['full'] = $filename;
+	$spath = $filename;
+	$spos = strrpos($spath, "/");
+	if ($spos !== false)
+		$spath = substr($spath, $spos+1);
+	$path['short'] = $spath;
+	$path['tree'] = git_get_hash_by_path($project, $base, $filename);
+	return $path;
+}
+
+?>
+

--- /dev/null
+++ b/include/gitutil.git_path_trees.php
@@ -1,1 +1,33 @@
+<?php
+/*
+ *  gitutil.git_path_trees.php
+ *  gitphp: A PHP git repository browser
+ *  Component: Git utility - path trees
+ *
+ *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
+ */
 
+require_once('gitutil.git_path_tree.php');
+require_once('gitutil.git_get_hash_by_path.php');
+
+function git_path_trees($project,$base,$filename)
+{
+	$paths = array();
+	$path = git_path_tree($project,$base,$filename);
+	if ($path != null)
+		$paths[] = $path;
+	$pos = strrpos($filename, "/");
+	while ($pos !== false) {
+		$filename = substr($filename,0,$pos);
+		
+		$path = git_path_tree($project, $base, $filename);
+		if ($path != null)
+			$paths[] = $path;
+
+		$pos = strrpos($filename, "/");
+	}
+	return array_reverse($paths);
+}
+
+?>
+

--- a/templates/blob_header.tpl
+++ b/templates/blob_header.tpl
@@ -5,8 +5,6 @@
  *
  *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
  *}
- {if $file}
- <div class="page_path"><b>{$file}</b></div>
- {/if}
+ <div class="page_path"><b><a href="{$SCRIPT_NAME}?p={$project}&a=tree&hb={$hashbase}&h={$hashbase}">[{$project}]</a> / {foreach from=$paths item=path name=paths}{if $smarty.foreach.paths.last}<a href="{$SCRIPT_NAME}?p={$project}&a=blob_plain&h={$path.tree}&f={$path.full}">{$path.short}</a>{else}<a href="{$SCRIPT_NAME}?p={$project}&a=tree&hb={$hashbase}&h={$path.tree}&f={$path.full}">{$path.short}</a> / {/if}{/foreach}</b></div>
  <div class="page_body">
 

--- a/templates/tree_filelist_header.tpl
+++ b/templates/tree_filelist_header.tpl
@@ -5,7 +5,7 @@
  *
  *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
  *}
- <div class="page_path"><b>/{$filename}</b></div>
+ <div class="page_path"><b><a href="{$SCRIPT_NAME}?p={$project}&a=tree&hb={$hashbase}&h={$hashbase}">[{$project}]</a> / {foreach from=$paths item=path}<a href="{$SCRIPT_NAME}?p={$project}&a=tree&hb={$hashbase}&h={$path.tree}&f={$path.full}">{$path.short}</a> / {/foreach}</b></div>
  <div class="page_body">
  <table cellspacing="0">
 

comments