Changed all ereg references to preg_match("/regex/"... and eregi references to preg_match("/regex/i" to prevent php 5.3.0 from complaining
Changed all ereg references to preg_match("/regex/"... and eregi references to preg_match("/regex/i" to prevent php 5.3.0 from complaining

Signed-off-by: Chris Han <xiphux@gmail.com>

<?php <?php
/* /*
* display.git_commit.php * display.git_commit.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Display - commit * Component: Display - commit
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
require_once('util.file_type.php'); require_once('util.file_type.php');
require_once('util.date_str.php'); require_once('util.date_str.php');
require_once('gitutil.git_read_commit.php'); require_once('gitutil.git_read_commit.php');
require_once('gitutil.git_diff_tree.php'); require_once('gitutil.git_diff_tree.php');
require_once('gitutil.read_info_ref.php'); require_once('gitutil.read_info_ref.php');
   
function git_commit($projectroot,$project,$hash) function git_commit($projectroot,$project,$hash)
{ {
global $tpl; global $tpl;
   
$cachekey = sha1($project) . "|" . $hash; $cachekey = sha1($project) . "|" . $hash;
   
if (!$tpl->is_cached('commit.tpl', $cachekey)) { if (!$tpl->is_cached('commit.tpl', $cachekey)) {
$co = git_read_commit($projectroot . $project, $hash); $co = git_read_commit($projectroot . $project, $hash);
$ad = date_str($co['author_epoch'],$co['author_tz']); $ad = date_str($co['author_epoch'],$co['author_tz']);
$cd = date_str($co['committer_epoch'],$co['committer_tz']); $cd = date_str($co['committer_epoch'],$co['committer_tz']);
if (isset($co['parent'])) { if (isset($co['parent'])) {
$root = ""; $root = "";
$parent = $co['parent']; $parent = $co['parent'];
} else { } else {
$root = "--root"; $root = "--root";
$parent = ""; $parent = "";
} }
$diffout = git_diff_tree($projectroot . $project, $root . " " . $parent . " " . $hash, TRUE); $diffout = git_diff_tree($projectroot . $project, $root . " " . $parent . " " . $hash, TRUE);
$difftree = explode("\n",$diffout); $difftree = explode("\n",$diffout);
$tpl->assign("hash",$hash); $tpl->assign("hash",$hash);
$tpl->assign("tree",$co['tree']); $tpl->assign("tree",$co['tree']);
if (isset($co['parent'])) if (isset($co['parent']))
$tpl->assign("parent",$co['parent']); $tpl->assign("parent",$co['parent']);
$tpl->assign("title",$co['title']); $tpl->assign("title",$co['title']);
$refs = read_info_ref($projectroot . $project); $refs = read_info_ref($projectroot . $project);
if (isset($refs[$co['id']])) if (isset($refs[$co['id']]))
$tpl->assign("commitref",$refs[$co['id']]); $tpl->assign("commitref",$refs[$co['id']]);
$tpl->assign("author",$co['author']); $tpl->assign("author",$co['author']);
$tpl->assign("adrfc2822",$ad['rfc2822']); $tpl->assign("adrfc2822",$ad['rfc2822']);
$tpl->assign("adhourlocal",$ad['hour_local']); $tpl->assign("adhourlocal",$ad['hour_local']);
$tpl->assign("adminutelocal",$ad['minute_local']); $tpl->assign("adminutelocal",$ad['minute_local']);
$tpl->assign("adtzlocal",$ad['tz_local']); $tpl->assign("adtzlocal",$ad['tz_local']);
$tpl->assign("committer",$co['committer']); $tpl->assign("committer",$co['committer']);
$tpl->assign("cdrfc2822",$cd['rfc2822']); $tpl->assign("cdrfc2822",$cd['rfc2822']);
$tpl->assign("cdhourlocal",$cd['hour_local']); $tpl->assign("cdhourlocal",$cd['hour_local']);
$tpl->assign("cdminutelocal",$cd['minute_local']); $tpl->assign("cdminutelocal",$cd['minute_local']);
$tpl->assign("cdtzlocal",$cd['tz_local']); $tpl->assign("cdtzlocal",$cd['tz_local']);
$tpl->assign("id",$co['id']); $tpl->assign("id",$co['id']);
$tpl->assign("parents",$co['parents']); $tpl->assign("parents",$co['parents']);
$tpl->assign("comment",$co['comment']); $tpl->assign("comment",$co['comment']);
$tpl->assign("difftreesize",count($difftree)+1); $tpl->assign("difftreesize",count($difftree)+1);
$difftreelines = array(); $difftreelines = array();
foreach ($difftree as $i => $line) { foreach ($difftree as $i => $line) {
if (ereg("^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$",$line,$regs)) { if (preg_match("/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/",$line,$regs)) {
$difftreeline = array(); $difftreeline = array();
$difftreeline["from_mode"] = $regs[1]; $difftreeline["from_mode"] = $regs[1];
$difftreeline["to_mode"] = $regs[2]; $difftreeline["to_mode"] = $regs[2];
$difftreeline["from_mode_cut"] = substr($regs[1],-4); $difftreeline["from_mode_cut"] = substr($regs[1],-4);
$difftreeline["to_mode_cut"] = substr($regs[2],-4); $difftreeline["to_mode_cut"] = substr($regs[2],-4);
$difftreeline["from_id"] = $regs[3]; $difftreeline["from_id"] = $regs[3];
$difftreeline["to_id"] = $regs[4]; $difftreeline["to_id"] = $regs[4];
$difftreeline["status"] = $regs[5]; $difftreeline["status"] = $regs[5];
$difftreeline["similarity"] = ltrim($regs[6],"0"); $difftreeline["similarity"] = ltrim($regs[6],"0");
$difftreeline["file"] = $regs[7]; $difftreeline["file"] = $regs[7];
$difftreeline["from_file"] = strtok($regs[7],"\t"); $difftreeline["from_file"] = strtok($regs[7],"\t");
$difftreeline["from_filetype"] = file_type($regs[1]); $difftreeline["from_filetype"] = file_type($regs[1]);
$difftreeline["to_file"] = strtok("\t"); $difftreeline["to_file"] = strtok("\t");
$difftreeline["to_filetype"] = file_type($regs[2]); $difftreeline["to_filetype"] = file_type($regs[2]);
if ((octdec($regs[2]) & 0x8000) == 0x8000) if ((octdec($regs[2]) & 0x8000) == 0x8000)
$difftreeline["isreg"] = TRUE; $difftreeline["isreg"] = TRUE;
$modestr = ""; $modestr = "";
if ((octdec($regs[1]) & 0x17000) != (octdec($regs[2]) & 0x17000)) if ((octdec($regs[1]) & 0x17000) != (octdec($regs[2]) & 0x17000))
$modestr .= " from " . file_type($regs[1]) . " to " . file_type($regs[2]); $modestr .= " from " . file_type($regs[1]) . " to " . file_type($regs[2]);
if ((octdec($regs[1]) & 0777) != (octdec($regs[2]) & 0777)) { if ((octdec($regs[1]) & 0777) != (octdec($regs[2]) & 0777)) {
if ((octdec($regs[1]) & 0x8000) && (octdec($regs[2]) & 0x8000)) if ((octdec($regs[1]) & 0x8000) && (octdec($regs[2]) & 0x8000))
$modestr .= " mode: " . (octdec($regs[1]) & 0777) . "->" . (octdec($regs[2]) & 0777); $modestr .= " mode: " . (octdec($regs[1]) & 0777) . "->" . (octdec($regs[2]) & 0777);
else if (octdec($regs[2]) & 0x8000) else if (octdec($regs[2]) & 0x8000)
$modestr .= " mode: " . (octdec($regs[2]) & 0777); $modestr .= " mode: " . (octdec($regs[2]) & 0777);
} }
$difftreeline["modechange"] = $modestr; $difftreeline["modechange"] = $modestr;
$simmodechg = ""; $simmodechg = "";
if ($regs[1] != $regs[2]) if ($regs[1] != $regs[2])
$simmodechg .= ", mode: " . (octdec($regs[2]) & 0777); $simmodechg .= ", mode: " . (octdec($regs[2]) & 0777);
$difftreeline["simmodechg"] = $simmodechg; $difftreeline["simmodechg"] = $simmodechg;
$difftreelines[] = $difftreeline; $difftreelines[] = $difftreeline;
} }
} }
$tpl->assign("difftreelines",$difftreelines); $tpl->assign("difftreelines",$difftreelines);
} }
$tpl->display('commit.tpl', $cachekey); $tpl->display('commit.tpl', $cachekey);
} }
   
?> ?>
   
<?php <?php
/* /*
* display.git_commitdiff.php * display.git_commitdiff.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Display - commit diff * Component: Display - commit diff
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
require_once('util.file_type.php'); require_once('util.file_type.php');
require_once('util.prep_tmpdir.php'); require_once('util.prep_tmpdir.php');
require_once('gitutil.git_read_commit.php'); require_once('gitutil.git_read_commit.php');
require_once('gitutil.git_diff_tree.php'); require_once('gitutil.git_diff_tree.php');
require_once('gitutil.read_info_ref.php'); require_once('gitutil.read_info_ref.php');
require_once('gitutil.git_diff.php'); require_once('gitutil.git_diff.php');
   
function git_commitdiff($projectroot,$project,$hash,$hash_parent) function git_commitdiff($projectroot,$project,$hash,$hash_parent)
{ {
global $tpl; global $tpl;
   
$cachekey = sha1($project) . "|" . $hash . "|" . $hash_parent; $cachekey = sha1($project) . "|" . $hash . "|" . $hash_parent;
   
if (!$tpl->is_cached('commitdiff.tpl', $cachekey)) { if (!$tpl->is_cached('commitdiff.tpl', $cachekey)) {
$ret = prep_tmpdir(); $ret = prep_tmpdir();
if ($ret !== TRUE) { if ($ret !== TRUE) {
echo $ret; echo $ret;
return; return;
} }
$co = git_read_commit($projectroot . $project, $hash); $co = git_read_commit($projectroot . $project, $hash);
if (!isset($hash_parent)) if (!isset($hash_parent))
$hash_parent = $co['parent']; $hash_parent = $co['parent'];
$diffout = git_diff_tree($projectroot . $project, $hash_parent . " " . $hash); $diffout = git_diff_tree($projectroot . $project, $hash_parent . " " . $hash);
$difftree = explode("\n",$diffout); $difftree = explode("\n",$diffout);
$refs = read_info_ref($projectroot . $project); $refs = read_info_ref($projectroot . $project);
$tpl->assign("hash",$hash); $tpl->assign("hash",$hash);
$tpl->assign("tree",$co['tree']); $tpl->assign("tree",$co['tree']);
$tpl->assign("hashparent",$hash_parent); $tpl->assign("hashparent",$hash_parent);
$tpl->assign("title",$co['title']); $tpl->assign("title",$co['title']);
if (isset($refs[$co['id']])) if (isset($refs[$co['id']]))
$tpl->assign("commitref",$refs[$co['id']]); $tpl->assign("commitref",$refs[$co['id']]);
$tpl->assign("comment",$co['comment']); $tpl->assign("comment",$co['comment']);
$difftreelines = array(); $difftreelines = array();
foreach ($difftree as $i => $line) { foreach ($difftree as $i => $line) {
if (ereg("^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$",$line,$regs)) { if (preg_match("/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/",$line,$regs)) {
$difftreeline = array(); $difftreeline = array();
$difftreeline["from_mode"] = $regs[1]; $difftreeline["from_mode"] = $regs[1];
$difftreeline["to_mode"] = $regs[2]; $difftreeline["to_mode"] = $regs[2];
$difftreeline["from_id"] = $regs[3]; $difftreeline["from_id"] = $regs[3];
$difftreeline["to_id"] = $regs[4]; $difftreeline["to_id"] = $regs[4];
$difftreeline["status"] = $regs[5]; $difftreeline["status"] = $regs[5];
$difftreeline["file"] = $regs[6]; $difftreeline["file"] = $regs[6];
$difftreeline["from_type"] = file_type($regs[1]); $difftreeline["from_type"] = file_type($regs[1]);
$difftreeline["to_type"] = file_type($regs[2]); $difftreeline["to_type"] = file_type($regs[2]);
if ($regs[5] == "A") if ($regs[5] == "A")
$difftreeline['diffout'] = explode("\n",git_diff($projectroot . $project, null,"/dev/null",$regs[4],"b/" . $regs[6])); $difftreeline['diffout'] = explode("\n",git_diff($projectroot . $project, null,"/dev/null",$regs[4],"b/" . $regs[6]));
else if ($regs[5] == "D") else if ($regs[5] == "D")
$difftreeline['diffout'] = explode("\n",git_diff($projectroot . $project, $regs[3],"a/" . $regs[6],null,"/dev/null")); $difftreeline['diffout'] = explode("\n",git_diff($projectroot . $project, $regs[3],"a/" . $regs[6],null,"/dev/null"));
else if (($regs[5] == "M") && ($regs[3] != $regs[4])) else if (($regs[5] == "M") && ($regs[3] != $regs[4]))
$difftreeline['diffout'] = explode("\n",git_diff($projectroot . $project, $regs[3],"a/" . $regs[6],$regs[4],"b/" . $regs[6])); $difftreeline['diffout'] = explode("\n",git_diff($projectroot . $project, $regs[3],"a/" . $regs[6],$regs[4],"b/" . $regs[6]));
$difftreelines[] = $difftreeline; $difftreelines[] = $difftreeline;
} }
} }
$tpl->assign("difftreelines",$difftreelines); $tpl->assign("difftreelines",$difftreelines);
} }
$tpl->display('commitdiff.tpl', $cachekey); $tpl->display('commitdiff.tpl', $cachekey);
} }
   
?> ?>
   
<?php <?php
/* /*
* display.git_commitdiff_plain.php * display.git_commitdiff_plain.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Display - commit diff (plaintext) * Component: Display - commit diff (plaintext)
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
require_once('util.prep_tmpdir.php'); require_once('util.prep_tmpdir.php');
require_once('util.date_str.php'); require_once('util.date_str.php');
require_once('util.script_url.php'); require_once('util.script_url.php');
require_once('gitutil.git_read_commit.php'); require_once('gitutil.git_read_commit.php');
require_once('gitutil.git_diff_tree.php'); require_once('gitutil.git_diff_tree.php');
require_once('gitutil.git_read_revlist.php'); require_once('gitutil.git_read_revlist.php');
require_once('gitutil.read_info_ref.php'); require_once('gitutil.read_info_ref.php');
require_once('gitutil.git_diff.php'); require_once('gitutil.git_diff.php');
   
function git_commitdiff_plain($projectroot,$project,$hash,$hash_parent) function git_commitdiff_plain($projectroot,$project,$hash,$hash_parent)
{ {
global $tpl; global $tpl;
   
$cachekey = sha1($project) . "|" . $hash . "|" . $hash_parent; $cachekey = sha1($project) . "|" . $hash . "|" . $hash_parent;
   
header("Content-type: text/plain; charset=UTF-8"); header("Content-type: text/plain; charset=UTF-8");
header("Content-disposition: inline; filename=\"git-" . $hash . ".patch\""); header("Content-disposition: inline; filename=\"git-" . $hash . ".patch\"");
   
if (!$tpl->is_cached('diff_plaintext.tpl', $cachekey)) { if (!$tpl->is_cached('diff_plaintext.tpl', $cachekey)) {
$ret = prep_tmpdir(); $ret = prep_tmpdir();
if ($ret !== TRUE) { if ($ret !== TRUE) {
echo $ret; echo $ret;
return; return;
} }
$co = git_read_commit($projectroot . $project, $hash); $co = git_read_commit($projectroot . $project, $hash);
if (!isset($hash_parent)) if (!isset($hash_parent))
$hash_parent = $co['parent']; $hash_parent = $co['parent'];
$diffout = git_diff_tree($projectroot . $project, $hash_parent . " " . $hash); $diffout = git_diff_tree($projectroot . $project, $hash_parent . " " . $hash);
$difftree = explode("\n",$diffout); $difftree = explode("\n",$diffout);
$refs = read_info_ref($projectroot . $project,"tags"); $refs = read_info_ref($projectroot . $project,"tags");
$listout = git_read_revlist($projectroot . $project, "HEAD"); $listout = git_read_revlist($projectroot . $project, "HEAD");
foreach ($listout as $i => $rev) { foreach ($listout as $i => $rev) {
if (isset($refs[$rev])) if (isset($refs[$rev]))
$tagname = $refs[$rev]; $tagname = $refs[$rev];
if ($rev == $hash) if ($rev == $hash)
break; break;
} }
$ad = date_str($co['author_epoch'],$co['author_tz']); $ad = date_str($co['author_epoch'],$co['author_tz']);
$tpl->assign("from",$co['author']); $tpl->assign("from",$co['author']);
$tpl->assign("date",$ad['rfc2822']); $tpl->assign("date",$ad['rfc2822']);
$tpl->assign("subject",$co['title']); $tpl->assign("subject",$co['title']);
if (isset($tagname)) if (isset($tagname))
$tpl->assign("tagname",$tagname); $tpl->assign("tagname",$tagname);
$tpl->assign("url",script_url() . "?p=" . $project . "&a=commitdiff&h=" . $hash); $tpl->assign("url",script_url() . "?p=" . $project . "&a=commitdiff&h=" . $hash);
$tpl->assign("comment",$co['comment']); $tpl->assign("comment",$co['comment']);
$diffs = array(); $diffs = array();
foreach ($difftree as $i => $line) { foreach ($difftree as $i => $line) {
if (ereg("^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$",$line,$regs)) { if (preg_match("/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/",$line,$regs)) {
if ($regs[5] == "A") if ($regs[5] == "A")
$diffs[] = git_diff($projectroot . $project, null, "/dev/null", $regs[4], "b/" . $regs[6]); $diffs[] = git_diff($projectroot . $project, null, "/dev/null", $regs[4], "b/" . $regs[6]);
else if ($regs[5] == "D") else if ($regs[5] == "D")
$diffs[] = git_diff($projectroot . $project, $regs[3], "a/" . $regs[6], null, "/dev/null"); $diffs[] = git_diff($projectroot . $project, $regs[3], "a/" . $regs[6], null, "/dev/null");
else if ($regs[5] == "M") else if ($regs[5] == "M")
$diffs[] = git_diff($projectroot . $project, $regs[3], "a/" . $regs[6], $regs[4], "b/" . $regs[6]); $diffs[] = git_diff($projectroot . $project, $regs[3], "a/" . $regs[6], $regs[4], "b/" . $regs[6]);
} }
} }
$tpl->assign("diffs",$diffs); $tpl->assign("diffs",$diffs);
} }
$tpl->display('diff_plaintext.tpl', $cachekey); $tpl->display('diff_plaintext.tpl', $cachekey);
} }
   
?> ?>
   
<?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>
*/ */
   
require_once('gitutil.git_get_hash_by_path.php'); require_once('gitutil.git_get_hash_by_path.php');
require_once('gitutil.git_read_head.php'); require_once('gitutil.git_read_head.php');
require_once('gitutil.git_read_commit.php'); require_once('gitutil.git_read_commit.php');
require_once('gitutil.read_info_ref.php'); require_once('gitutil.read_info_ref.php');
require_once('gitutil.git_history_list.php'); require_once('gitutil.git_history_list.php');
require_once('gitutil.git_path_trees.php'); require_once('gitutil.git_path_trees.php');
   
function git_history($projectroot,$project,$hash,$file) function git_history($projectroot,$project,$hash,$file)
{ {
global $tpl; global $tpl;
   
$cachekey = sha1($project) . "|" . $hash . "|" . sha1($file); $cachekey = sha1($project) . "|" . $hash . "|" . sha1($file);
   
if (!$tpl->is_cached('history.tpl', $cachekey)) { if (!$tpl->is_cached('history.tpl', $cachekey)) {
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->assign("hash",$hash); $tpl->assign("hash",$hash);
if (isset($refs[$hash])) if (isset($refs[$hash]))
$tpl->assign("hashbaseref",$refs[$hash]); $tpl->assign("hashbaseref",$refs[$hash]);
$tpl->assign("tree",$co['tree']); $tpl->assign("tree",$co['tree']);
$tpl->assign("title",$co['title']); $tpl->assign("title",$co['title']);
$paths = git_path_trees($projectroot . $project, $hash, $file); $paths = git_path_trees($projectroot . $project, $hash, $file);
$tpl->assign("paths",$paths); $tpl->assign("paths",$paths);
$cmdout = git_history_list($projectroot . $project, $hash, $file); $cmdout = git_history_list($projectroot . $project, $hash, $file);
$lines = explode("\n", $cmdout); $lines = explode("\n", $cmdout);
$historylines = array(); $historylines = array();
foreach ($lines as $i => $line) { foreach ($lines as $i => $line) {
if (ereg("^([0-9a-fA-F]{40})",$line,$regs)) if (preg_match("/^([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 (preg_match("/:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/",$line,$regs) && isset($commit)) {
$historyline = array(); $historyline = array();
$co = git_read_commit($projectroot . $project, $commit); $co = git_read_commit($projectroot . $project, $commit);
$historyline["agestringage"] = $co['age_string_age']; $historyline["agestringage"] = $co['age_string_age'];
$historyline["agestringdate"] = $co['age_string_date']; $historyline["agestringdate"] = $co['age_string_date'];
$historyline["authorname"] = $co['author_name']; $historyline["authorname"] = $co['author_name'];
$historyline["commit"] = $commit; $historyline["commit"] = $commit;
$historyline["file"] = $file; $historyline["file"] = $file;
$historyline["title"] = $co['title_short']; $historyline["title"] = $co['title_short'];
if (isset($refs[$commit])) if (isset($refs[$commit]))
$historyline["commitref"] = $refs[$commit]; $historyline["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)) {
$historyline["blob"] = $blob; $historyline["blob"] = $blob;
$historyline["blobparent"] = $blob_parent; $historyline["blobparent"] = $blob_parent;
} }
$historylines[] = $historyline; $historylines[] = $historyline;
unset($commit); unset($commit);
} }
} }
$tpl->assign("historylines",$historylines); $tpl->assign("historylines",$historylines);
} }
$tpl->display('history.tpl', $cachekey); $tpl->display('history.tpl', $cachekey);
} }
   
?> ?>
   
<?php <?php
/* /*
* display.git_rss.php * display.git_rss.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Display - RSS feed * Component: Display - RSS feed
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
require_once('defs.constants.php'); require_once('defs.constants.php');
require_once('util.date_str.php'); require_once('util.date_str.php');
require_once('util.script_url.php'); require_once('util.script_url.php');
require_once('gitutil.git_read_head.php'); require_once('gitutil.git_read_head.php');
require_once('gitutil.git_read_revlist.php'); require_once('gitutil.git_read_revlist.php');
require_once('gitutil.git_read_commit.php'); require_once('gitutil.git_read_commit.php');
require_once('gitutil.git_diff_tree.php'); require_once('gitutil.git_diff_tree.php');
   
function git_rss($projectroot,$project) function git_rss($projectroot,$project)
{ {
global $tpl; global $tpl;
header("Content-type: text/xml; charset=UTF-8"); header("Content-type: text/xml; charset=UTF-8");
   
$cachekey = sha1($project); $cachekey = sha1($project);
   
if (!$tpl->is_cached('rss.tpl', $cachekey)) { if (!$tpl->is_cached('rss.tpl', $cachekey)) {
$head = git_read_head($projectroot . $project); $head = git_read_head($projectroot . $project);
$revlist = git_read_revlist($projectroot . $project, $head, GITPHP_RSS_ITEMS); $revlist = git_read_revlist($projectroot . $project, $head, GITPHP_RSS_ITEMS);
$tpl->assign("self",script_url()); $tpl->assign("self",script_url());
   
$commitlines = array(); $commitlines = array();
for ($i = 0; $i < count($revlist); $i++) { for ($i = 0; $i < count($revlist); $i++) {
$commit = $revlist[$i]; $commit = $revlist[$i];
$co = git_read_commit($projectroot . $project, $commit); $co = git_read_commit($projectroot . $project, $commit);
if (($i >= 20) && ((time() - $co['committer_epoch']) > 48*60*60)) if (($i >= 20) && ((time() - $co['committer_epoch']) > 48*60*60))
break; break;
$cd = date_str($co['committer_epoch']); $cd = date_str($co['committer_epoch']);
$difftree = array(); $difftree = array();
$diffout = git_diff_tree($projectroot . $project, $co['parent'] . " " . $co['id']); $diffout = git_diff_tree($projectroot . $project, $co['parent'] . " " . $co['id']);
$tok = strtok($diffout,"\n"); $tok = strtok($diffout,"\n");
while ($tok !== false) { while ($tok !== false) {
if (ereg("^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$",$tok,$regs)) if (preg_match("/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/",$tok,$regs))
$difftree[] = $regs[7]; $difftree[] = $regs[7];
$tok = strtok("\n"); $tok = strtok("\n");
} }
$commitline = array(); $commitline = array();
$commitline["cdmday"] = $cd['mday']; $commitline["cdmday"] = $cd['mday'];
$commitline["cdmonth"] = $cd['month']; $commitline["cdmonth"] = $cd['month'];
$commitline["cdhour"] = $cd['hour']; $commitline["cdhour"] = $cd['hour'];
$commitline["cdminute"] = $cd['minute']; $commitline["cdminute"] = $cd['minute'];
$commitline["title"] = $co['title']; $commitline["title"] = $co['title'];
$commitline["author"] = $co['author']; $commitline["author"] = $co['author'];
$commitline["cdrfc2822"] = $cd['rfc2822']; $commitline["cdrfc2822"] = $cd['rfc2822'];
$commitline["commit"] = $commit; $commitline["commit"] = $commit;
$commitline["comment"] = $co['comment']; $commitline["comment"] = $co['comment'];
$commitline["difftree"] = $difftree; $commitline["difftree"] = $difftree;
$commitlines[] = $commitline; $commitlines[] = $commitline;
} }
$tpl->assign("commitlines",$commitlines); $tpl->assign("commitlines",$commitlines);
} }
$tpl->display('rss.tpl', $cachekey); $tpl->display('rss.tpl', $cachekey);
} }
   
?> ?>
   
<?php <?php
/* /*
* display.git_tree.php * display.git_tree.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Display - tree * Component: Display - tree
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
require_once('util.mode_str.php'); require_once('util.mode_str.php');
require_once('gitutil.git_read_head.php'); require_once('gitutil.git_read_head.php');
require_once('gitutil.git_get_hash_by_path.php'); require_once('gitutil.git_get_hash_by_path.php');
require_once('gitutil.git_ls_tree.php'); require_once('gitutil.git_ls_tree.php');
require_once('gitutil.read_info_ref.php'); require_once('gitutil.read_info_ref.php');
require_once('gitutil.git_read_commit.php'); require_once('gitutil.git_read_commit.php');
require_once('gitutil.git_path_trees.php'); require_once('gitutil.git_path_trees.php');
   
function git_tree($projectroot,$project,$hash,$file,$hashbase) function git_tree($projectroot,$project,$hash,$file,$hashbase)
{ {
global $tpl; global $tpl;
   
$cachekey = sha1($project) . "|" . $hashbase . "|" . $hash . "|" . sha1($file); $cachekey = sha1($project) . "|" . $hashbase . "|" . $hash . "|" . sha1($file);
   
if (!$tpl->is_cached('tree.tpl', $cachekey)) { if (!$tpl->is_cached('tree.tpl', $cachekey)) {
if (!isset($hash)) { if (!isset($hash)) {
$hash = git_read_head($projectroot . $project); $hash = git_read_head($projectroot . $project);
if (isset($file)) if (isset($file))
$hash = git_get_hash_by_path($projectroot . $project, ($hashbase?$hashbase:$hash),$file,"tree"); $hash = git_get_hash_by_path($projectroot . $project, ($hashbase?$hashbase:$hash),$file,"tree");
if (!isset($hashbase)) if (!isset($hashbase))
$hashbase = $hash; $hashbase = $hash;
} }
$lsout = git_ls_tree($projectroot . $project, $hash, TRUE); $lsout = git_ls_tree($projectroot . $project, $hash, TRUE);
$refs = read_info_ref($projectroot . $project); $refs = read_info_ref($projectroot . $project);
$tpl->assign("hash",$hash); $tpl->assign("hash",$hash);
if (isset($hashbase)) if (isset($hashbase))
$tpl->assign("hashbase",$hashbase); $tpl->assign("hashbase",$hashbase);
if (isset($hashbase) && ($co = git_read_commit($projectroot . $project, $hashbase))) { if (isset($hashbase) && ($co = git_read_commit($projectroot . $project, $hashbase))) {
$basekey = $hashbase; $basekey = $hashbase;
$tpl->assign("fullnav",TRUE); $tpl->assign("fullnav",TRUE);
$tpl->assign("title",$co['title']); $tpl->assign("title",$co['title']);
if (isset($refs[$hashbase])) if (isset($refs[$hashbase]))
$tpl->assign("hashbaseref",$refs[$hashbase]); $tpl->assign("hashbaseref",$refs[$hashbase]);
} }
$paths = git_path_trees($projectroot . $project, $hashbase, $file); $paths = git_path_trees($projectroot . $project, $hashbase, $file);
$tpl->assign("paths",$paths); $tpl->assign("paths",$paths);
   
if (isset($file)) if (isset($file))
$tpl->assign("base",$file . "/"); $tpl->assign("base",$file . "/");
   
$treelines = array(); $treelines = array();
$tok = strtok($lsout,"\0"); $tok = strtok($lsout,"\0");
while ($tok !== false) { while ($tok !== false) {
if (ereg("^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$",$tok,$regs)) { if (preg_match("/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/",$tok,$regs)) {
$treeline = array(); $treeline = array();
$treeline["filemode"] = mode_str($regs[1]); $treeline["filemode"] = mode_str($regs[1]);
$treeline["type"] = $regs[2]; $treeline["type"] = $regs[2];
$treeline["hash"] = $regs[3]; $treeline["hash"] = $regs[3];
$treeline["name"] = $regs[4]; $treeline["name"] = $regs[4];
$treelines[] = $treeline; $treelines[] = $treeline;
} }
$tok = strtok("\0"); $tok = strtok("\0");
} }
$tpl->assign("treelines",$treelines); $tpl->assign("treelines",$treelines);
} }
$tpl->display('tree.tpl', $cachekey); $tpl->display('tree.tpl', $cachekey);
} }
   
?> ?>
   
<?php <?php
/* /*
* gitutil.git_filesearch.php * gitutil.git_filesearch.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Git utility - search files * Component: Git utility - search files
* *
* Copyright (C) 2009 Christopher Han <xiphux@gmail.com> * Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
*/ */
   
require_once('gitutil.git_grep.php'); require_once('gitutil.git_grep.php');
require_once('gitutil.git_ls_tree.php'); require_once('gitutil.git_ls_tree.php');
   
function git_filesearch($project, $hash, $search, $case = false, $skip = 0, $count = 100) function git_filesearch($project, $hash, $search, $case = false, $skip = 0, $count = 100)
{ {
$matches = array(); $matches = array();
/* /*
* Search file contents * Search file contents
*/ */
$grepout = git_grep($project, $hash, $search, $case, false, true); $grepout = git_grep($project, $hash, $search, $case, false, true);
$lines = explode("\n",$grepout); $lines = explode("\n",$grepout);
foreach ($lines as $j => $line) { foreach ($lines as $j => $line) {
if ($case) if ($case)
$ret = ereg("^([^:]+):([^:]+):(.*" . quotemeta($search) . ".*)",$line,$regs); $ret = preg_match("/^([^:]+):([^:]+):(.*" . quotemeta($search) . ".*)/",$line,$regs);
else else
$ret = eregi("^([^:]+):([^:]+):(.*" . quotemeta($search) . ".*)",$line,$regs); $ret = preg_match(("/^([^:]+):([^:]+):(.*" . quotemeta($search) . ".*)/i",$line,$regs);
if ($ret) { if ($ret) {
$fname = trim($regs[2]); $fname = trim($regs[2]);
if (!isset($matches[$fname])) { if (!isset($matches[$fname])) {
$matches[$fname] = array(); $matches[$fname] = array();
$matches[$fname]['lines'] = array(); $matches[$fname]['lines'] = array();
} }
$matches[$fname]['lines'][] = $regs[3]; $matches[$fname]['lines'][] = $regs[3];
} }
} }
   
/* /*
* Search filenames * Search filenames
*/ */
$lsout = git_ls_tree($project, $hash, false, true); $lsout = git_ls_tree($project, $hash, false, true);
$entries = explode("\n",$lsout); $entries = explode("\n",$lsout);
foreach ($entries as $j => $line) { foreach ($entries as $j => $line) {
$ret = ereg("^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)",$line,$regs); $ret = preg_match("/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)/",$line,$regs);
$fname = trim($regs[4]); $fname = trim($regs[4]);
if (isset($matches[$fname])) { if (isset($matches[$fname])) {
$matches[$fname]['hash'] = $regs[3]; $matches[$fname]['hash'] = $regs[3];
$matches[$fname]['type'] = $regs[2]; $matches[$fname]['type'] = $regs[2];
} else { } else {
if ($case) if ($case)
$ret = ereg("^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.*" . quotemeta($search) . "[^/]*)$",$line,$regs); $ret = preg_match("/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.*" . quotemeta($search) . "[^/]*)$/",$line,$regs);
else else
$ret = eregi("^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.*" . quotemeta($search) . "[^/]*)$",$line,$regs); $ret = preg_match("/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.*" . quotemeta($search) . "[^/]*)$/i",$line,$regs);
if ($ret) { if ($ret) {
$fname = trim($regs[4]); $fname = trim($regs[4]);
$matches[$fname] = array(); $matches[$fname] = array();
$matches[$fname]['hash'] = $regs[3]; $matches[$fname]['hash'] = $regs[3];
$matches[$fname]['type'] = $regs[2]; $matches[$fname]['type'] = $regs[2];
} }
} }
} }
if ($skip > 0) { if ($skip > 0) {
foreach ($matches as $i => $val) { foreach ($matches as $i => $val) {
unset($matches[$i]); unset($matches[$i]);
$skip--; $skip--;
if ($skip <= 0) if ($skip <= 0)
break; break;
} }
} }
   
if (count($matches) > $count) { if (count($matches) > $count) {
$index = 1; $index = 1;
foreach ($matches as $i => $val) { foreach ($matches as $i => $val) {
if ($index > $count) if ($index > $count)
unset($matches[$i]); unset($matches[$i]);
$index++; $index++;
} }
} }
   
return $matches; return $matches;
} }
   
?> ?>
   
<?php <?php
/* /*
* gitutil.git_get_hash_by_path.php * gitutil.git_get_hash_by_path.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Git utility - get hash from a path * Component: Git utility - get hash from a path
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
require_once('gitutil.git_ls_tree.php'); require_once('gitutil.git_ls_tree.php');
   
function git_get_hash_by_path($project,$base,$path,$type = null) function git_get_hash_by_path($project,$base,$path,$type = null)
{ {
$tree = $base; $tree = $base;
$parts = explode("/",$path); $parts = explode("/",$path);
$partcount = count($parts); $partcount = count($parts);
foreach ($parts as $i => $part) { foreach ($parts as $i => $part) {
$lsout = git_ls_tree($project, $tree); $lsout = git_ls_tree($project, $tree);
$entries = explode("\n",$lsout); $entries = explode("\n",$lsout);
foreach ($entries as $j => $line) { foreach ($entries as $j => $line) {
if (ereg("^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$",$line,$regs)) { if (preg_match("/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/",$line,$regs)) {
if ($regs[4] == $part) { if ($regs[4] == $part) {
if ($i == ($partcount)-1) if ($i == ($partcount)-1)
return $regs[3]; return $regs[3];
if ($regs[2] == "tree") if ($regs[2] == "tree")
$tree = $regs[3]; $tree = $regs[3];
break; break;
} }
} }
} }
} }
} }
   
?> ?>
   
<?php <?php
/* /*
* gitutil.git_read_commit.php * gitutil.git_read_commit.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Git utility - read a commit * Component: Git utility - read a commit
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
require_once('defs.constants.php'); require_once('defs.constants.php');
require_once('util.age_string.php'); require_once('util.age_string.php');
require_once('gitutil.git_read_revlist.php'); require_once('gitutil.git_read_revlist.php');
   
function git_read_commit($proj,$head) function git_read_commit($proj,$head)
{ {
$lines = git_read_revlist($proj,$head,1,NULL,TRUE,TRUE); $lines = git_read_revlist($proj,$head,1,NULL,TRUE,TRUE);
if (!($lines[0]) || !ereg("^[0-9a-fA-F]{40}",$lines[0])) if (!($lines[0]) || !preg_match("/^[0-9a-fA-F]{40}/",$lines[0]))
return null; return null;
$commit = array(); $commit = array();
$tok = strtok($lines[0]," "); $tok = strtok($lines[0]," ");
$commit['id'] = $tok; $commit['id'] = $tok;
$tok = strtok(" "); $tok = strtok(" ");
$parents = array(); $parents = array();
while ($tok !== false) { while ($tok !== false) {
$parents[] = $tok; $parents[] = $tok;
$tok = strtok(" "); $tok = strtok(" ");
} }
$commit['parents'] = $parents; $commit['parents'] = $parents;
if (isset($parents[0])) if (isset($parents[0]))
$commit['parent'] = $parents[0]; $commit['parent'] = $parents[0];
$comment = array(); $comment = array();
foreach ($lines as $i => $line) { foreach ($lines as $i => $line) {
if (ereg("^tree ([0-9a-fA-F]{40})$",$line,$regs)) if (preg_match("/^tree ([0-9a-fA-F]{40})$/",$line,$regs))
$commit['tree'] = $regs[1]; $commit['tree'] = $regs[1];
else if (ereg("^author (.*) ([0-9]+) (.*)$",$line,$regs)) { else if (preg_match("/^author (.*) ([0-9]+) (.*)$/",$line,$regs)) {
$commit['author'] = $regs[1]; $commit['author'] = $regs[1];
$commit['author_epoch'] = $regs[2]; $commit['author_epoch'] = $regs[2];
$commit['author_tz'] = $regs[3]; $commit['author_tz'] = $regs[3];
if (ereg("^([^<]+) <",$commit['author'],$r)) if (preg_match("/^([^<]+) </",$commit['author'],$r))
$commit['author_name'] = $r[1]; $commit['author_name'] = $r[1];
else else
$commit['author_name'] = $commit['author']; $commit['author_name'] = $commit['author'];
} else if (ereg("^committer (.*) ([0-9]+) (.*)$",$line,$regs)) { } else if (preg_match("/^committer (.*) ([0-9]+) (.*)$/",$line,$regs)) {
$commit['committer'] = $regs[1]; $commit['committer'] = $regs[1];
$commit['committer_epoch'] = $regs[2]; $commit['committer_epoch'] = $regs[2];
$commit['committer_tz'] = $regs[3]; $commit['committer_tz'] = $regs[3];
$commit['committer_name'] = $commit['committer']; $commit['committer_name'] = $commit['committer'];
$commit['committer_name'] = ereg_replace(" <.*","",$commit['committer_name']); $commit['committer_name'] = preg_replace("/ <.*/","",$commit['committer_name']);
} else { } else {
$trimmed = trim($line); $trimmed = trim($line);
if ((strlen($trimmed) > 0) && !ereg("^[0-9a-fA-F]{40}",$trimmed) && !ereg("^parent [0-9a-fA-F]{40}",$trimmed)) { if ((strlen($trimmed) > 0) && !preg_match("/^[0-9a-fA-F]{40}/",$trimmed) && !preg_match("/^parent [0-9a-fA-F]{40}/",$trimmed)) {
if (!isset($commit['title'])) { if (!isset($commit['title'])) {
$commit['title'] = $trimmed; $commit['title'] = $trimmed;
if (strlen($trimmed) > GITPHP_TRIM_LENGTH) if (strlen($trimmed) > GITPHP_TRIM_LENGTH)
$commit['title_short'] = substr($trimmed,0,GITPHP_TRIM_LENGTH) . "..."; $commit['title_short'] = substr($trimmed,0,GITPHP_TRIM_LENGTH) . "...";
else else
$commit['title_short'] = $trimmed; $commit['title_short'] = $trimmed;
} }
$comment[] = $trimmed; $comment[] = $trimmed;
} }
} }
} }
$commit['comment'] = $comment; $commit['comment'] = $comment;
$age = time() - $commit['committer_epoch']; $age = time() - $commit['committer_epoch'];
$commit['age'] = $age; $commit['age'] = $age;
$commit['age_string'] = age_string($age); $commit['age_string'] = age_string($age);
date_default_timezone_set("UTC"); date_default_timezone_set("UTC");
if ($age > 60*60*24*7*2) { if ($age > 60*60*24*7*2) {
$commit['age_string_date'] = date("Y-m-d",$commit['committer_epoch']); $commit['age_string_date'] = date("Y-m-d",$commit['committer_epoch']);
$commit['age_string_age'] = $commit['age_string']; $commit['age_string_age'] = $commit['age_string'];
} else { } else {
$commit['age_string_date'] = $commit['age_string']; $commit['age_string_date'] = $commit['age_string'];
$commit['age_string_age'] = date("Y-m-d",$commit['committer_epoch']); $commit['age_string_age'] = date("Y-m-d",$commit['committer_epoch']);
} }
return $commit; return $commit;
} }
   
