function git_diff($proj, $from, $from_name, $to, $to_name) { global $gitphp_conf; $from_tmp = "/dev/null"; $to_tmp = "/dev/null"; if (function_exists('posix_getpid')) { $pid = posix_getpid(); } else { $pid = rand(); } if (isset($from)) { $from_tmp = $gitphp_conf['gittmp'] . "gitphp_" . $pid . "_from"; git_cat_file($proj, $from, $from_tmp); } if (isset($to)) { $to_tmp = $gitphp_conf['gittmp'] . "gitphp_" . $pid . "_to"; git_cat_file($proj, $to, $to_tmp); } $out = shell_exec($gitphp_conf['diffbin'] . " -u -p -L '" . $from_name . "' -L '" . $to_name . "' " . $from_tmp . " " . $to_tmp); if (isset($from)) { unlink($from_tmp); } if (isset($to)) { unlink($to_tmp); } return $out; }
function git_read_tag($project, $tag_id) { $tag = array(); $tagout = git_cat_file($project, $tag_id, NULL, "tag"); $tag['id'] = $tag_id; $comment = array(); $tok = strtok($tagout, "\n"); while ($tok !== false) { if (preg_match("/^object ([0-9a-fA-F]{40})\$/", $tok, $regs)) { $tag['object'] = $regs[1]; } else { if (preg_match("/^type (.+)\$/", $tok, $regs)) { $tag['type'] = $regs[1]; } else { if (preg_match("/^tag (.+)\$/", $tok, $regs)) { $tag['name'] = $regs[1]; } else { if (preg_match("/^tagger (.*) ([0-9]+) (.*)\$/", $tok, $regs)) { $tag['author'] = $regs[1]; $tag['epoch'] = $regs[2]; $tag['tz'] = $regs[3]; } else { while ($tok !== false) { $comment[] = $tok; $tok = strtok("\n"); } break; } } } } $tok = strtok("\n"); } $tag['comment'] = $comment; if (!isset($tag['name'])) { return null; } return $tag; }
function git_blob_plain($projectroot, $project, $hash, $file) { global $gitphp_conf, $tpl; $cachekey = sha1($project) . "|" . $hash . "|" . sha1($file); $buffer = null; // XXX: Nasty hack to cache headers if (!$tpl->is_cached('blobheaders.tpl', $cachekey)) { if ($file) { $saveas = $file; } else { $saveas = $hash . ".txt"; } $buffer = git_cat_file($projectroot . $project, $hash); if ($gitphp_conf['filemimetype']) { $mime = file_mime($buffer, $file); } $headers = array(); if ($mime) { $headers[] = "Content-type: " . $mime; } else { $headers[] = "Content-type: text/plain; charset=UTF-8"; } $headers[] = "Content-disposition: inline; filename=\"" . $saveas . "\""; $tpl->assign("blobheaders", serialize($headers)); } $out = $tpl->fetch('blobheaders.tpl', $cachekey); $returnedheaders = unserialize($out); foreach ($returnedheaders as $i => $header) { header($header); } if (!$tpl->is_cached('blobplain.tpl', $cachekey)) { if (!$buffer) { $buffer = git_cat_file($projectroot . $project, $hash); } $tpl->assign("blob", $buffer); } $tpl->display('blobplain.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_get_type($project, $hash) { return trim(git_cat_file($project, $hash, NULL, "-t")); }