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($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\""); 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); }
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_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); }
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); }
} elseif ($action === 'commitdiff') { $template = 'commitdiff'; $page['project'] = validate_project($_REQUEST['p']); $page['title'] = "{$page['project']} - Commitdiff - ViewGit"; $hash = validate_hash($_REQUEST['h']); $page['commit_id'] = $hash; $page['subtitle'] = "Commitdiff " . substr($page['commit_id'], 0, 6); $info = git_get_commit_info($page['project'], $hash); $page['tree_id'] = $info['tree']; $page['message'] = $info['message']; $page['message_firstline'] = $info['message_firstline']; $page['message_full'] = $info['message_full']; $page['author_name'] = $info['author_name']; $page['author_mail'] = $info['author_mail']; $page['author_datetime'] = $info['author_datetime']; $text = fix_encoding(git_diff($page['project'], "{$hash}^", $hash)); list($page['files'], $page['diffdata']) = format_diff($text); //$page['diffdata'] = format_diff($text); } elseif ($action === 'patch') { $project = validate_project($_REQUEST['p']); $hash = validate_hash($_REQUEST['h']); $filename = "{$project}-" . substr($hash, 0, 7) . ".patch"; //header("Content-Type: text/x-diff"); header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: binary"); // TODO git-style filename header("Content-Disposition: attachment; filename=\"{$filename}\";"); run_git_passthru($project, "format-patch --stdout {$hash}^..{$hash}"); die; } elseif ($action === 'rss-log') { $page['project'] = validate_project($_REQUEST['p']);