?> ?>
   
<?php <?php
/* /*
* gitutil.git_read_tag.php * gitutil.git_read_tag.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Git utility - read tag * Component: Git utility - read tag
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
require_once('gitutil.git_cat_file.php'); require_once('gitutil.git_cat_file.php');
   
function git_read_tag($project, $tag_id) function git_read_tag($project, $tag_id)
{ {
$tag = array(); $tag = array();
$tagout = git_cat_file($project, $tag_id, NULL, "tag"); $tagout = git_cat_file($project, $tag_id, NULL, "tag");
$tag['id'] = $tag_id; $tag['id'] = $tag_id;
$comment = array(); $comment = array();
$tok = strtok($tagout,"\n"); $tok = strtok($tagout,"\n");
while ($tok !== false) { while ($tok !== false) {
if (ereg("^object ([0-9a-fA-F]{40})$",$tok,$regs)) if (preg_match("/^object ([0-9a-fA-F]{40})$/",$tok,$regs))
$tag['object'] = $regs[1]; $tag['object'] = $regs[1];
else if (ereg("^type (.+)$",$tok,$regs)) else if (preg_match("/^type (.+)$/",$tok,$regs))
$tag['type'] = $regs[1]; $tag['type'] = $regs[1];
else if (ereg("^tag (.+)$",$tok,$regs)) else if (preg_match("/^tag (.+)$/",$tok,$regs))
$tag['name'] = $regs[1]; $tag['name'] = $regs[1];
else if (ereg("^tagger (.*) ([0-9]+) (.*)$",$tok,$regs)) { else if (preg_match("/^tagger (.*) ([0-9]+) (.*)$/",$tok,$regs)) {
$tag['author'] = $regs[1]; $tag['author'] = $regs[1];
$tag['epoch'] = $regs[2]; $tag['epoch'] = $regs[2];
$tag['tz'] = $regs[3]; $tag['tz'] = $regs[3];
} else { } else {
while ($tok !== false) { while ($tok !== false) {
$comment[] = $tok; $comment[] = $tok;
$tok = strtok("\n"); $tok = strtok("\n");
} }
break; break;
} }
$tok = strtok("\n"); $tok = strtok("\n");
} }
$tag['comment'] = $comment; $tag['comment'] = $comment;
if (!isset($tag['name'])) if (!isset($tag['name']))
return null; return null;
return $tag; return $tag;
} }
   
?> ?>
   
<?php <?php
/* /*
* gitutil.read_info_ref.php * gitutil.read_info_ref.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Git utility - read info on a ref * Component: Git utility - read info on a ref
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
require_once('defs.commands.php'); require_once('defs.commands.php');
require_once('gitutil.git_exec.php'); require_once('gitutil.git_exec.php');
   
function read_info_ref($project, $type = "") function read_info_ref($project, $type = "")
{ {
$refs = array(); $refs = array();
$cmd = GIT_SHOW_REF . " --dereference"; $cmd = GIT_SHOW_REF . " --dereference";
$showrefs = git_exec($project, $cmd); $showrefs = git_exec($project, $cmd);
$lines = explode("\n",$showrefs); $lines = explode("\n",$showrefs);
foreach ($lines as $no => $line) { foreach ($lines as $no => $line) {
if (ereg("^([0-9a-fA-F]{40}) .*" . $type . "/([^\^]+)",$line,$regs)) { if (preg_match("`^([0-9a-fA-F]{40}) .*" . $type . "/([^\^]+)`",$line,$regs)) {
if (isset($refs[$regs[1]])) if (isset($refs[$regs[1]]))
$refs[$regs[1]] .= " / " . $regs[2]; $refs[$regs[1]] .= " / " . $regs[2];
else else
$refs[$regs[1]] = $regs[2]; $refs[$regs[1]] = $regs[2];
} }
} }
return $refs; return $refs;
} }
   
?> ?>
   
<?php <?php
/* /*
* util.date_str.php * util.date_str.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Utility - Date string * Component: Utility - Date string
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
function date_str($epoch,$tz = "-0000") function date_str($epoch,$tz = "-0000")
{ {
$date = array(); $date = array();
$date['hour'] = date("H",$epoch); $date['hour'] = date("H",$epoch);
$date['minute'] = date("i",$epoch); $date['minute'] = date("i",$epoch);
$date['mday'] = date("d",$epoch); $date['mday'] = date("d",$epoch);
$date['day'] = date("D",$epoch); $date['day'] = date("D",$epoch);
$date['month'] = date("M",$epoch); $date['month'] = date("M",$epoch);
$date['rfc2822'] = date("r",$epoch); $date['rfc2822'] = date("r",$epoch);
$date['mday-time'] = date("d M H:i",$epoch); $date['mday-time'] = date("d M H:i",$epoch);
if (ereg("^([+\-][0-9][0-9])([0-9][0-9])$",$tz,$regs)) { if (preg_match("/^([+\-][0-9][0-9])([0-9][0-9])$/",$tz,$regs)) {
$local = $epoch + ((((int)$regs[1]) + ($regs[2]/60)) * 3600); $local = $epoch + ((((int)$regs[1]) + ($regs[2]/60)) * 3600);
$date['hour_local'] = date("H",$local); $date['hour_local'] = date("H",$local);
$date['minute_local'] = date("i",$local); $date['minute_local'] = date("i",$local);
$date['tz_local'] = $tz; $date['tz_local'] = $tz;
} }
return $date; return $date;
} }
   
?> ?>
   
<?php <?php
/* /*
* util.highlight.php * util.highlight.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Utility - highlight a string * Component: Utility - highlight a string
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
function highlight($haystack, $needle, $highlightclass, $trimlen = NULL, $escape = false) function highlight($haystack, $needle, $highlightclass, $trimlen = NULL, $escape = false)
{ {
if (eregi("(.*)(" . quotemeta($needle) . ")(.*)",$haystack,$regs)) { if (preg_match("/(.*)(" . quotemeta($needle) . ")(.*)/i",$haystack,$regs)) {
if (isset($trimlen) && ($trimlen > 0)) { if (isset($trimlen) && ($trimlen > 0)) {
$linelen = strlen($regs[0]); $linelen = strlen($regs[0]);
if ($linelen > $trimlen) { if ($linelen > $trimlen) {
$matchlen = strlen($regs[2]); $matchlen = strlen($regs[2]);
$remain = floor(($trimlen - $matchlen) / 2); $remain = floor(($trimlen - $matchlen) / 2);
$leftlen = strlen($regs[1]); $leftlen = strlen($regs[1]);
$rightlen = strlen($regs[3]); $rightlen = strlen($regs[3]);
if ($leftlen > $remain) { if ($leftlen > $remain) {
$leftremain = $remain; $leftremain = $remain;
if ($rightlen < $remain) if ($rightlen < $remain)
$leftremain += ($remain - $rightlen); $leftremain += ($remain - $rightlen);
$regs[1] = "..." . substr($regs[1], ($leftlen - ($leftremain - 3))); $regs[1] = "..." . substr($regs[1], ($leftlen - ($leftremain - 3)));
} }
if ($rightlen > $remain) { if ($rightlen > $remain) {
$rightremain = $remain; $rightremain = $remain;
if ($leftlen < $remain) if ($leftlen < $remain)
$rightremain += ($remain - $leftlen); $rightremain += ($remain - $leftlen);
$regs[3] = substr($regs[3],0,$rightremain-3) . "..."; $regs[3] = substr($regs[3],0,$rightremain-3) . "...";
} }
} }
} }
if ($escape) { if ($escape) {
$regs[1] = htmlspecialchars($regs[1]); $regs[1] = htmlspecialchars($regs[1]);
$regs[2] = htmlspecialchars($regs[2]); $regs[2] = htmlspecialchars($regs[2]);
$regs[3] = htmlspecialchars($regs[3]); $regs[3] = htmlspecialchars($regs[3]);
} }
$ret = $regs[1] . "<span"; $ret = $regs[1] . "<span";
if ($highlightclass) if ($highlightclass)
$ret .= " class=\"" . $highlightclass . "\""; $ret .= " class=\"" . $highlightclass . "\"";
$ret .= ">" . $regs[2] . "</span>" . $regs[3]; $ret .= ">" . $regs[2] . "</span>" . $regs[3];
return $ret; return $ret;
} }
   
return false; return false;
} }
   
?> ?>
   
comments