Esempio n. 1
0
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_commitdiff($projectroot, $project, $hash, $hash_parent)
{
    global $tpl;
    $cachekey = sha1($project) . "|" . $hash . "|" . $hash_parent;
    $git = new Git($projectroot . $project);
    $hash = sha1_bin($hash);
    if (isset($hash_parent)) {
        $hash_parent = sha1_bin($hash_parent);
    }
    if (!$tpl->is_cached('commitdiff.tpl', $cachekey)) {
        $co = git_read_commit($git, $hash);
        $ad = date_str($co['author_epoch']);
        $tpl->assign('committer', $co['committer']);
        $tpl->assign('rfc2822', $ad['rfc2822']);
        if (!isset($hash_parent) && isset($co['parent'])) {
            $hash_parent = sha1_bin($co['parent']);
        }
        $a_tree = isset($hash_parent) ? $git->getObject($hash_parent)->getTree() : array();
        $b_tree = $git->getObject(sha1_bin($co['tree']));
        $difftree = GitTree::diffTree($a_tree, $b_tree);
        $tpl->assign("hash", sha1_hex($hash));
        $tpl->assign("tree", $co['tree']);
        $tpl->assign("hashparent", sha1_hex($hash_parent));
        $tpl->assign("title", $co['title']);
        $refs = read_info_ref($git);
        if (isset($refs[$hash])) {
            $tpl->assign("commitref", $refs[$hash]);
        }
        $tpl->assign("comment", $co['comment']);
        $difftreelines = array();
        $status_map = array(GitTree::TREEDIFF_ADDED => "A", GitTree::TREEDIFF_REMOVED => "D", GitTree::TREEDIFF_CHANGED => "M");
        foreach ($difftree as $file => $diff) {
            $difftreeline = array();
            $difftreeline["from_mode"] = decoct($diff->old_mode);
            $difftreeline["to_mode"] = decoct($diff->new_mode);
            $difftreeline["from_id"] = sha1_hex($diff->old_obj);
            $difftreeline["to_id"] = sha1_hex($diff->new_obj);
            $difftreeline["status"] = $status_map[$diff->status];
            $difftreeline["file"] = $file;
            $difftreeline["md5"] = md5($file);
            $difftreeline["from_type"] = file_type($difftreeline["from_mode"]);
            $difftreeline["to_type"] = file_type($difftreeline["to_mode"]);
            if ($diff->status == GitTree::TREEDIFF_ADDED) {
                $difftreeline['diffout'] = explode("\n", git_diff($git, null, "/dev/null", $diff->new_obj, "b/" . $file));
            } else {
                if ($diff->status == GitTree::TREEDIFF_REMOVED) {
                    $difftreeline['diffout'] = explode("\n", git_diff($git, $diff->old_obj, "a/" . $file, null, "/dev/null"));
                } else {
                    if ($diff->status == GitTree::TREEDIFF_CHANGED && $diff->old_obj != $diff->new_obj) {
                        $difftreeline['diffout'] = explode("\n", git_diff($git, $diff->old_obj, "a/" . $file, $diff->new_obj, "b/" . $file));
                    }
                }
            }
            $difftreelines[] = $difftreeline;
        }
        $tpl->assign("difftreelines", $difftreelines);
    }
    $tpl->display('commitdiff.tpl', $cachekey);
}
function git_commitdiff_plain($projectroot, $project, $hash, $hash_parent)
{
    global $tpl;
    $cachekey = sha1($project) . "|" . $hash . "|" . $hash_parent;
    header("Content-type: text/plain; charset=UTF-8");
    header("Content-disposition: inline; filename=\"git-" . $hash . ".patch\"");
    if (!$tpl->is_cached('diff_plaintext.tpl', $cachekey)) {
        $ret = prep_tmpdir();
        if ($ret !== TRUE) {
            echo $ret;
            return;
        }
        $co = git_read_commit($projectroot . $project, $hash);
        if (!isset($hash_parent)) {
            $hash_parent = $co['parent'];
        }
        $diffout = git_diff_tree($projectroot . $project, $hash_parent . " " . $hash);
        $difftree = explode("\n", $diffout);
        $refs = read_info_ref($projectroot . $project, "tags");
        $listout = git_read_revlist($projectroot . $project, "HEAD");
        foreach ($listout as $i => $rev) {
            if (isset($refs[$rev])) {
                $tagname = $refs[$rev];
            }
            if ($rev == $hash) {
                break;
            }
        }
        $ad = date_str($co['author_epoch'], $co['author_tz']);
        $tpl->assign("from", $co['author']);
        $tpl->assign("date", $ad['rfc2822']);
        $tpl->assign("subject", $co['title']);
        if (isset($tagname)) {
            $tpl->assign("tagname", $tagname);
        }
        $tpl->assign("url", script_url() . "?p=" . $project . "&a=commitdiff&h=" . $hash);
        $tpl->assign("comment", $co['comment']);
        $diffs = array();
        foreach ($difftree as $i => $line) {
            if (preg_match("/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)\$/", $line, $regs)) {
                if ($regs[5] == "A") {
                    $diffs[] = git_diff($projectroot . $project, null, "/dev/null", $regs[4], "b/" . $regs[6]);
                } else {
                    if ($regs[5] == "D") {
                        $diffs[] = git_diff($projectroot . $project, $regs[3], "a/" . $regs[6], null, "/dev/null");
                    } else {
                        if ($regs[5] == "M") {
                            $diffs[] = git_diff($projectroot . $project, $regs[3], "a/" . $regs[6], $regs[4], "b/" . $regs[6]);
                        }
                    }
                }
            }
        }
        $tpl->assign("diffs", $diffs);
    }
    $tpl->display('diff_plaintext.tpl', $cachekey);
}
Esempio n. 4
0
function git_commitdiff($projectroot, $project, $hash, $hash_parent)
{
    global $tpl;
    $cachekey = sha1($project) . "|" . $hash . "|" . $hash_parent;
    if (!$tpl->is_cached('commitdiff.tpl', $cachekey)) {
        $ret = prep_tmpdir();
        if ($ret !== TRUE) {
            echo $ret;
            return;
        }
        $co = git_read_commit($projectroot . $project, $hash);
        if (!isset($hash_parent)) {
            $hash_parent = $co['parent'];
        }
        $diffout = git_diff_tree($projectroot . $project, $hash_parent . " " . $hash);
        $difftree = explode("\n", $diffout);
        $refs = read_info_ref($projectroot . $project);
        $tpl->assign("hash", $hash);
        $tpl->assign("tree", $co['tree']);
        $tpl->assign("hashparent", $hash_parent);
        $tpl->assign("title", $co['title']);
        if (isset($refs[$co['id']])) {
            $tpl->assign("commitref", $refs[$co['id']]);
        }
        $tpl->assign("comment", $co['comment']);
        $difftreelines = array();
        foreach ($difftree as $i => $line) {
            if (preg_match("/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)\$/", $line, $regs)) {
                $difftreeline = array();
                $difftreeline["from_mode"] = $regs[1];
                $difftreeline["to_mode"] = $regs[2];
                $difftreeline["from_id"] = $regs[3];
                $difftreeline["to_id"] = $regs[4];
                $difftreeline["status"] = $regs[5];
                $difftreeline["file"] = $regs[6];
                $difftreeline["from_type"] = file_type($regs[1]);
                $difftreeline["to_type"] = file_type($regs[2]);
                if ($regs[5] == "A") {
                    $difftreeline['diffout'] = explode("\n", git_diff($projectroot . $project, null, "/dev/null", $regs[4], "b/" . $regs[6]));
                } else {
                    if ($regs[5] == "D") {
                        $difftreeline['diffout'] = explode("\n", git_diff($projectroot . $project, $regs[3], "a/" . $regs[6], null, "/dev/null"));
                    } else {
                        if ($regs[5] == "M" && $regs[3] != $regs[4]) {
                            $difftreeline['diffout'] = explode("\n", git_diff($projectroot . $project, $regs[3], "a/" . $regs[6], $regs[4], "b/" . $regs[6]));
                        }
                    }
                }
                $difftreelines[] = $difftreeline;
            }
        }
        $tpl->assign("difftreelines", $difftreelines);
    }
    $tpl->display('commitdiff.tpl', $cachekey);
}
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);
}
Esempio n. 6
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);
}
Esempio n. 7
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);
}
Esempio 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);
}
Esempio n. 9
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);
}
Esempio n. 10
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);
}
Esempio n. 11
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);
}
Esempio n. 12
0
function git_commit($projectroot, $project, $hash)
{
    global $tpl;
    $cachekey = sha1($project) . "|" . $hash;
    if (!$tpl->is_cached('commit.tpl', $cachekey)) {
        $co = git_read_commit($projectroot . $project, $hash);
        $ad = date_str($co['author_epoch'], $co['author_tz']);
        $cd = date_str($co['committer_epoch'], $co['committer_tz']);
        if (isset($co['parent'])) {
            $root = "";
            $parent = $co['parent'];
        } else {
            $root = "--root";
            $parent = "";
        }
        $diffout = git_diff_tree($projectroot . $project, $root . " " . $parent . " " . $hash, TRUE);
        $difftree = explode("\n", $diffout);
        $tpl->assign("hash", $hash);
        $tpl->assign("tree", $co['tree']);
        if (isset($co['parent'])) {
            $tpl->assign("parent", $co['parent']);
        }
        $tpl->assign("title", $co['title']);
        $refs = read_info_ref($projectroot . $project);
        if (isset($refs[$co['id']])) {
            $tpl->assign("commitref", $refs[$co['id']]);
        }
        $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("repository", preg_replace('/^([a-zA-Z0-9\\-\\_]+).git$/', '$1', $project));
        $tpl->assign("parents", $co['parents']);
        $tpl->assign("comment", $co['comment']);
        $tpl->assign("difftreesize", count($difftree) + 1);
        $difftreelines = array();
        foreach ($difftree as $i => $line) {
            if (preg_match("/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)\$/", $line, $regs)) {
                $difftreeline = array();
                $difftreeline["from_mode"] = $regs[1];
                $difftreeline["to_mode"] = $regs[2];
                $difftreeline["from_mode_cut"] = substr($regs[1], -4);
                $difftreeline["to_mode_cut"] = substr($regs[2], -4);
                $difftreeline["from_id"] = $regs[3];
                $difftreeline["to_id"] = $regs[4];
                $difftreeline["status"] = $regs[5];
                $difftreeline["similarity"] = ltrim($regs[6], "0");
                $difftreeline["file"] = $regs[7];
                $difftreeline["from_file"] = strtok($regs[7], "\t");
                $difftreeline["from_filetype"] = file_type($regs[1]);
                $difftreeline["to_file"] = strtok("\t");
                $difftreeline["to_filetype"] = file_type($regs[2]);
                if ((octdec($regs[2]) & 0x8000) == 0x8000) {
                    $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);
}
Esempio n. 13
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);
}