示例#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);
}
示例#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_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\"");
    $git = new Git($projectroot . $project);
    $hash = sha1_bin($hash);
    if (isset($hash_parent)) {
        $hash_parent = sha1_bin($hash_parent);
    }
    if (!$tpl->is_cached('diff_plaintext.tpl', $cachekey)) {
        $co = git_read_commit($git, $hash);
        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);
        // FIXME: simplified tagname search is not implemented yet
        /*$refs = read_info_ref($git,"tags");
        		$listout = git_read_revlist($git, "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=" . sha1_hex($hash));
        $tpl->assign("comment", $co['comment']);
        $diffs = array();
        foreach ($difftree as $file => $diff) {
            if ($diff->status == GitTree::TREEDIFF_ADDED) {
                $diffs[] = git_diff($git, null, "/dev/null", $diff->new_obj, "b/" . $file);
            } else {
                if ($diff->status == GitTree::TREEDIFF_REMOVED) {
                    $diffs[] = git_diff($git, $diff->old_obj, "a/" . $file, null, "/dev/null");
                } else {
                    if ($diff->status == GitTree::TREEDIFF_CHANGED) {
                        $diffs[] = git_diff($git, $diff->old_obj, "a/" . $file, $diff->new_obj, "b/" . $file);
                    }
                }
            }
        }
        $tpl->assign("diffs", $diffs);
    }
    $tpl->display('diff_plaintext.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);
}
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;
}
示例#8
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);
}
示例#9
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);
}
示例#10
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);
}
示例#11
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);
}
示例#12
0
function git_read_ref($project, $ref_id, $ref_file)
{
    $hash = $project->revParse(trim($ref_id));
    $type = git_get_type($project, $hash);
    if (!$type) {
        return null;
    }
    $ref_item = array();
    $ref_item['type'] = $type;
    $ref_item['id'] = $ref_id;
    $ref_item['epoch'] = 0;
    $ref_item['age_string'] = "unknown";
    if ($type == "tag") {
        $tag = git_read_tag($project, $hash);
        $ref_item['comment'] = $tag['comment'];
        if ($tag['type'] == "commit") {
            $co = git_read_commit($project, sha1_bin($tag['object']));
            $ref_item['epoch'] = $co['committer_epoch'];
            $ref_item['age_string'] = $co['age_string'];
            $ref_item['age'] = $co['age'];
        } else {
            if (isset($tag['epoch'])) {
                $age = time() - $tag['epoch'];
                $ref_item['epoch'] = $tag['epoch'];
                $ref_item['age_string'] = age_string($age);
                $ref_item['age'] = $age;
            }
        }
        $ref_item['reftype'] = $tag['type'];
        $ref_item['name'] = $tag['name'];
        $ref_item['refid'] = $tag['object'];
    } else {
        if ($type == "commit") {
            $co = git_read_commit($project, $hash);
            $ref_item['reftype'] = "commit";
            $ref_item['name'] = $ref_file;
            $ref_item['title'] = $co['title'];
            $ref_item['refid'] = $ref_id;
            $ref_item['epoch'] = $co['committer_epoch'];
            $ref_item['age_string'] = $co['age_string'];
            $ref_item['age'] = $co['age'];
        }
    }
    return $ref_item;
}
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;
}
示例#14
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);
}
示例#15
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);
}
示例#16
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);
}
示例#17
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);
}
示例#18
0
function git_search_files($projectroot, $project, $hash, $search, $page = 0)
{
    global $tpl, $gitphp_conf;
    $cachekey = sha1($project) . "|" . $hash . "|" . "filesearch" . "|" . sha1($search) . "|" . (isset($page) ? $page : 0);
    if (!$tpl->is_cached('searchfiles.tpl', $cachekey)) {
        if (!($gitphp_conf['search'] && $gitphp_conf['filesearch'])) {
            git_message("File search has been disabled", TRUE, TRUE);
            return;
        }
        if (!isset($search) || strlen($search) < 2) {
            git_message("You must enter search text of at least 2 characters", TRUE, TRUE);
            return;
        }
        if (!isset($hash)) {
            //$hash = git_read_head($projectroot . $project);
            $hash = "HEAD";
        }
        $co = git_read_commit($projectroot . $project, $hash);
        $filesearch = git_filesearch($projectroot . $project, $hash, $search, false, $page * 100, 101);
        if (count($filesearch) < 1) {
            git_message("No matches for '" . $search . "'.", FALSE, TRUE);
            return;
        }
        $tpl->assign("hash", $hash);
        $tpl->assign("treehash", $co['tree']);
        $tpl->assign("search", $search);
        $tpl->assign("searchtype", "file");
        $tpl->assign("page", $page);
        $filesearchcount = count($filesearch);
        $tpl->assign("filesearchcount", $filesearchcount);
        $tpl->assign("title", $co['title']);
        $filesearchlines = array();
        $i = 0;
        foreach ($filesearch as $file => $data) {
            $filesearchline = array();
            $filesearchline["file"] = $file;
            if (strpos($file, "/") !== false) {
                $f = basename($file);
                $d = dirname($file);
                if ($d == "/") {
                    $d = "";
                }
                $hlt = highlight($f, $search, "searchmatch");
                if ($hlt) {
                    $hlt = $d . "/" . $hlt;
                }
            } else {
                $hlt = highlight($file, $search, "searchmatch");
            }
            if ($hlt) {
                $filesearchline["filename"] = $hlt;
            } else {
                $filesearchline["filename"] = $file;
            }
            $filesearchline["hash"] = $data['hash'];
            if ($data['type'] == "tree") {
                $filesearchline["tree"] = TRUE;
            }
            if (isset($data['lines'])) {
                $matches = array();
                foreach ($data['lines'] as $line) {
                    $hlt = highlight($line, $search, "searchmatch", floor(GITPHP_TRIM_LENGTH * 1.5), true);
                    if ($hlt) {
                        $matches[] = $hlt;
                    }
                }
                if (count($matches) > 0) {
                    $filesearchline["matches"] = $matches;
                }
            }
            $filesearchlines[] = $filesearchline;
            ++$i;
            if ($i >= 100) {
                break;
            }
        }
        $tpl->assign("filesearchlines", $filesearchlines);
    }
    $tpl->display('searchfiles.tpl', $cachekey);
}
示例#19
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);
}
示例#20
0
function git_search($projectroot, $project, $hash, $search, $searchtype, $page = 0)
{
    global $tpl, $gitphp_conf;
    $cachekey = sha1($project) . "|" . $hash . "|" . sha1($searchtype) . "|" . sha1($search) . "|" . (isset($page) ? $page : 0);
    if (!$tpl->is_cached('search.tpl', $cachekey)) {
        if (!$gitphp_conf['search']) {
            git_message("Search has been disabled", TRUE, TRUE);
            return;
        }
        if (!isset($search) || strlen($search) < 2) {
            git_message("You must enter search text of at least 2 characters", TRUE, TRUE);
            return;
        }
        if (!isset($hash)) {
            //$hash = git_read_head($projectroot . $project);
            $hash = "HEAD";
        }
        $co = git_read_commit($projectroot . $project, $hash);
        $revlist = git_read_revlist($projectroot . $project, $hash, 101, $page * 100, FALSE, FALSE, $searchtype, $search);
        if (count($revlist) < 1 || strlen($revlist[0]) < 1) {
            git_message("No matches for '" . $search . "'.", FALSE, TRUE);
            return;
        }
        $tpl->assign("hash", $hash);
        $tpl->assign("treehash", $co['tree']);
        $tpl->assign("search", $search);
        $tpl->assign("searchtype", $searchtype);
        $tpl->assign("page", $page);
        $revlistcount = count($revlist);
        $tpl->assign("revlistcount", $revlistcount);
        $tpl->assign("title", $co['title']);
        $commitlines = array();
        $commitcount = min(100, $revlistcount);
        for ($i = 0; $i < $commitcount; ++$i) {
            $commit = $revlist[$i];
            if (strlen(trim($commit)) > 0) {
                $commitline = array();
                $co2 = git_read_commit($projectroot . $project, $commit);
                $commitline["commit"] = $commit;
                $commitline["agestringage"] = $co2['age_string_age'];
                $commitline["agestringdate"] = $co2['age_string_date'];
                $commitline["authorname"] = $co2['author_name'];
                $commitline["title_short"] = $co2['title_short'];
                if (strlen($co2['title_short']) < strlen($co2['title'])) {
                    $commitline["title"] = $co2['title'];
                }
                $commitline["committree"] = $co2['tree'];
                $matches = array();
                foreach ($co2['comment'] as $comline) {
                    $hl = highlight($comline, $search, "searchmatch", GITPHP_TRIM_LENGTH);
                    if ($hl && strlen($hl) > 0) {
                        $matches[] = $hl;
                    }
                }
                $commitline["matches"] = $matches;
                $commitlines[] = $commitline;
            }
        }
        $tpl->assign("commitlines", $commitlines);
    }
    $tpl->display('search.tpl', $cachekey);
}
示例#21
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);
}