Add blobdiff and blobdiff_plain support
Add blobdiff and blobdiff_plain support

--- a/gitphp.lib.php
+++ b/gitphp.lib.php
@@ -1103,7 +1103,7 @@
 	global $tpl,$gitphp_conf;
 	$head = git_read_head($projectroot . $project);
 	$revlist = git_read_revlist($projectroot . $project, $head, 150);
-	header("Content-type: text/xml; charset=utf-8");
+	header("Content-type: text/xml; charset=UTF-8");
 	$tpl->clear_all_assign();
 	$tpl->assign("self",$gitphp_conf['self']);
 	$tpl->assign("project",$project);
@@ -1199,5 +1199,53 @@
 	echo shell_exec("env GIT_DIR=" . $projectroot . $project . " " . $gitphp_conf['gitbin'] . "git-cat-file blob " . $hash);
 }
 
+function git_blobdiff($projectroot,$project,$hash,$hashbase,$hashparent,$file)
+{
+	global $gitphp_conf,$tpl;
+	$ret = prep_tmpdir($gitphp_conf['gittmp']);
+	if ($ret !== TRUE) {
+		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->assign("tree",$co['tree']);
+		$tpl->assign("title",$co['title']);
+		$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);
+	$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");
+}
+
+function git_blobdiff_plain($projectroot,$project,$hash,$hashbase,$hashparent)
+{
+	global $gitphp_conf;
+	$ret = prep_tmpdir($gitphp_conf['gittmp']);
+	if ($ret !== TRUE) {
+		echo $ret;
+		return;
+	}
+	header("Content-type: text/plain; charset=UTF-8");
+	git_diff_print($projectroot . $project, $hashparent,($file?$file:$hashparent),$hash,($file?$file:$hash),"plain");
+}
+
 ?>
 

file:a/index.php -> file:b/index.php
--- a/index.php
+++ b/index.php
@@ -98,6 +98,13 @@
 					$suppress_headers = TRUE;
 					git_blob_plain($gitphp_conf['projectroot'],$_GET['p'],$_GET['h'],$_GET['f']);
 					break;
+				case "blobdiff":
+					git_blobdiff($gitphp_conf['projectroot'],$_GET['p'],$_GET['h'],$_GET['hb'],$_GET['hp'],$_GET['f']);
+					break;
+				case "blobdiff_plain":
+					$suppress_headers = TRUE;
+					git_blobdiff_plain($gitphp_conf['projectroot'],$_GET['p'],$_GET['h'],$_GET['hb'],$_GET['hp'],$_GET['f']);
+					break;
 				default:
 					echo "Unknown action";
 					break;

--- /dev/null
+++ b/templates/blobdiff_emptynav.tpl
@@ -1,1 +1,26 @@
+{*
+ *  blobdiff_emptynav.tpl
+ *  gitphp: A PHP git repository browser
+ *  Component: Blobdiff view emptynav template
+ *
+ *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *}
+ <div class="page_nav">
+ <br /><br />
+ </div>
+ <div class="title">{$hash} vs {$hashparent}</div>
 

--- /dev/null
+++ b/templates/blobdiff_footer.tpl
@@ -1,1 +1,23 @@
+{*
+ *  blobdiff_footer.tpl
+ *  gitphp: A PHP git repository browser
+ *  Component: Blobdiff view footer template
+ *
+ *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *}
+ </div>
 

--- /dev/null
+++ b/templates/blobdiff_header.tpl
@@ -1,1 +1,27 @@
+{*
+ *  blobdiff_header.tpl
+ *  gitphp: A PHP git repository browser
+ *  Component: Blobdiff view header template
+ *
+ *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *}
+ {if $file}
+ <div class="page_path"><b>/{$file}</b></div>
+ {/if}
+ <div class="page_body">
+ <div class="diff_info">blob:<a href="{$SCRIPT_NAME}?p={$project}&a=blob&h={$hashparent}&hb={$hashbase}&f={$file}">{$hashparent}</a> -&gt; blob:<a href="{$SCRIPT_NAME}?p={$project}&a=blob&h={$hash}&hb={$hashbase}&f={$file}">{$hash}</a></div>
 

--- /dev/null
+++ b/templates/blobdiff_nav.tpl
@@ -1,1 +1,27 @@
+{*
+ *  blobdiff_nav.tpl
+ *  gitphp: A PHP git repository browser
+ *  Component: Blobdiff view nav template
+ *
+ *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *}
+ <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}">plain</a>
+ </div>
+ <div><a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hashbase}" class="title">{$title}</a></div>
 

comments