Added smooth handling of bad files and commits.

Now simply redirect to the root of the first available branch.
newdiff
Loic d'Anterroches 2008-07-27 21:38:49 +02:00
parent 8a0a35726c
commit 3dbae6272a
2 changed files with 23 additions and 6 deletions

View File

@ -66,9 +66,6 @@ class IDF_Git
*/ */
public function filesAtCommit($commit='HEAD', $folder='') public function filesAtCommit($commit='HEAD', $folder='')
{ {
if ('commit' != $this->testHash($commit)) {
throw new Exception(sprintf(__('Not a valid commit: %s.'), $commit));
}
// now we grab the info about this commit including its tree. // now we grab the info about this commit including its tree.
$co = $this->getCommit($commit); $co = $this->getCommit($commit);
if ($folder) { if ($folder) {

View File

@ -55,6 +55,13 @@ class IDF_Views_Source
$git = new IDF_Git(Pluf::f('git_repository')); $git = new IDF_Git(Pluf::f('git_repository'));
$commit = $match[2]; $commit = $match[2];
$branches = $git->getBranches(); $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); $res = $git->filesAtCommit($commit);
$cobject = $git->getCommit($commit); $cobject = $git->getCommit($commit);
$tree_in = in_array($commit, $branches); $tree_in = in_array($commit, $branches);
@ -75,18 +82,31 @@ class IDF_Views_Source
{ {
$title = sprintf('%s Git Source Tree', (string) $request->project); $title = sprintf('%s Git Source Tree', (string) $request->project);
$git = new IDF_Git(Pluf::f('git_repository')); $git = new IDF_Git(Pluf::f('git_repository'));
$branches = $git->getBranches();
$commit = $match[2]; $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 = $match[3];
$request_file_info = $git->getFileInfo($request_file, $commit); $request_file_info = $git->getFileInfo($request_file, $commit);
if (!$request_file_info) throw new Pluf_HTTP_Error404(); 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') { if ($request_file_info->type != 'tree') {
return new Pluf_HTTP_Response($git->getBlob($request_file_info->hash), return new Pluf_HTTP_Response($git->getBlob($request_file_info->hash),
'application/octet-stream'); 'application/octet-stream');
} }
$bc = self::makeBreadCrumb($request->project, $commit, $request_file_info->file); $bc = self::makeBreadCrumb($request->project, $commit, $request_file_info->file);
$page_title = $bc.' - '.$title; $page_title = $bc.' - '.$title;
$branches = $git->getBranches(); $cobject = $git->getCommit($commit);
$cobject = $git->getCommit();
$tree_in = in_array($commit, $branches); $tree_in = in_array($commit, $branches);
$res = $git->filesAtCommit($commit, $request_file); $res = $git->filesAtCommit($commit, $request_file);
// try to find the previous level if it exists. // try to find the previous level if it exists.