Пример #1
0
function git_tag($projectroot, $project, $hash)
{
    global $tpl;
    $cachekey = sha1($project) . "|" . $hash;
    $git = new Git($projectroot . $project);
    $hash = $git->revParse($hash);
    if (!$tpl->is_cached('tag.tpl', $cachekey)) {
        $head = git_read_head($git);
        $tpl->assign("head", sha1_hex($head));
        $tpl->assign("hash", sha1_hex($hash));
        $tag = git_read_tag($git, $hash);
        $tpl->assign("tag", $tag);
        if (isset($tag['author'])) {
            $ad = date_str($tag['epoch'], $tag['tz']);
            $tpl->assign("datedata", $ad);
        }
    }
    $tpl->display('tag.tpl', $cachekey);
}
Пример #2
0
function git_blob_plain($projectroot, $project, $hash, $file)
{
    global $gitphp_conf, $tpl;
    $cachekey = sha1($project) . "|" . $hash . "|" . sha1($file);
    $buffer = null;
    $git = new Git($projectroot . $project);
    $hash = $git->revParse($hash);
    // XXX: Nasty hack to cache headers
    if (!$tpl->is_cached('blobheaders.tpl', $cachekey)) {
        if ($file) {
            $saveas = $file;
        } else {
            $saveas = $hash . ".txt";
        }
        $buffer = $git->getObject($hash)->data;
        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->getObject($hash)->data;
        }
        $tpl->assign("blob", $buffer);
    }
    $tpl->display('blobplain.tpl', $cachekey);
}
Пример #3
0
function git_commit($projectroot, $project, $hash)
{
    global $tpl;
    $cachekey = sha1($project) . "|" . $hash;
    $git = new Git($projectroot . $project);
    $hash = $git->revParse($hash);
    if (!$tpl->is_cached('commit.tpl', $cachekey)) {
        $co = git_read_commit($git, $hash);
        $ad = date_str($co['author_epoch'], $co['author_tz']);
        $cd = date_str($co['committer_epoch'], $co['committer_tz']);
        if (isset($co['parent'])) {
            $a_tree = $git->getObject(sha1_bin($co['parent']))->getTree();
        } else {
            $a_tree = false;
        }
        $b_tree = $git->getObject(sha1_bin($co['tree']));
        $difftree = GitTree::diffTree($a_tree, $b_tree);
        ksort($difftree);
        $tpl->assign("hash", sha1_hex($hash));
        $tpl->assign("tree", $co['tree']);
        if (isset($co['parent'])) {
            $tpl->assign("parent", $co['parent']);
        }
        $tpl->assign("title", $co['title']);
        $refs = read_info_ref($git);
        if (isset($refs[$hash])) {
            $tpl->assign("commitref", $refs[$hash]);
        }
        $tpl->assign("author", $co['author']);
        $tpl->assign("adrfc2822", $ad['rfc2822']);
        $tpl->assign("adhourlocal", $ad['hour_local']);
        $tpl->assign("adminutelocal", $ad['minute_local']);
        $tpl->assign("adtzlocal", $ad['tz_local']);
        $tpl->assign("committer", $co['committer']);
        $tpl->assign("cdrfc2822", $cd['rfc2822']);
        $tpl->assign("cdhourlocal", $cd['hour_local']);
        $tpl->assign("cdminutelocal", $cd['minute_local']);
        $tpl->assign("cdtzlocal", $cd['tz_local']);
        $tpl->assign("id", $co['id']);
        $tpl->assign("parents", $co['parents']);
        $tpl->assign("comment", $co['comment']);
        $tpl->assign("difftreesize", count($difftree) + 1);
        $status_map = array(GitTree::TREEDIFF_ADDED => "A", GitTree::TREEDIFF_REMOVED => "D", GitTree::TREEDIFF_CHANGED => "M");
        $difftreelines = array();
        foreach ($difftree as $file => $diff) {
            $difftreeline = array();
            $difftreeline["from_mode"] = decoct($diff->old_mode);
            $difftreeline["to_mode"] = decoct($diff->new_mode);
            $difftreeline["from_mode_cut"] = substr(decoct($diff->old_mode), -4);
            $difftreeline["to_mode_cut"] = substr(decoct($diff->new_mode), -4);
            $difftreeline["from_id"] = sha1_hex($diff->old_obj);
            $difftreeline["to_id"] = sha1_hex($diff->new_obj);
            $difftreeline["status"] = $status_map[$diff->status];
            $difftreeline["similarity"] = "";
            $difftreeline["file"] = $file;
            $difftreeline["from_file"] = "";
            $difftreeline["from_filetype"] = "";
            $difftreeline["to_file"] = "";
            $difftreeline["to_filetype"] = "";
            $difftreeline["isreg"] = TRUE;
            $modestr = "";
            /*if ((octdec($regs[1]) & 0x17000) != (octdec($regs[2]) & 0x17000))
            			$modestr .= " from " . file_type($regs[1]) . " to " . file_type($regs[2]);
            		if ((octdec($regs[1]) & 0777) != (octdec($regs[2]) & 0777)) {
            			if ((octdec($regs[1]) & 0x8000) && (octdec($regs[2]) & 0x8000))
            				$modestr .= " mode: " . (octdec($regs[1]) & 0777) . "->" . (octdec($regs[2]) & 0777);
            			else if (octdec($regs[2]) & 0x8000)
            				$modestr .= " mode: " . (octdec($regs[2]) & 0777);*/
            $difftreeline["modechange"] = $modestr;
            $simmodechg = "";
            /*if ($regs[1] != $regs[2])
            		$simmodechg .= ", mode: " . (octdec($regs[2]) & 0777);*/
            $difftreeline["simmodechg"] = $simmodechg;
            $difftreelines[] = $difftreeline;
        }
        $tpl->assign("difftreelines", $difftreelines);
    }
    $tpl->display('commit.tpl', $cachekey);
}
Пример #4
0
function git_blob($projectroot, $project, $hash, $file, $hashbase)
{
    global $gitphp_conf, $tpl;
    $cachekey = sha1($project) . "|" . $hashbase . "|" . $hash . "|" . sha1($file);
    $git = new Git($projectroot . $project);
    if (isset($hash)) {
        $hash = $git->revParse($hash);
    }
    if (isset($hashbase)) {
        $hashbase = $git->revParse($hashbase);
    }
    if (!$tpl->is_cached('blob.tpl', $cachekey)) {
        $head = git_read_head($git);
        if (!isset($hashbase)) {
            $hashbase = $head;
        }
        if (!isset($hash) && isset($file)) {
            $hash = git_get_hash_by_path($git, $git->getObject($hashbase), $file, "blob");
        }
        $catout = $git->getObject($hash)->data;
        $tpl->assign("hash", sha1_hex($hash));
        $tpl->assign("hashbase", sha1_hex($hashbase));
        $tpl->assign("head", sha1_hex($head));
        if ($co = git_read_commit($git, $hashbase)) {
            $tpl->assign("fullnav", TRUE);
            $refs = read_info_ref($git);
            $tpl->assign("tree", $co['tree']);
            $tpl->assign("title", $co['title']);
            if (isset($file)) {
                $tpl->assign("file", $file);
            }
            if (isset($refs[$hashbase])) {
                $tpl->assign("hashbaseref", $refs[$hashbase]);
            }
        }
        $paths = git_path_trees($git, $git->getObject($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("", 'php');
                    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_read_head(Git $proj)
{
    return $proj->revParse("HEAD");
}