Unify blobdiff template
Unify blobdiff template

--- a/include/display.git_blobdiff.php
+++ b/include/display.git_blobdiff.php
@@ -11,7 +11,7 @@
  require_once('gitutil.git_read_commit.php');
  require_once('gitutil.read_info_ref.php');
  require_once('gitutil.git_path_trees.php');
- require_once('display.git_diff_print.php');
+ require_once('gitutil.git_diff.php');
 
 function git_blobdiff($projectroot,$project,$hash,$hashbase,$hashparent,$file)
 {
@@ -21,38 +21,26 @@
 		echo $ret;
 		return;
 	}
-	if (isset($hashbase) && ($co = git_read_commit($projectroot . $project, $hashbase))) {
-		$tpl->clear_all_assign();
-		$tpl->assign("project",$project);
-		$tpl->assign("hash",$hash);
-		$tpl->assign("hashbase",$hashbase);
-		$tpl->assign("hashparent",$hashparent);
+	$tpl->clear_all_assign();
+	$tpl->assign("hash",$hash);
+	$tpl->assign("hashparent",$hashparent);
+	$tpl->assign("hashbase",$hashbase);
+	$tpl->assign("project",$project);
+	if (isset($file))
+		$tpl->assign("file",$file);
+	if ($co = git_read_commit($projectroot . $project, $hashbase)) {
+		$tpl->assign("fullnav",TRUE);
 		$tpl->assign("tree",$co['tree']);
 		$tpl->assign("title",$co['title']);
-		$tpl->assign("file",$file);
 		$refs = read_info_ref($projectroot . $project);
 		if (isset($refs[$hashbase]))
 			$tpl->assign("hashbaseref",$refs[$hashbase]);
-		$tpl->display("blobdiff_nav.tpl");
-	} else {
-		$tpl->clear_all_assign();
-		$tpl->assign("hash",$hash);
-		$tpl->assign("hashparent",$hashparent);
-		$tpl->display("blobdiff_emptynav.tpl");
 	}
-	$tpl->clear_all_assign();
-	if (isset($file))
-		$tpl->assign("file",$file);
-	$tpl->assign("project",$project);
-	$tpl->assign("hashparent",$hashparent);
-	$tpl->assign("hashbase",$hashbase);
-	$tpl->assign("hash",$hash);
 	$paths = git_path_trees($projectroot . $project, $hashbase, $file);
 	$tpl->assign("paths",$paths);
-	$tpl->display("blobdiff_header.tpl");
-	git_diff_print($projectroot . $project, $hashparent,($file?$file:$hashparent),$hash,($file?$file:$hash));
-	$tpl->clear_all_assign();
-	$tpl->display("blobdiff_footer.tpl");
+	$diffout = explode("\n",git_diff($projectroot . $project, $hashparent,($file?$file:$hashparent),$hash,($file?$file:$hash)));
+	$tpl->assign("diff",$diffout);
+	$tpl->display("blobdiff.tpl");
 }
 
 ?>

