function git_log($projectroot, $project, $hash, $page)
{
    global $tpl;
    $cachekey = sha1($project) . "|" . $hash . "|" . (isset($page) ? $page : 0);
    $git = new Git($projectroot . $project);
    if (!$tpl->is_cached('shortlog.tpl', $cachekey)) {
        $head = git_read_head($git);
        if (!isset($hash)) {
            $hash = $head;
        } else {
            $hash = $git->revParse($hash);
        }
        if (!isset($page)) {
            $page = 0;
        }
        $refs = read_info_ref($git);
        $tpl->assign("hash", sha1_hex($hash));
        $tpl->assign("head", sha1_hex($head));
        if ($page) {
            $tpl->assign("page", $page);
        }
        $revlist = git_read_revlist($git, $hash, 101, $page * 100);
        $revlistcount = count($revlist);
        $tpl->assign("revlistcount", $revlistcount);
        if (!$revlist) {
            $tpl->assign("norevlist", TRUE);
            $co = git_read_commit($git, $hash);
            $tpl->assign("lastchange", $co['age_string']);
        }
        $commitlines = array();
        $commitcount = min(100, $revlistcount);
        for ($i = 0; $i < $commitcount; ++$i) {
            $commit = $revlist[$i];
            $commithash = sha1_hex($commit->getName());
            $commitline = array();
            $co = git_read_commit($git, $commit->getName());
            $ad = date_str($co['author_epoch']);
            $commitline["project"] = $project;
            $commitline["commit"] = $commithash;
            if (isset($refs[$commit->getName()])) {
                $commitline["commitref"] = $refs[$commit->getName()];
                $commitline["commitclass"] = get_commit_class($refs[$commit->getName()]);
            }
            $commitline["agestring"] = $co['age_string'];
            $commitline["title"] = $co['title'];
            $commitline["authorname"] = $co['author_name'];
            $commitline["rfc2822"] = $ad['rfc2822'];
            $commitline["comment"] = $co['comment'];
            $commitlines[] = $commitline;
        }
        $tpl->assign("commitlines", $commitlines);
    }
    $tpl->display('log.tpl', $cachekey);
}
function git_summary($projectroot, $project)
{
    global $tpl, $gitphp_conf;
    $cachekey = sha1($project);
    $git = new Git($projectroot . $project);
    if (!$tpl->is_cached('project.tpl', $cachekey)) {
        $descr = git_project_descr($projectroot, $project);
        $head = git_read_head($git);
        $commit = git_read_commit($git, $head);
        $commitdate = date_str($commit['committer_epoch'], $commit['committer_tz']);
        $owner = git_project_owner($projectroot, $project);
        $refs = read_info_ref($git);
        $tpl->assign("head", sha1_hex($head));
        $tpl->assign("description", $descr);
        $tpl->assign("owner", $owner);
        $tpl->assign("lastchange", $commitdate['rfc2822']);
        if (isset($gitphp_conf['cloneurl'])) {
            $tpl->assign('cloneurl', $gitphp_conf['cloneurl'] . $project);
        }
        if (isset($gitphp_conf['pushurl'])) {
            $tpl->assign('pushurl', $gitphp_conf['pushurl'] . $project);
        }
        $revlist = git_read_revlist($git, $head, 17);
        foreach ($revlist as $i => $rev) {
            $revhash = sha1_hex($rev->getName());
            $revdata = array();
            $revco = git_read_commit($git, $rev->getName());
            $authordate = date_str($revco['author_epoch']);
            $revdata["commit"] = $revhash;
            if (isset($refs[$rev->getName()])) {
                $revdata["commitref"] = $refs[$rev->getName()];
                $revdata["commitclass"] = get_commit_class($refs[$rev->getName()]);
            }
            $revdata["commitage"] = $revco['age_string'];
            $revdata["commitauthor"] = $revco['author_name'];
            if (strlen($revco['title_short']) < strlen($revco['title'])) {
                $revdata["title"] = $revco['title'];
                $revdata["title_short"] = $revco['title_short'];
            } else {
                $revdata["title_short"] = $revco['title'];
            }
            $revlist[$i] = $revdata;
        }
        $tpl->assign("revlist", $revlist);
        $taglist = git_read_refs($git, "refs/tags");
        if (isset($taglist) && count($taglist) > 0) {
            foreach ($taglist as $i => $tag) {
                if (isset($tag['comment'])) {
                    $com = trim($tag['comment'][0]);
                    if (strlen($com) > GITPHP_TRIM_LENGTH) {
                        $com = substr($com, 0, GITPHP_TRIM_LENGTH) . "...";
                    }
                    $taglist[$i]['comment'] = $com;
                }
            }
            $tpl->assign("taglist", $taglist);
        }
        $headlist = git_read_refs($git, "refs/heads");
        if (isset($headlist) && count($headlist) > 0) {
            $tpl->assign("headlist", $headlist);
        }
    }
    $tpl->display('project.tpl', $cachekey);
}