Пример #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_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);
}
Пример #3
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);
}
Пример #4
0
function git_blobdiff_plain($projectroot, $project, $hash, $hashbase, $hashparent, $file)
{
    global $tpl;
    header("Content-type: text/plain; charset=UTF-8");
    $cachekey = sha1($project) . "|" . $hashbase . "|" . $hash . "|" . $hashparent . "|" . sha1($file);
    if (!$tpl->is_cached('blobdiffplain.tpl', $cachekey)) {
        $ret = prep_tmpdir();
        if ($ret !== TRUE) {
            echo $ret;
            return;
        }
        $tpl->assign("blobdiff", git_diff($projectroot . $project, $hashparent, $file ? "a/" . $file : $hashparent, $hash, $file ? "b/" . $file : $hash));
    }
    $tpl->display('blobdiffplain.tpl', $cachekey);
}