--- /dev/null
+++ b/templates/blobdiff.tpl
@@ -1,1 +1,50 @@
+{*
+ *  blobdiff.tpl
+ *  gitphp: A PHP git repository browser
+ *  Component: Blobdiff view template
+ *
+ *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
+ *}
+ {* If we managed to look up commit info, we have enough info to display the full header - othewise just use a simple header *}
+ <div class="page_nav">
+   {if $fullnav}
+     <a href="{$SCRIPT_NAME}?p={$project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=shortlog">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=log">log</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hashbase}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$hashbase}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$tree}&hb={$hashbase}">tree</a>
+     <br />
+     <a href="{$SCRIPT_NAME}?p={$project}&a=blobdiff_plain&h={$hash}&hp={$hashparent}&f={$file}">plain</a>
+   {else}
+     <br /><br />
+   {/if}
+ </div>
+ <div class="title">
+   {if $fullnav}
+     <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hashbase}" class="title">{$title}
+       {if $hashbaseref}
+         <span class="tag">{$hashbaseref}</span>
+       {/if}
+     </a>
+   {else}
+     {$hash} vs {$hashparent}
+   {/if}
+ </div>
+ <div class="page_path">
+   {* The path to the file, with directories broken into tree links *}
+   <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&h={$path.tree}&hb={$hashbase}&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">
+   <div class="diff_info">
+     {* Display the from -> to diff header *}
+     blob:<a href="{$SCRIPT_NAME}?p={$project}&a=blob&h={$hashparent}&hb={$hashbase}&f={$file}">{if $file}a/{$file}{else}{$hashparent}{/if}</a> -&gt; blob:<a href="{$SCRIPT_NAME}?p={$project}&a=blob&h={$hash}&hb={$hashbase}&f={$file}">{if $file}b/{$file}{else}{$hash}{/if}</a>
+   </div>
+   {* Display the diff *}
+   {include file='filediff.tpl'}
+ </div>
 

--- a/templates/blobdiff_emptynav.tpl
+++ /dev/null
@@ -1,12 +1,1 @@
-{*
- *  blobdiff_emptynav.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Blobdiff view emptynav template
- *
- *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
- *}
- <div class="page_nav">
- <br /><br />
- </div>
- <div class="title">{$hash} vs {$hashparent}</div>
 

--- a/templates/blobdiff_footer.tpl
+++ /dev/null
@@ -1,9 +1,1 @@
-{*
- *  blobdiff_footer.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Blobdiff view footer template
- *
- *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
- *}
- </div>
 

--- a/templates/blobdiff_header.tpl
+++ /dev/null
@@ -1,11 +1,1 @@
-{*
- *  blobdiff_header.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Blobdiff view header template
- *
- *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
- *}
- <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&h={$path.tree}&hb={$hashbase}&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">
- <div class="diff_info">blob:<a href="{$SCRIPT_NAME}?p={$project}&a=blob&h={$hashparent}&hb={$hashbase}&f={$file}">{if $file}a/{$file}{else}{$hashparent}{/if}</a> -&gt; blob:<a href="{$SCRIPT_NAME}?p={$project}&a=blob&h={$hash}&hb={$hashbase}&f={$file}">{if $file}b/{$file}{else}{$hash}{/if}</a></div>
 

--- a/templates/blobdiff_nav.tpl
+++ /dev/null
@@ -1,17 +1,1 @@
-{*
- *  blobdiff_nav.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Blobdiff view nav template
- *
- *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
- *}
- <div class="page_nav">
- <a href="{$SCRIPT_NAME}?p={$project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=shortlog">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=log">log</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hashbase}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$hashbase}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$tree}&hb={$hashbase}">tree</a><br />
- <a href="{$SCRIPT_NAME}?p={$project}&a=blobdiff_plain&h={$hash}&hp={$hashparent}&f={$file}">plain</a>
- </div>
- <div><a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hashbase}" class="title">{$title}
- {if $hashbaseref}
- <span class="tag">{$hashbaseref}</span>
- {/if}
- </a></div>
 

--- /dev/null
+++ b/templates/filediff.tpl
@@ -1,1 +1,21 @@
+{*
+ *  filediff.tpl
+ *  gitphp: A PHP git repository browser
+ *  Component: Single file diff template
+ *
+ *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
+ *}
+<div class="pre">
+{foreach from=$diff item=diffline}
+  {if substr($diffline,0,1)=="+"}
+    <span class="diffplus">{$diffline|escape:'htmlall'}</span>
+  {elseif substr($diffline,0,1)=="-"}
+    <span class="diffminus">{$diffline|escape:'htmlall'}</span>
+  {elseif substr($diffline,0,1)=="@"}
+    <span class="diffat">{$diffline|escape:'htmlall'}</span>
+  {else}
+    <span>{$diffline|escape:'htmlall'}</span>
+  {/if}
+{/foreach}
+</div>
 

comments