project);
$git = new IDF_Git($request->project->getGitRepository());
$branches = $git->getBranches();
$commit = $match[2];
$res = $git->getChangeLog($commit, 25);
return Pluf_Shortcuts_RenderToResponse('source/changelog.html',
array(
'page_title' => $title,
'title' => $title,
'changes' => $res,
'commit' => $commit,
'branches' => $branches,
),
$request);
}
public function treeBase($request, $match)
{
$title = sprintf('%s Git Source Tree', (string) $request->project);
$git = new IDF_Git($request->project->getGitRepository());
$commit = $match[2];
$branches = $git->getBranches();
if ('commit' != $git->testHash($commit)) {
// Redirect to the first branch
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::treeBase',
array($request->project->shortname,
$branches[0]));
return new Pluf_HTTP_Response_Redirect($url);
}
$res = $git->filesAtCommit($commit);
$cobject = $git->getCommit($commit);
$tree_in = in_array($commit, $branches);
return Pluf_Shortcuts_RenderToResponse('source/tree.html',
array(
'page_title' => $title,
'title' => $title,
'files' => $res,
'cobject' => $cobject,
'commit' => $commit,
'tree_in' => $tree_in,
'branches' => $branches,
),
$request);
}
public function tree($request, $match)
{
$title = sprintf('%s Git Source Tree', (string) $request->project);
$git = new IDF_Git($request->project->getGitRepository());
$branches = $git->getBranches();
$commit = $match[2];
if ('commit' != $git->testHash($commit)) {
// Redirect to the first branch
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::treeBase',
array($request->project->shortname,
$branches[0]));
return new Pluf_HTTP_Response_Redirect($url);
}
$request_file = $match[3];
$request_file_info = $git->getFileInfo($request_file, $commit);
if (!$request_file_info) {
// Redirect to the first branch
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::treeBase',
array($request->project->shortname,
$branches[0]));
return new Pluf_HTTP_Response_Redirect($url);
}
if ($request_file_info->type != 'tree') {
return new Pluf_HTTP_Response($git->getBlob($request_file_info->hash),
'application/octet-stream');
}
$bc = self::makeBreadCrumb($request->project, $commit, $request_file_info->file);
$page_title = $bc.' - '.$title;
$cobject = $git->getCommit($commit);
$tree_in = in_array($commit, $branches);
$res = $git->filesAtCommit($commit, $request_file);
// try to find the previous level if it exists.
$prev = split('/', $request_file);
$l = array_pop($prev);
$previous = substr($request_file, 0, -strlen($l.' '));
return Pluf_Shortcuts_RenderToResponse('source/tree.html',
array(
'page_title' => $page_title,
'title' => $title,
'breadcrumb' => $bc,
'files' => $res,
'commit' => $commit,
'cobject' => $cobject,
'base' => $request_file_info->file,
'prev' => $previous,
'tree_in' => $tree_in,
'branches' => $branches,
),
$request);
}
public static function makeBreadCrumb($project, $commit, $file, $sep='/')
{
$elts = split('/', $file);
$out = array();
$stack = '';
$i = 0;
foreach ($elts as $elt) {
$stack .= ($i==0) ? $elt : '/'.$elt;
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::tree',
array($project->shortname,
$commit, $stack));
$out[] = ''.Pluf_esc($elt).'';
$i++;
}
return ''.implode(''.$sep.'', $out).'';
}
public function commit($request, $match)
{
$git = new IDF_Git($request->project->getGitRepository());
$commit = $match[2];
$branches = $git->getBranches();
if ('commit' != $git->testHash($commit)) {
// Redirect to the first branch
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::treeBase',
array($request->project->shortname,
$branches[0]));
return new Pluf_HTTP_Response_Redirect($url);
}
$title = sprintf('%s Commit Details', (string) $request->project);
$page_title = sprintf('%s Commit Details - %s', (string) $request->project, $commit);
$cobject = $git->getCommit($commit);
$diff = new IDF_Diff($cobject->changes);
$diff->parse();
return Pluf_Shortcuts_RenderToResponse('source/commit.html',
array(
'page_title' => $page_title,
'title' => $title,
'diff' => $diff,
'cobject' => $cobject,
'commit' => $commit,
'branches' => $branches,
),
$request);
}
/**
* Get a zip archive of the current commit.
*
*/
public function download($request, $match)
{
$commit = trim($match[2]);
$git = new IDF_Git($request->project->getGitRepository());
$branches = $git->getBranches();
if ('commit' != $git->testHash($commit)) {
// Redirect to the first branch
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::treeBase',
array($request->project->shortname,
$branches[0]));
return new Pluf_HTTP_Response_Redirect($url);
}
$base = $request->project->shortname.'-'.$commit;
$cmd = $git->getArchiveCommand($commit, $base.'/');
$rep = new Pluf_HTTP_Response_CommandPassThru($cmd, 'application/x-zip');
$rep->headers['Content-Transfer-Encoding'] = 'binary';
$rep->headers['Content-Disposition'] = 'attachment; filename="'.$base.'.zip"';
return $rep;
}
}
function IDF_Views_Source_PrettySize($size)
{
return Pluf_Template::markSafe(Pluf_Utils::prettySize($size));
}