Proof of concept for #56388: add last commit msg to tre views.
[catagits/Gitalist.git] / lib / Gitalist / URIStructure / Ref.pm
CommitLineData
2980657b 1package Gitalist::URIStructure::Ref;
0da7966e 2use MooseX::MethodAttributes::Role;
b6ec181b 3use Moose::Autobox;
0da7966e 4use namespace::autoclean;
5
cbcd8397 6use Gitalist::Git::Types qw/SHA1/;
7
0da7966e 8requires 'base';
9
b9423b8e 10with qw/
11 Gitalist::URIStructure::WithLog
12/;
13
0da7966e 14after 'base' => sub {
15 my ($self, $c) = @_;
16 confess("No repository in the stash")
17 unless $c->stash->{Repository};
18};
19
20sub find : Chained('base') PathPart('') CaptureArgs(1) {
21 my ($self, $c, $sha1part) = @_;
22 # FIXME - Should not be here!
dcb1b927 23 $c->stash->{Commit} = $c->stash->{Repository}->get_object_or_head($sha1part)
0da7966e 24 or $c->detach('/error404', "Couldn't find a object for '$sha1part' in XXXX!");
25}
26
d361d955 27sub diff : Chained('find') CaptureArgs(0) {}
28
cbcd8397 29sub _set_diff_args {
30 my($self, $c, @rest) = @_;
31
7998de12 32 # FIXME - This ain't pretty
cbcd8397 33 $c->stash(parent => shift @rest)
c4ed9eb3 34 if @rest == 2
35 # Check that the single arg is unlikely to be a path.
36 or @rest && to_SHA1($rest[0]) && $c->stash->{Repository}->get_object_or_head($rest[0]);
cbcd8397 37 $c->stash(filename => $rest[-1])
7998de12 38 if @rest;
39}
d361d955 40
cbcd8397 41sub diff_fancy : Chained('diff') PathPart('') Args() {
42 my($self, $c, @rest) = @_;
43
44 $self->_set_diff_args($c, @rest);
45 }
46
65f0ead5 47sub diff_plain : Chained('diff') PathPart('plain') Args() {
48 my($self, $c, $comparison, @rest) = @_;
cbcd8397 49
50 $self->_set_diff_args($c, @rest);
51
65f0ead5 52 $c->stash(no_wrapper => 1);
53 $c->response->content_type('text/plain; charset=utf-8');
8254b171 54}
0da7966e 55
bec3aecb 56sub commit : Chained('find') PathPart('commit') Args(0) {}
0da7966e 57
5dc23a14 58sub file_commit_info : Chained('find') Does('FilenameArgs') Args() {}
59
b6ec181b 60sub tree : Chained('find') Does('FilenameArgs') Args() {}
0da7966e 61
ca06a177 62sub find_blob : Action {
b132dce6 63 my ($self, $c) = @_;
592fa490 64 my($repo, $object) = @{$c->{stash}}{qw(Repository Commit)};
b132dce6 65 # FIXME - Eugh!
592fa490 66 my $h = $object->isa('Gitalist::Git::Object::Commit')
24450117 67 ? $repo->hash_by_path($object->sha1, $c->stash->{filename})
68 : $object->isa('Gitalist::Git::Object::Blob')
592fa490 69 ? $object->sha1
70 : die "Unknown object type for '${\$object->sha1}'";
71 die "No file or sha1 provided."
72 unless $h;
73 $c->stash(blob => $repo->get_object($h)->content);
b132dce6 74}
1f9a47c2 75
ca06a177 76sub blob : Chained('find') Does('FilenameArgs') Args() {
77 my ($self, $c) = @_;
78 $c->forward('find_blob');
79}
1f9a47c2 80
b6ec181b 81sub blame : Chained('find') Does('FilenameArgs') Args() {}
1f9a47c2 82
b6ec181b 83sub history : Chained('find') Does('FilenameArgs') Args() {}
84
0da7966e 851;