From: Zachary Stevens Date: Sun, 8 Nov 2009 21:11:13 +0000 (+0000) Subject: Migrated blob to new model, + fixes for some legacy URI fails. X-Git-Tag: 0.000000_01~58^2~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8bb7649bb9fb1347e1028d03b6eb6a21bcd115a7;p=catagits%2FGitalist.git Migrated blob to new model, + fixes for some legacy URI fails. --- diff --git a/lib/Gitalist/Controller/Root.pm b/lib/Gitalist/Controller/Root.pm index 7e24e0b..32e7d7c 100644 --- a/lib/Gitalist/Controller/Root.pm +++ b/lib/Gitalist/Controller/Root.pm @@ -160,19 +160,20 @@ The blob action i.e the contents of a file. sub blob : Local { my ( $self, $c ) = @_; - + $c->stash(current_model => 'GitRepos'); + my $project = $c->stash->{Project}; my $h = $c->req->param('h') - || $c->model()->hash_by_path($c->req->param('f')) + || $project->hash_by_path($c->req->param('hb'), $c->req->param('f')) || die "No file or sha1 provided."; my $hb = $c->req->param('hb') - || $c->model()->head_hash + || $project->head_hash || die "Couldn't discern the corresponding head."; my $filename = $c->req->param('f') || ''; $c->stash( - blob => $c->model()->get_object($h)->content, - head => $c->model()->get_object($hb), + blob => $project->get_object($h)->contents, + head => $project->get_object($hb), filename => $filename, # XXX Hack hack hack, see View::SyntaxHighlight language => ($filename =~ /\.p[lm]$/ ? 'Perl' : ''), diff --git a/lib/Gitalist/Git/Project.pm b/lib/Gitalist/Git/Project.pm index 1845c46..69eaf84 100644 --- a/lib/Gitalist/Git/Project.pm +++ b/lib/Gitalist/Git/Project.pm @@ -195,13 +195,16 @@ The keys for each item will be: return @ret; } - method get_object (Str $sha1) { + method get_object (NonEmptySimpleStr $sha1) { + unless ( $self->valid_rev($sha1) ) { + $sha1 = $self->head_hash($sha1); + } return Object->new( project => $self, sha1 => $sha1, ); } - + # Should be in ::Object method get_object_mode_string (Gitalist::Git::Object $object) { return unless $object && $object->{mode}; @@ -303,8 +306,8 @@ The keys for each item will be: ); my @out = $self->raw_diff( - ( $patch ? '--patch-with-raw' : () ), - $parent, $commit->sha1, @etc + \(( $patch ? '--patch-with-raw' : () ), + $parent, $commit->sha1, @etc ) ); # XXX Yes, there is much wrongness having parse_diff_tree be destructive. diff --git a/t/01app.t b/t/01app.t index 42cbf90..9ebc7a4 100644 --- a/t/01app.t +++ b/t/01app.t @@ -30,6 +30,7 @@ is request('/summary?p=DoesNotExist')->code, 404, test('/tree', 'h=145dc3ef5d307be84cb9b325d70bd08aeed0eceb;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818'); test('/search', 'h=36c6c6708b8360d7023e8a1649c45bcf9b3bd818&f=&type=commit&text=added'); test('/blobdiff', 'f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hp=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=refs/heads/master;hpb=3bc0634310b9c62222bb0e724c11ffdfb297b4ac'); + test('/blob', 'f=dir1/file2;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818'); } done_testing;