function git_read_tag($proj, $tag_id) { $obj = $proj->getObject($tag_id); if ($obj->getType() != Git::OBJ_TAG) { return; } $tag['id'] = sha1_hex($tag_id); if ($obj->object !== null) { $tag['object'] = sha1_hex($obj->object); } if ($obj->objtype !== null) { $tag['type'] = Git::getTypeName($obj->objtype); } if ($obj->tag !== null) { $tag['name'] = $obj->tag; } if ($obj->tagger !== null) { $tag['author'] = $obj->tagger->name; $tag['epoch'] = $obj->tagger->time; $tag['tz'] = sprintf("%+03d%02d", $obj->tagger->offset / 3600, abs($obj->tagger->offset % 3600 / 60)); } $tag['comment'] = explode("\n", $obj->summary . "\n" . $obj->detail); if (!isset($tag['name'])) { return null; } return $tag; }
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\""); $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); }
public function _serialize() { $s = ''; $s .= sprintf("tree %s\n", sha1_hex($this->tree)); foreach ($this->parents as $parent) { $s .= sprintf("parent %s\n", sha1_hex($parent)); } $s .= sprintf("author %s\n", $this->author->serialize()); $s .= sprintf("committer %s\n", $this->committer->serialize()); $s .= "\n" . $this->summary . "\n" . $this->detail; return $s; }
function git_heads($projectroot, $project) { global $tpl; $cachekey = sha1($project); $git = new Git($projectroot . $project); if (!$tpl->is_cached('heads.tpl', $cachekey)) { $head = git_read_head($git); $tpl->assign("head", sha1_hex($head)); $headlist = git_read_refs($git, "refs/heads"); $tpl->assign("headlist", $headlist); } $tpl->display('heads.tpl', $cachekey); }
function git_tags($projectroot, $project) { global $tpl; $cachekey = sha1($project); $git = new Git($projectroot . $project); if (!$tpl->is_cached('tags.tpl', $cachekey)) { $head = git_read_head($git); $tpl->assign("head", sha1_hex($head)); $taglist = git_read_refs($git, "refs/tags"); if (isset($taglist) && count($taglist) > 0) { $tpl->assign("taglist", $taglist); } } $tpl->display('tags.tpl', $cachekey); }
function git_read_commit($proj, $head) { $obj = $proj->getObject($head); if ($obj->getType() != Git::OBJ_COMMIT) { return; } $commit = array(); $commit['id'] = sha1_hex($obj->getName()); $parents = array(); foreach ($obj->parents as $par) { $parents[] = sha1_hex($par); } $commit['parents'] = $parents; if (isset($parents[0])) { $commit['parent'] = $parents[0]; } $commit['tree'] = sha1_hex($obj->tree); $commit['author'] = sprintf("%s <%s>", $obj->author->name, $obj->author->email); $commit['author_epoch'] = $obj->author->time; $commit['author_tz'] = sprintf("%+03d%02d", $obj->author->offset / 3600, abs($obj->author->offset % 3600 / 60)); $commit['author_name'] = $obj->author->name; $commit['committer'] = sprintf("%s <%s>", $obj->committer->name, $obj->committer->email); $commit['committer_epoch'] = $obj->committer->time; $commit['committer_tz'] = sprintf("%+03d%02d", $obj->committer->offset / 3600, abs($obj->committer->offset % 3600 / 60)); $commit['committer_name'] = $obj->committer->name; $commit['title'] = $obj->summary; if (strlen($obj->summary) > GITPHP_TRIM_LENGTH) { $commit['title_short'] = substr($obj->summary, 0, GITPHP_TRIM_LENGTH) . "..."; } else { $commit['title_short'] = $obj->summary; } $comment = explode("\n", $obj->summary . "\n" . $obj->detail); $commit['comment'] = $comment; $age = (int) (time() - $commit['committer_epoch']); $commit['age'] = $age; $commit['age_string'] = age_string($age); date_default_timezone_set("UTC"); $age_class = $age <= 7200 ? 'age0' : ($age >= 7200 && $age <= 172800 ? 'age1' : ($age >= 172800 ? 'age2' : 'noage')); $commit['age_class'] = $age_class; if ($age > 60 * 60 * 24 * 7 * 2) { $commit['age_string_date'] = date("Y-m-d", $commit['committer_epoch']); $commit['age_string_age'] = $commit['age_string']; } else { $commit['age_string_date'] = $commit['age_string']; $commit['age_string_age'] = date("Y-m-d", $commit['committer_epoch']); } return $commit; }
function git_path_tree($project, $base, $filename) { if (strlen($filename) < 1) { return null; } $path = array(); $path['full'] = $filename; $spath = $filename; $spos = strrpos($spath, "/"); if ($spos !== false) { $spath = substr($spath, $spos + 1); } $path['short'] = $spath; $path['tree'] = sha1_hex(git_get_hash_by_path($project, $base, $filename)); return $path; }
function git_tag($projectroot, $project, $hash) { global $tpl; $cachekey = sha1($project) . "|" . $hash; $git = new Git($projectroot . $project); $hash = $git->revParse($hash); if (!$tpl->is_cached('tag.tpl', $cachekey)) { $head = git_read_head($git); $tpl->assign("head", sha1_hex($head)); $tpl->assign("hash", sha1_hex($hash)); $tag = git_read_tag($git, $hash); $tpl->assign("tag", $tag); if (isset($tag['author'])) { $ad = date_str($tag['epoch'], $tag['tz']); $tpl->assign("datedata", $ad); } } $tpl->display('tag.tpl', $cachekey); }
function git_blobdiff($projectroot, $project, $hash, $hashbase, $hashparent, $file) { global $tpl; $cachekey = sha1($project) . "|" . $hashbase . "|" . $hash . "|" . $hashparent . "|" . sha1($file); $git = new Git($projectroot . $project); 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); } $hash = sha1_bin($hash); $hashbase = sha1_bin($hashbase); $hashparent = sha1_bin($hashparent); if ($co = git_read_commit($git, $hashbase)) { $tpl->assign("fullnav", TRUE); $tpl->assign("tree", sha1_hex($co['tree'])); $tpl->assign("title", $co['title']); $refs = read_info_ref($git); if (isset($refs[$hashbase])) { $tpl->assign("hashbaseref", $refs[$hashbase]); } } $paths = git_path_trees($git, $git->getObject($hashbase), $file); $tpl->assign("paths", $paths); $diffout = explode("\n", git_diff($git, $hashparent, $file ? $file : $hashparent, $hash, $file ? $file : $hash)); $tpl->assign("diff", $diffout); } $tpl->display('blobdiff.tpl', $cachekey); }
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); }
<?php require_once '../lib/common.inc.php'; require_once 'lib/project.class.php'; $name = $_REQUEST['project']; $project = new Project($name); $data = array(); if (!$project->hasRepo()) { $data['status'] = 'norepo'; } else { $repo = $project->getRepo(); $latestCommit = $repo->getObject($repo->getTip()); $data['status'] = 'commit'; $data['currentCommit'] = array('sha1' => sha1_hex($repo->getTip()), 'author' => $latestCommit->author->name, 'summary' => $latestCommit->summary); } echo json_encode($data);
function git_blob($projectroot, $project, $hash, $file, $hashbase) { global $gitphp_conf, $tpl; $cachekey = sha1($project) . "|" . $hashbase . "|" . $hash . "|" . sha1($file); $git = new Git($projectroot . $project); if (isset($hash)) { $hash = $git->revParse($hash); } if (isset($hashbase)) { $hashbase = $git->revParse($hashbase); } if (!$tpl->is_cached('blob.tpl', $cachekey)) { $head = git_read_head($git); if (!isset($hashbase)) { $hashbase = $head; } if (!isset($hash) && isset($file)) { $hash = git_get_hash_by_path($git, $git->getObject($hashbase), $file, "blob"); } $catout = $git->getObject($hash)->data; $tpl->assign("hash", sha1_hex($hash)); $tpl->assign("hashbase", sha1_hex($hashbase)); $tpl->assign("head", sha1_hex($head)); if ($co = git_read_commit($git, $hashbase)) { $tpl->assign("fullnav", TRUE); $refs = read_info_ref($git); $tpl->assign("tree", $co['tree']); $tpl->assign("title", $co['title']); if (isset($file)) { $tpl->assign("file", $file); } if (isset($refs[$hashbase])) { $tpl->assign("hashbaseref", $refs[$hashbase]); } } $paths = git_path_trees($git, $git->getObject($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("", 'php'); 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); }
public function _serialize() { $s = ''; if ($this->object !== null) { $s .= sprintf("object %s\n", sha1_hex($this->object)); $s .= sprintf("type %s\n", Git::getTypeName($this->objtype)); } if ($this->tag !== null) { $s .= sprintf("tag %s\n", $this->tagger->serialize()); } if ($this->tagger !== null) { $s .= sprintf("tagger %s\n", $this->tagger->serialize()); } $s .= "\n" . $this->summary . "\n" . $this->detail; return $s; }
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); }
protected function addObject($obj, $data) { $hash = hash_init("sha1"); hash_update($hash, Git::getTypeName($obj->type)); hash_update($hash, ' '); hash_update($hash, strlen($data)); hash_update($hash, ""); hash_update($hash, $data); $hash = hash_final($hash, true); if (isset($this->objects[$hash])) { throw new Exception(sprintf("duplicate object %s\n", sha1_hex($hash))); } $this->objects[$hash] = $obj; return $hash; }
/** * @brief Fetch an object in its binary representation by name. * * Throws an exception if the object cannot be found. * * @param $object_name (string) name of the object (binary SHA1) * @returns (array) an array consisting of the object type (int) and the * binary representation of the object (string) */ protected function getRawObject($object_name) { static $cache = array(); /* FIXME allow limiting the cache to a certain size */ if (isset($cache[$object_name])) { return $cache[$object_name]; } $sha1 = sha1_hex($object_name); $path = sprintf('%s/objects/%s/%s', $this->dir, substr($sha1, 0, 2), substr($sha1, 2)); if (file_exists($path)) { list($hdr, $object_data) = explode("", gzuncompress(file_get_contents($path)), 2); sscanf($hdr, "%s %d", $type, $object_size); $object_type = Git::getTypeID($type); $r = array($object_type, $object_data); } else { if ($x = $this->findPackedObject($object_name)) { list($pack_name, $object_offset) = $x; $pack = fopen(sprintf('%s/objects/pack/pack-%s.pack', $this->dir, sha1_hex($pack_name)), 'rb'); flock($pack, LOCK_SH); /* check magic and version */ $magic = fread($pack, 4); $version = Binary::fuint32($pack); if ($magic != 'PACK' || $version != 2) { throw new Exception('unsupported pack format'); } $r = $this->unpackObject($pack, $object_offset); fclose($pack); } else { throw new Exception(sprintf('object not found: %s', sha1_hex($object_name))); } } $cache[$object_name] = $r; return $r; }
try { $f = fopen(sprintf('%s/refs/heads/%s', $repo->dir, $branch), 'xb'); } catch (Exception $e) { /* * fopen() will raise a warning if the file already * exists, which Core will make into an Exception. */ } } flock($f, LOCK_EX); } foreach ($pending as $obj) { $obj->write(); } ftruncate($f, 0); fwrite($f, sha1_hex($newcommit->getName())); fclose($f); if ($fast_forward || $fast_merge) { redirect($page->getURL()); } else { redirect(sprintf('%s/:merge/%s?fresh', Config::PATH, join('/', array_map('urlencode', explode('/', $branch))))); } // }}} $committed = TRUE; } } if (!$committed) { $view->setTemplate('page-edit.php'); $view->page_type = $page->getPageType(); $view->is_binary = isset($content) ? $_POST['type'] == 'file' : $view->page_type == WikiPage::TYPE_BINARY || $view->page_type == WikiPage::TYPE_IMAGE; if (isset($content) && !$view->is_binary) {
/** * @brief Write this object in its serialized form to the git repository * given at creation time. */ public function write() { $sha1 = sha1_hex($this->name); $path = sprintf('%s/objects/%s/%s', $this->repo->dir, substr($sha1, 0, 2), substr($sha1, 2)); if (file_exists($path)) { return FALSE; } $dir = dirname($path); if (!is_dir($dir)) { mkdir(dirname($path), 0770); } $f = fopen($path, 'ab'); flock($f, LOCK_EX); ftruncate($f, 0); $data = $this->serialize(); $data = Git::getTypeName($this->type) . ' ' . strlen($data) . "" . $data; fwrite($f, gzcompress($data)); fclose($f); return TRUE; }
function git_summary($projectroot, $project) { global $tpl, $gitphp_conf; $cachekey = sha1($project); $git = new Git($projectroot . $project); if (!$tpl->is_cached('project.tpl', $cachekey)) { $descr = git_project_descr($projectroot, $project); $head = git_read_head($git); $commit = git_read_commit($git, $head); $commitdate = date_str($commit['committer_epoch'], $commit['committer_tz']); $owner = git_project_owner($projectroot, $project); $refs = read_info_ref($git); $tpl->assign("head", sha1_hex($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($git, $head, 17); foreach ($revlist as $i => $rev) { $revhash = sha1_hex($rev->getName()); $revdata = array(); $revco = git_read_commit($git, $rev->getName()); $authordate = date_str($revco['author_epoch']); $revdata["commit"] = $revhash; if (isset($refs[$rev->getName()])) { $revdata["commitref"] = $refs[$rev->getName()]; } $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($git, "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($com, 0, GITPHP_TRIM_LENGTH) . "..."; } $taglist[$i]['comment'] = $com; } } $tpl->assign("taglist", $taglist); } $headlist = git_read_refs($git, "refs/heads"); if (isset($headlist) && count($headlist) > 0) { $tpl->assign("headlist", $headlist); } } $tpl->display('project.tpl', $cachekey); }
$history = $tmp; ?> <h1>Recent activity</h1> <ol> <?php foreach ($history as $date => $commits) { ?> <li><h2><?php echo $date; ?> </h2> <ol> <?php foreach ($commits as $commit) { ?> <li> <?php echo html::anchor(url::site('/changelog/' . sha1_hex($commit->getName())), html::chars($commit->summary)); ?> </li> <?php } ?> </ol> <?php } ?> </ol>
fseek($rfile, 0); ftruncate($rfile, 0); fwrite($rfile, $newhash . "\n"); fclose($rfile); } $line = "ok {$uref}\n"; echo sprintf("%04x%s", strlen($line) + 4, $line); unset($uref); } //update info/refs $f = fopen($repo_dir . "info/refs", "w"); $refcache = new GitRefCache($repo_dir); $refs = $refcache->refs; ksort($refs); foreach ($refs as $ref => $hash) { fwrite($f, sha1_hex($hash) . "\t{$ref}\n"); } fclose($f); // update objects/info/packs $f = fopen($repo_dir . "objects/info/packs", "w"); foreach (glob($repo_dir . "objects/pack/pack-*.pack") as $pack) { fwrite($f, sprintf("P %s\n", basename($pack))); } fwrite($f, "\n"); fclose($f); echo "0000"; } catch (Exception $e) { $line = $e->__toString(); echo sprintf("%04x%s", strlen($line) + 4, $line); echo "0000"; return;