Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
function git_heads($projectroot, $project)
{
    global $tpl;
    $cachekey = sha1($project);
    if (!$tpl->is_cached('heads.tpl', $cachekey)) {
        $head = git_read_head($projectroot . $project);
        $tpl->assign("head", $head);
        $headlist = git_read_refs($projectroot, $project, "refs/heads");
        $tpl->assign("headlist", $headlist);
    }
    $tpl->display('heads.tpl', $cachekey);
}
Ejemplo n.º 3
0
function git_project_info($projectroot, $project)
{
    $projinfo = array();
    $projinfo["project"] = $project;
    $projinfo["descr"] = git_project_descr($projectroot, $project, TRUE);
    $projinfo["owner"] = git_project_owner($projectroot, $project);
    $head = git_read_head($projectroot . $project);
    $commit = git_read_commit($projectroot . $project, $head);
    $projinfo["age"] = $commit['age'];
    $projinfo["age_string"] = $commit['age_string'];
    return $projinfo;
}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
function git_tags($projectroot, $project)
{
    global $tpl;
    $cachekey = sha1($project);
    if (!$tpl->is_cached('tags.tpl', $cachekey)) {
        $head = git_read_head($projectroot . $project);
        $tpl->assign("head", $head);
        $taglist = git_read_refs($projectroot, $project, "refs/tags");
        if (isset($taglist) && count($taglist) > 0) {
            $tpl->assign("taglist", $taglist);
        }
    }
    $tpl->display('tags.tpl', $cachekey);
}
Ejemplo n.º 6
0
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);
}
Ejemplo n.º 7
0
function git_rss($projectroot, $project)
{
    global $tpl;
    header("Content-type: text/xml; charset=UTF-8");
    $cachekey = sha1($project);
    if (!$tpl->is_cached('rss.tpl', $cachekey)) {
        $head = git_read_head($projectroot . $project);
        $revlist = git_read_revlist($projectroot . $project, $head, GITPHP_RSS_ITEMS);
        $tpl->assign("self", script_url());
        $commitlines = array();
        $revlistcount = count($revlist);
        for ($i = 0; $i < $revlistcount; ++$i) {
            $commit = $revlist[$i];
            $co = git_read_commit($projectroot . $project, $commit);
            if ($i >= 20 && time() - $co['committer_epoch'] > 48 * 60 * 60) {
                break;
            }
            $cd = date_str($co['committer_epoch']);
            $difftree = array();
            $parent = '';
            if (!empty($co['parent'])) {
                $parent = $co['parent'];
            }
            $diffout = git_diff_tree($projectroot . $project, $parent . " " . $co['id']);
            $tok = strtok($diffout, "\n");
            while ($tok !== false) {
                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];
                }
                $tok = strtok("\n");
            }
            $commitline = array();
            $commitline["cdmday"] = $cd['mday'];
            $commitline["cdmonth"] = $cd['month'];
            $commitline["cdhour"] = $cd['hour'];
            $commitline["cdminute"] = $cd['minute'];
            $commitline["title"] = $co['title'];
            $commitline["author"] = $co['author'];
            $commitline["cdrfc2822"] = $cd['rfc2822'];
            $commitline["commit"] = $commit;
            $commitline["comment"] = $co['comment'];
            $commitline["difftree"] = $difftree;
            $commitlines[] = $commitline;
        }
        $tpl->assign("commitlines", $commitlines);
    }
    $tpl->display('rss.tpl', $cachekey);
}
Ejemplo n.º 8
0
function git_shortlog($projectroot, $project, $hash, $page)
{
    global $tpl;
    $cachekey = sha1($project) . "|" . $hash . "|" . (isset($page) ? $page : 0);
    if (!$tpl->is_cached('shortlog.tpl', $cachekey)) {
        $head = git_read_head($projectroot . $project);
        if (!isset($hash)) {
            $hash = $head;
        }
        if (!isset($page)) {
            $page = 0;
        }
        $refs = read_info_ref($projectroot . $project);
        $tpl->assign("hash", $hash);
        $tpl->assign("head", $head);
        if ($page) {
            $tpl->assign("page", $page);
        }
        $revlist = git_read_revlist($projectroot . $project, $hash, 101, $page * 100);
        $revlistcount = count($revlist);
        $tpl->assign("revlistcount", $revlistcount);
        $commitlines = array();
        $commitcount = min(100, count($revlist));
        for ($i = 0; $i < $commitcount; ++$i) {
            $commit = $revlist[$i];
            if (strlen(trim($commit)) > 0) {
                $commitline = array();
                if (isset($refs[$commit])) {
                    $commitline["commitref"] = $refs[$commit];
                }
                $co = git_read_commit($projectroot . $project, $commit);
                $ad = date_str($co['author_epoch']);
                $commitline["commit"] = $commit;
                $commitline["agestringage"] = $co['age_string_age'];
                $commitline["agestringdate"] = $co['age_string_date'];
                $commitline["authorname"] = $co['author_name'];
                $commitline["title_short"] = $co['title_short'];
                if (strlen($co['title_short']) < strlen($co['title'])) {
                    $commitline["title"] = $co['title'];
                }
                $commitlines[] = $commitline;
            }
        }
        $tpl->assign("commitlines", $commitlines);
    }
    $tpl->display('shortlog.tpl', $cachekey);
}
Ejemplo n.º 9
0
function git_tag($projectroot, $project, $hash)
{
    global $tpl;
    $cachekey = sha1($project) . "|" . $hash;
    if (!$tpl->is_cached('tag.tpl', $cachekey)) {
        $head = git_read_head($projectroot . $project);
        $tpl->assign("head", $head);
        $tpl->assign("hash", $hash);
        $tag = git_read_tag($projectroot . $project, $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);
}
function git_project_info($projectroot, $project)
{
    $git = new Git($projectroot . $project);
    $projinfo = array();
    $projinfo["project"] = $project;
    $projinfo["descr"] = git_project_descr($projectroot, $project, TRUE);
    $projinfo["owner"] = git_project_owner($projectroot, $project);
    try {
        $head = git_read_head($git, $project);
        $commit = git_read_commit($git, $head);
    } catch (Exception $e) {
        $head = '';
        $commit = array('age' => false, 'age_string' => false, 'age_class' => 'noage');
    }
    $projinfo['age_class'] = $commit['age_class'];
    $projinfo["age"] = $commit['age'];
    $projinfo["age_string"] = $commit['age_string'];
    return $projinfo;
}
Ejemplo n.º 11
0
function git_rss($projectroot, $project)
{
    global $tpl;
    header("Content-type: text/xml; charset=UTF-8");
    $cachekey = sha1($project);
    $git = new Git($projectroot . $project);
    if (!$tpl->is_cached('rss.tpl', $cachekey)) {
        $head = git_read_head($git);
        $revlist = git_read_revlist($git, $head, GITPHP_RSS_ITEMS);
        $tpl->assign("self", script_url());
        $commitlines = array();
        $revlistcount = count($revlist);
        for ($i = 0; $i < $revlistcount; ++$i) {
            $commit = $revlist[$i];
            $co = git_read_commit($git, $commit->getName());
            if ($i >= 20 && time() - $co['committer_epoch'] > 48 * 60 * 60) {
                break;
            }
            $cd = date_str($co['committer_epoch']);
            $difftree = array();
            $diffout = GitTree::diffTree(isset($commit->parent[0]) ? $commit->parent[0]->getTree() : null, $commit->getTree());
            foreach ($diffout as $file => $diff) {
                $difftree[] = $file;
            }
            $commitline = array();
            $commitline["cdmday"] = $cd['mday'];
            $commitline["cdmonth"] = $cd['month'];
            $commitline["cdhour"] = $cd['hour'];
            $commitline["cdminute"] = $cd['minute'];
            $commitline["title"] = $co['title'];
            $commitline["author"] = $co['author'];
            $commitline["cdrfc2822"] = $cd['rfc2822'];
            $commitline["commit"] = $commit;
            $commitline["comment"] = $co['comment'];
            $commitline["difftree"] = $difftree;
            $commitlines[] = $commitline;
        }
        $tpl->assign("commitlines", $commitlines);
    }
    $tpl->display('rss.tpl', $cachekey);
}
Ejemplo n.º 12
0
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);
}
Ejemplo n.º 13
0
function git_summary($projectroot, $project)
{
    global $tpl, $gitphp_conf;
    $cachekey = sha1($project);
    if (!$tpl->is_cached('project.tpl', $cachekey)) {
        $descr = git_project_descr($projectroot, $project);
        $head = git_read_head($projectroot . $project);
        $commit = git_read_commit($projectroot . $project, $head);
        $commitdate = date_str($commit['committer_epoch'], $commit['committer_tz']);
        $owner = git_project_owner($projectroot, $project);
        $refs = read_info_ref($projectroot . $project);
        $tpl->assign("head", $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($projectroot . $project, $head, 17);
        foreach ($revlist as $i => $rev) {
            $revdata = array();
            $revco = git_read_commit($projectroot . $project, $rev);
            $authordate = date_str($revco['author_epoch']);
            $revdata["commit"] = $rev;
            if (isset($refs[$rev])) {
                $revdata["commitref"] = $refs[$rev];
            }
            $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($projectroot, $project, "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($trimmed, 0, GITPHP_TRIM_LENGTH) . "...";
                    }
                    $taglist[$i]['comment'] = $com;
                }
            }
            $tpl->assign("taglist", $taglist);
        }
        $headlist = git_read_refs($projectroot, $project, "refs/heads");
        if (isset($headlist) && count($headlist) > 0) {
            $tpl->assign("headlist", $headlist);
        }
    }
    $tpl->display('project.tpl', $cachekey);
}
Ejemplo n.º 14
0
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);
}