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_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); }