1 package Gitalist::URIStructure::Ref;
2 use MooseX::MethodAttributes::Role;
4 use namespace::autoclean;
6 use Gitalist::Git::Types qw/SHA1/;
11 Gitalist::URIStructure::WithLog
16 confess("No repository in the stash")
17 unless $c->stash->{Repository};
20 sub find : Chained('base') PathPart('') CaptureArgs(1) {
21 my ($self, $c, $sha1part) = @_;
22 # FIXME - Should not be here!
23 $c->stash->{Commit} = $c->stash->{Repository}->get_object($sha1part)
24 or $c->detach('/error404', "Couldn't find a object for '$sha1part' in XXXX!");
25 $c->stash->{data} = $c->stash->{Commit};
28 sub diff : Chained('find') CaptureArgs(0) {}
31 my($self, $c, @rest) = @_;
33 # FIXME - This ain't pretty
34 $c->stash(parent => shift @rest)
36 # Check that the single arg is unlikely to be a path.
37 or @rest && to_SHA1($rest[0]) && $c->stash->{Repository}->get_object($rest[0]);
38 $c->stash(filename => $rest[-1])
42 sub diff_fancy : Chained('diff') PathPart('') Args() {
43 my($self, $c, @rest) = @_;
45 $self->_set_diff_args($c, @rest);
48 sub diff_plain : Chained('diff') PathPart('plain') Args() {
49 my($self, $c, $comparison, @rest) = @_;
51 $self->_set_diff_args($c, @rest);
53 $c->stash(no_wrapper => 1);
54 $c->response->content_type('text/plain; charset=utf-8');
57 sub commit : Chained('find') PathPart('commit') Args(0) {}
59 sub file_commit_info : Chained('find') Does('FilenameArgs') Args() {}
61 sub tree : Chained('find') Does('FilenameArgs') Args() {}
63 sub find_blob : Action {
65 my($repo, $object) = @{$c->{stash}}{qw(Repository Commit)};
69 if ($object->isa('Gitalist::Git::Object::Commit')) {
70 $blob = $object->sha_by_path($c->stash->{filename});
71 } elsif ($object->isa('Gitalist::Git::Object::Blob')) {
74 die "Unknown object type for '${\$object->sha1}'";
76 die "No file or sha1 provided."
79 $c->stash(blob => $blob->content);
82 sub blob : Chained('find') Does('FilenameArgs') Args() {
84 $c->forward('find_blob');
87 sub blame : Chained('find') Does('FilenameArgs') Args() {}
89 sub history : Chained('find') Does('FilenameArgs') Args() {}