function git_blob_plain($projectroot, $project, $hash, $file) { global $gitphp_conf, $tpl; $cachekey = sha1($project) . "|" . $hash . "|" . sha1($file); $buffer = null; $git = new Git($projectroot . $project); $hash = $git->revParse($hash); // XXX: Nasty hack to cache headers if (!$tpl->is_cached('blobheaders.tpl', $cachekey)) { if ($file) { $saveas = $file; } else { $saveas = $hash . ".txt"; } $buffer = $git->getObject($hash)->data; if ($gitphp_conf['filemimetype']) { $mime = file_mime($buffer, $file); } $headers = array(); if ($mime) { $headers[] = "Content-type: " . $mime; } else { $headers[] = "Content-type: text/plain; charset=UTF-8"; } $headers[] = "Content-disposition: inline; filename=\"" . $saveas . "\""; $tpl->assign("blobheaders", serialize($headers)); } $out = $tpl->fetch('blobheaders.tpl', $cachekey); $returnedheaders = unserialize($out); foreach ($returnedheaders as $i => $header) { header($header); } if (!$tpl->is_cached('blobplain.tpl', $cachekey)) { if (!$buffer) { $buffer = $git->getObject($hash)->data; } $tpl->assign("blob", $buffer); } $tpl->display('blobplain.tpl', $cachekey); }
$user = NULL; } } } $view->user = $user; // Git {{{1 $repo = new Git(Config::GIT_PATH); $parts = explode('?', $_SERVER['REQUEST_URI'], 2); assert(!strncmp($parts[0], Config::PATH, strlen(Config::PATH))); $parts[0] = substr($parts[0], strlen(Config::PATH)); $tip = $repo->getTip(Config::GIT_BRANCH); $commit = $tip; if (isset($_GET['commit'])) { $commit = sha1_bin($_GET['commit']); } $commit = $repo->getObject($commit); $commit_id = sha1_hex($commit->getName()); $view->commit_id = $commit_id; $link_to_tip = !isset($_GET['commit']); $commit_is_tip = $commit->getName() == $tip; $view->commit_is_tip = $commit_is_tip; $view->n_conflicts = count(ls_r(sprintf('%s/refs/heads/%s', Config::GIT_PATH, Config::GIT_CONFLICT_BRANCH_DIR))); // URL parsing {{{1 $special = $page = NULL; if (!strncmp($parts[0], '/:', 2)) { $special = explode('/', substr($parts[0], 2), 2); } if ($special === NULL) { $action = isset($_GET['action']) ? $_GET['action'] : ''; if ($action == '') { $action = 'view';