Properly pipe git_history_list
Properly pipe git_history_list

<?php <?php
/* /*
* display.git_history.php * display.git_history.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Display - history * Component: Display - history
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
include_once('gitutil.git_get_hash_by_path.php'); include_once('gitutil.git_get_hash_by_path.php');
include_once('gitutil.git_read_head.php'); include_once('gitutil.git_read_head.php');
include_once('gitutil.git_read_commit.php'); include_once('gitutil.git_read_commit.php');
include_once('gitutil.read_info_ref.php'); include_once('gitutil.read_info_ref.php');
include_once('gitutil.git_history_list.php'); include_once('gitutil.git_history_list.php');
   
function git_history($projectroot,$project,$hash,$file) function git_history($projectroot,$project,$hash,$file)
{ {
global $tpl; global $tpl;
if (!isset($hash)) if (!isset($hash))
$hash = git_read_head($projectroot . $project); $hash = git_read_head($projectroot . $project);
$co = git_read_commit($projectroot . $project, $hash); $co = git_read_commit($projectroot . $project, $hash);
$refs = read_info_ref($projectroot . $project); $refs = read_info_ref($projectroot . $project);
$tpl->clear_all_assign(); $tpl->clear_all_assign();
$tpl->assign("project",$project); $tpl->assign("project",$project);
$tpl->assign("hash",$hash); $tpl->assign("hash",$hash);
$tpl->assign("tree",$co['tree']); $tpl->assign("tree",$co['tree']);
$tpl->display("history_nav.tpl"); $tpl->display("history_nav.tpl");
$tpl->assign("title",$co['title']); $tpl->assign("title",$co['title']);
$tpl->assign("file",$file); $tpl->assign("file",$file);
$tpl->display("history_header.tpl"); $tpl->display("history_header.tpl");
$cmdout = git_history_list($projectroot . $project, $hash, $file); $cmdout = git_history_list($projectroot . $project, $hash, $file);
$alternate = FALSE; $alternate = FALSE;
foreach ($cmdout as $i => $line) { $lines = explode("\n", $cmdout);
  foreach ($lines as $i => $line) {
if (ereg("^([0-9a-fA-F]{40})",$line,$regs)) if (ereg("^([0-9a-fA-F]{40})",$line,$regs))
$commit = $regs[1]; $commit = $regs[1];
else if (ereg(":([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$",$line,$regs) && isset($commit)) { else if (ereg(":([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$",$line,$regs) && isset($commit)) {
$co = git_read_commit($projectroot . $project, $commit); $co = git_read_commit($projectroot . $project, $commit);
$tpl->clear_all_assign(); $tpl->clear_all_assign();
if ($alternate) if ($alternate)
$tpl->assign("class","dark"); $tpl->assign("class","dark");
else else
$tpl->assign("class","light"); $tpl->assign("class","light");
$alternate = !$alternate; $alternate = !$alternate;
$tpl->assign("project",$project); $tpl->assign("project",$project);
$tpl->assign("agestringage",$co['age_string_age']); $tpl->assign("agestringage",$co['age_string_age']);
$tpl->assign("agestringdate",$co['age_string_date']); $tpl->assign("agestringdate",$co['age_string_date']);
$tpl->assign("authorname",$co['author_name']); $tpl->assign("authorname",$co['author_name']);
$tpl->assign("commit",$commit); $tpl->assign("commit",$commit);
$tpl->assign("file",$file); $tpl->assign("file",$file);
$tpl->assign("title",$co['title_short']); $tpl->assign("title",$co['title_short']);
if (isset($refs[$commit])) if (isset($refs[$commit]))
$tpl->assign("commitref",$refs[$commit]); $tpl->assign("commitref",$refs[$commit]);
$blob = git_get_hash_by_path($projectroot . $project, $hash,$file); $blob = git_get_hash_by_path($projectroot . $project, $hash,$file);
$blob_parent = git_get_hash_by_path($projectroot . $project, $commit,$file); $blob_parent = git_get_hash_by_path($projectroot . $project, $commit,$file);
if ($blob && $blob_parent && ($blob != $blob_parent)) { if ($blob && $blob_parent && ($blob != $blob_parent)) {
$tpl->assign("blob",$blob); $tpl->assign("blob",$blob);
$tpl->assign("blobparent",$blob_parent); $tpl->assign("blobparent",$blob_parent);
$tpl->assign("difftocurrent",TRUE); $tpl->assign("difftocurrent",TRUE);
} }
$tpl->display("history_item.tpl"); $tpl->display("history_item.tpl");
unset($commit); unset($commit);
} }
} }
$tpl->clear_all_assign(); $tpl->clear_all_assign();
$tpl->display("history_footer.tpl"); $tpl->display("history_footer.tpl");
} }
   
?> ?>
   
<?php <?php
/* /*
* gitutil.git_history_list.php * gitutil.git_history_list.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Git utility - history list * Component: Git utility - history list
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
include_once('defs.commands.php'); include_once('defs.commands.php');
include_once('gitutil.git_exec.php'); include_once('gitutil.git_exec.php');
   
function git_history_list($proj,$hash,$file) function git_history_list($proj,$hash,$file)
{ {
$list = array(); global $gitphp_conf;
$cmd = GIT_REV_LIST . " " . $hash; $cmd = GIT_REV_LIST . " " . $hash . " | " . $gitphp_conf['gitbin'] . " --git-dir=" . $proj . " " . GIT_DIFF_TREE . " -r --stdin -- " . $file;
$out = git_exec($proj, $cmd); return git_exec($proj, $cmd);
$outlist = explode("\n",$out);  
foreach ($outlist as $i => $line) {  
$out2 = git_exec($proj, GIT_DIFF_TREE . " -r " . $line . " '" . $file . "'");  
$out2list = explode("\n",$out2);  
$list = array_merge($list, $out2list);  
}  
return $list;  
} }
   
?> ?>
   
comments