X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FGitalist%2FURIStructure%2FRef.pm;h=2536dc5fb1dab487025138f3040d25bbe852fc8b;hb=b5bae81d515d875209d3c8de2e4139fb481635e7;hp=659ccc05d98b4f359af740c59e18c682bb4c8c8c;hpb=7998de1265a0e9b2bddd66ab3ee57553e2fdef6a;p=catagits%2FGitalist.git diff --git a/lib/Gitalist/URIStructure/Ref.pm b/lib/Gitalist/URIStructure/Ref.pm index 659ccc0..2536dc5 100644 --- a/lib/Gitalist/URIStructure/Ref.pm +++ b/lib/Gitalist/URIStructure/Ref.pm @@ -3,6 +3,8 @@ use MooseX::MethodAttributes::Role; use Moose::Autobox; use namespace::autoclean; +use Gitalist::Git::Types qw/SHA1/; + requires 'base'; with qw/ @@ -20,31 +22,56 @@ sub find : Chained('base') PathPart('') CaptureArgs(1) { # FIXME - Should not be here! $c->stash->{Commit} = $c->stash->{Repository}->get_object_or_head($sha1part) or $c->detach('/error404', "Couldn't find a object for '$sha1part' in XXXX!"); + $c->stash->{data} = $c->stash->{Commit}; } sub diff : Chained('find') CaptureArgs(0) {} -sub diff_fancy : Chained('diff') PathPart('') Args() { - my($self, $c, $comparison, @rest) = @_; +sub _set_diff_args { + my($self, $c, @rest) = @_; + # FIXME - This ain't pretty - $c->stash->{parent} = $comparison - if $comparison; - $c->stash->{filename} = $rest[0] + $c->stash(parent => shift @rest) + if @rest == 2 + # Check that the single arg is unlikely to be a path. + or @rest && to_SHA1($rest[0]) && $c->stash->{Repository}->get_object_or_head($rest[0]); + $c->stash(filename => $rest[-1]) if @rest; } -sub diff_plain : Chained('diff') PathPart('plain') Args(0) {} +sub diff_fancy : Chained('diff') PathPart('') Args() { + my($self, $c, @rest) = @_; + + $self->_set_diff_args($c, @rest); + } + +sub diff_plain : Chained('diff') PathPart('plain') Args() { + my($self, $c, $comparison, @rest) = @_; + + $self->_set_diff_args($c, @rest); + + $c->stash(no_wrapper => 1); + $c->response->content_type('text/plain; charset=utf-8'); +} sub commit : Chained('find') PathPart('commit') Args(0) {} +sub file_commit_info : Chained('find') Does('FilenameArgs') Args() {} + sub tree : Chained('find') Does('FilenameArgs') Args() {} sub find_blob : Action { my ($self, $c) = @_; + my($repo, $object) = @{$c->{stash}}{qw(Repository Commit)}; # FIXME - Eugh! - my $h = $c->stash->{Repository}->hash_by_path($c->stash->{Commit}->sha1, $c->stash->{filename}) - || die "No file or sha1 provided."; - $c->stash(blob => $c->stash->{Repository}->get_object($h)->content); + my $h = $object->isa('Gitalist::Git::Object::Commit') + ? $repo->hash_by_path($object->sha1, $c->stash->{filename}) + : $object->isa('Gitalist::Git::Object::Blob') + ? $object->sha1 + : die "Unknown object type for '${\$object->sha1}'"; + die "No file or sha1 provided." + unless $h; + $c->stash(blob => $repo->get_object($h)->content); } sub blob : Chained('find') Does('FilenameArgs') Args() {