function git_blobdiff($projectroot, $project, $hash, $hashbase, $hashparent, $file) { global $tpl; $cachekey = sha1($project) . "|" . $hashbase . "|" . $hash . "|" . $hashparent . "|" . sha1($file); if (!$tpl->is_cached('blobdiff.tpl', $cachekey)) { $ret = prep_tmpdir(); if ($ret !== TRUE) { echo $ret; return; } $tpl->assign("hash", $hash); $tpl->assign("hashparent", $hashparent); $tpl->assign("hashbase", $hashbase); 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']); $refs = read_info_ref($projectroot . $project); if (isset($refs[$hashbase])) { $tpl->assign("hashbaseref", $refs[$hashbase]); } } $paths = git_path_trees($projectroot . $project, $hashbase, $file); $tpl->assign("paths", $paths); $diffout = explode("\n", git_diff($projectroot . $project, $hashparent, $file ? $file : $hashparent, $hash, $file ? $file : $hash)); $tpl->assign("diff", $diffout); } $tpl->display('blobdiff.tpl', $cachekey); }
function git_history($projectroot, $project, $hash, $file) { global $tpl; $cachekey = sha1($project) . "|" . $hash . "|" . sha1($file); if (!$tpl->is_cached('history.tpl', $cachekey)) { if (!isset($hash)) { $hash = git_read_head($projectroot . $project); } $co = git_read_commit($projectroot . $project, $hash); $refs = read_info_ref($projectroot . $project); $tpl->assign("hash", $hash); if (isset($refs[$hash])) { $tpl->assign("hashbaseref", $refs[$hash]); } $tpl->assign("tree", $co['tree']); $tpl->assign("title", $co['title']); $paths = git_path_trees($projectroot . $project, $hash, $file); $tpl->assign("paths", $paths); $cmdout = git_history_list($projectroot . $project, $hash, $file); $lines = explode("\n", $cmdout); $historylines = array(); foreach ($lines as $i => $line) { if (preg_match("/^([0-9a-fA-F]{40})/", $line, $regs)) { $commit = $regs[1]; } 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(); $co = git_read_commit($projectroot . $project, $commit); $historyline["agestringage"] = $co['age_string_age']; $historyline["agestringdate"] = $co['age_string_date']; $historyline["authorname"] = $co['author_name']; $historyline["commit"] = $commit; $historyline["file"] = $file; $historyline["title"] = $co['title_short']; if (isset($refs[$commit])) { $historyline["commitref"] = $refs[$commit]; } $blob = git_get_hash_by_path($projectroot . $project, $hash, $file); $blob_parent = git_get_hash_by_path($projectroot . $project, $commit, $file); if ($blob && $blob_parent && $blob != $blob_parent) { $historyline["blob"] = $blob; $historyline["blobparent"] = $blob_parent; } $historylines[] = $historyline; unset($commit); } } } $tpl->assign("historylines", $historylines); } $tpl->display('history.tpl', $cachekey); }
function git_tree($projectroot, $project, $hash, $file, $hashbase) { global $tpl; $cachekey = sha1($project) . "|" . $hashbase . "|" . $hash . "|" . sha1($file); if (!$tpl->is_cached('tree.tpl', $cachekey)) { if (!isset($hash)) { $hash = git_read_head($projectroot . $project); if (isset($file)) { $hash = git_get_hash_by_path($projectroot . $project, $hashbase ? $hashbase : $hash, $file, "tree"); } if (!isset($hashbase)) { $hashbase = $hash; } } $lsout = git_ls_tree($projectroot . $project, $hash, TRUE); $refs = read_info_ref($projectroot . $project); $tpl->assign("hash", $hash); if (isset($hashbase)) { $tpl->assign("hashbase", $hashbase); } if (isset($hashbase) && ($co = git_read_commit($projectroot . $project, $hashbase))) { $basekey = $hashbase; $tpl->assign("fullnav", TRUE); $tpl->assign("title", $co['title']); if (isset($refs[$hashbase])) { $tpl->assign("hashbaseref", $refs[$hashbase]); } } $paths = git_path_trees($projectroot . $project, $hashbase, $file); $tpl->assign("paths", $paths); if (isset($file)) { $tpl->assign("base", $file . "/"); } $treelines = array(); $tok = strtok($lsout, ""); while ($tok !== false) { if (preg_match("/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)\$/", $tok, $regs)) { $treeline = array(); $treeline["filemode"] = mode_str($regs[1]); $treeline["type"] = $regs[2]; $treeline["hash"] = $regs[3]; $treeline["name"] = $regs[4]; $treelines[] = $treeline; } $tok = strtok(""); } $tpl->assign("treelines", $treelines); } $tpl->display('tree.tpl', $cachekey); }
function git_blob($projectroot, $project, $hash, $file, $hashbase) { global $gitphp_conf, $tpl; $cachekey = sha1($project) . "|" . $hashbase . "|" . $hash . "|" . sha1($file); if (!$tpl->is_cached('blob.tpl', $cachekey)) { $head = git_read_head($projectroot . $project); if (!isset($hashbase)) { $hashbase = $head; } if (!isset($hash) && isset($file)) { $hash = git_get_hash_by_path($projectroot . $project, $hashbase, $file, "blob"); } $catout = git_cat_file($projectroot . $project, $hash); $tpl->assign("hash", $hash); $tpl->assign("hashbase", $hashbase); $tpl->assign("head", $head); if ($co = git_read_commit($projectroot . $project, $hashbase)) { $tpl->assign("fullnav", TRUE); $refs = read_info_ref($projectroot . $project); $tpl->assign("tree", $co['tree']); $tpl->assign("title", $co['title']); if (isset($file)) { $tpl->assign("file", $file); } if ($hashbase == "HEAD") { if (isset($refs[$head])) { $tpl->assign("hashbaseref", $refs[$head]); } } else { if (isset($refs[$hashbase])) { $tpl->assign("hashbaseref", $refs[$hashbase]); } } } $paths = git_path_trees($projectroot . $project, $hashbase, $file); $tpl->assign("paths", $paths); if ($gitphp_conf['filemimetype']) { $mime = file_mime($catout, $file); if ($mime) { $mimetype = strtok($mime, "/"); } } if ($mimetype == "image") { $tpl->assign("mime", $mime); $tpl->assign("data", base64_encode($catout)); } else { $usedgeshi = $gitphp_conf['geshi']; if ($usedgeshi) { $usedgeshi = FALSE; include_once $gitphp_conf['geshiroot'] . "geshi.php"; if (class_exists("GeSHi")) { $geshi = new GeSHi($catout, $lang = Geshi::get_language_name_from_extension(substr(strrchr($file, '.'), 1))); if ($geshi) { $lang = ""; if (isset($file)) { $lang = $geshi->get_language_name_from_extension(substr(strrchr($file, '.'), 1)); } if (isset($lang) && strlen($lang) > 0) { #$geshi->set_source($catout); #$geshi->set_language($lang); #$geshi->set_header_type(GESHI_HEADER_DIV); #$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); $tpl->assign("geshiout", $geshi->parse_code()); $usedgeshi = TRUE; } } } } if (!$usedgeshi) { $lines = explode("\n", $catout); $tpl->assign("lines", $lines); } } } $tpl->display('blob.tpl', $cachekey); }
function git_tree($projectroot, $project, $hash, $file, $hashbase) { global $tpl; $cachekey = sha1($project) . "|" . $hashbase . "|" . $hash . "|" . sha1($file); $git = new Git($projectroot . $project); if (isset($hash)) { $hash = sha1_bin($hash); } if (isset($hashbase)) { $hashbase = sha1_bin($hashbase); } if (!$tpl->is_cached('tree.tpl', $cachekey)) { if (!isset($hash)) { $hash = git_read_head($git); if (!isset($hashbase)) { $hashbase = $hash; } if (isset($file)) { $hash = git_get_hash_by_path($git, $git->getObject($hashbase ? $hashbase : $hash), $file, "tree"); } } $refs = read_info_ref($git); $tpl->assign("hash", sha1_hex($hash)); if (isset($hashbase)) { $tpl->assign("hashbase", sha1_hex($hashbase)); } if (isset($hashbase) && ($co = git_read_commit($git, $hashbase))) { $basekey = $hashbase; $tpl->assign("fullnav", TRUE); $tpl->assign("title", $co['title']); if (isset($refs[$hashbase])) { $tpl->assign("hashbaseref", $refs[$hashbase]); } } if (isset($hashbase)) { $objbase = $git->getObject($hashbase); if ($objbase->getType() == Git::OBJ_COMMIT) { $objbase = $objbase->getTree(); } $paths = git_path_trees($git, $objbase, $file); $tpl->assign("paths", $paths); } if (isset($file)) { $tpl->assign("base", $file . "/"); } $obj = $git->getObject($hash); if ($obj->getType() == Git::OBJ_COMMIT) { $obj = $obj->getTree(); } $treelines = array(); foreach ($obj->nodes as $node) { $treeline = array(); $treeline["filemode"] = mode_str(decoct($node->mode)); $treeline["type"] = $node->is_dir ? "tree" : "blob"; $treeline["hash"] = sha1_hex($node->object); $treeline["name"] = $node->name; $treelines[] = $treeline; $tok = strtok(""); } $tpl->assign("treelines", $treelines); } $tpl->display('tree.tpl', $cachekey); }