示例#1
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);
}
function git_get_hash_by_path($project, $base, $path, $type = null)
{
    $tree = $base;
    $parts = explode("/", $path);
    $partcount = count($parts);
    foreach ($parts as $i => $part) {
        $lsout = git_ls_tree($project, $tree);
        $entries = explode("\n", $lsout);
        foreach ($entries as $j => $line) {
            if (preg_match("/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)\$/", $line, $regs)) {
                if ($regs[4] == $part) {
                    if ($i == $partcount - 1) {
                        return $regs[3];
                    }
                    if ($regs[2] == "tree") {
                        $tree = $regs[3];
                    }
                    break;
                }
            }
        }
    }
}
示例#3
0
/**
 * Get information about the given object in a tree, or null if not in the tree.
 */
function git_ls_tree_part($project, $tree, $name)
{
    $entries = git_ls_tree($project, $tree);
    foreach ($entries as $entry) {
        if ($entry['name'] === $name) {
            return $entry;
        }
    }
    return null;
}
示例#4
0
文件: git.php 项目: rwaldron/git-php
function html_tree($proj, $tree)
{
    global $extEnscript;
    $t = git_ls_tree(get_repo_path($proj), $tree);
    echo "<div class=\"gitbrowse\">\n";
    echo "<table>\n";
    foreach ($t as $obj) {
        $plain = "";
        $dlfile = "";
        $icon = "";
        $perm = perm_string($obj['perm']);
        if ($obj['type'] == 'tree') {
            $objlink = html_ahref(array('p' => $proj, 'a' => "jump_to_tag", 't' => $obj['hash'])) . $obj['file'] . "</a>\n";
            $icon = "<img src=\"" . sanitized_url() . "dl=icon_folder\" style=\"border-width: 0px;\"/>";
        } elseif ($obj['type'] == 'blob') {
            $plain = html_ahref(array('p' => $proj, 'dl' => "plain", 'h' => $obj['hash'], 'n' => $obj['file'])) . "plain</a>";
            $dlfile = " | " . html_ahref(array('p' => $proj, 'dl' => "dlfile", 'h' => $obj['hash'], 'n' => $obj['file'])) . "file</a>";
            $objlink = html_ahref(array('p' => $proj, 'a' => "jump_to_tag", 'b' => $obj['hash'], 'n' => $obj['file']), "blob") . $obj['file'] . "</a>\n";
            $ext = @$extEnscript[strrchr($obj['file'], ".")];
            if ($ext == "") {
                $icon = "<img src=\"" . sanitized_url() . "dl=icon_plain\" style=\"border-width: 0px;\"/>";
            } else {
                $icon = "<img src=\"" . sanitized_url() . "dl=icon_color\" style=\"border-width: 0px;\"/>";
            }
        }
        echo "<tr><td>{$perm}</td><td>{$icon}</td></td><td>{$objlink}</td><td>{$plain}{$dlfile}</td></tr>\n";
    }
    echo "</table>\n";
    echo "</div>\n";
}
示例#5
0
文件: index.php 项目: n3wtron/viewgit
    if (isset($_REQUEST['f'])) {
        $page['path'] = $_REQUEST['f'];
        // TODO validate?
    }
    // get path info for the header
    $page['pathinfo'] = git_get_path_info($page['project'], $page['commit_id'], $page['path']);
    if (!isset($page['tree_id'])) {
        // Take the last hash from the tree
        if (count($page['pathinfo']) > 0) {
            $page['tree_id'] = $page['pathinfo'][count($page['pathinfo']) - 1]['hash'];
        } else {
            $page['tree_id'] = 'HEAD';
        }
    }
    $page['subtitle'] = "Tree " . substr($page['tree_id'], 0, 6);
    $page['entries'] = git_ls_tree($page['project'], $page['tree_id']);
} elseif ($action === 'viewblob') {
    $template = 'blob';
    $page['project'] = validate_project($_REQUEST['p']);
    $page['hash'] = validate_hash($_REQUEST['h']);
    $page['title'] = "{$page['project']} - Blob - ViewGit";
    if (isset($_REQUEST['hb'])) {
        $page['commit_id'] = validate_hash($_REQUEST['hb']);
    } else {
        $page['commit_id'] = 'HEAD';
    }
    $page['subtitle'] = "Blob " . substr($page['hash'], 0, 6);
    $page['path'] = '';
    if (isset($_REQUEST['f'])) {
        $page['path'] = $_REQUEST['f'];
        // TODO validate?
示例#6
0
function html_tree($proj, $cid, $filepath)
{
    $str = '';
    $t = git_ls_tree(get_repo_path($proj), $cid, $filepath);
    $str .= "<div class=\"gittree\">\n";
    $str .= "<table>\n";
    foreach ($t as $obj) {
        $plain = "";
        $perm = perm_string($obj['perm']);
        $f = isset($filepath) ? "{$filepath}/{$obj['file']}" : $obj['file'];
        if ($obj['type'] == 'tree') {
            $objlink = html_ahref(array('p' => $proj, 'c' => $cid, 'f' => $f), $obj['file']);
        } else {
            if ($obj['type'] == 'blob') {
                $plain = html_ahref(array('p' => $proj, 'dl' => 'plain', 'c' => $cid, 'b' => $obj['hash']), 'plain');
                $objlink = html_ahref(array('p' => $proj, 'c' => $cid, 'b' => $obj['hash'], 'f' => $f), $obj['file'], 'blob');
            }
        }
        $str .= "<tr><td>{$perm}</td><td>{$objlink}</td><td>{$plain}</td></tr>\n";
    }
    $str .= "</table>\n";
    $str .= "</div>\n";
    return $str;
}