Provided support for blobdiff_plain legacy URIs.
[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
6requires 'base';
7
b9423b8e 8with qw/
9 Gitalist::URIStructure::WithLog
10/;
11
0da7966e 12after 'base' => sub {
13 my ($self, $c) = @_;
14 confess("No repository in the stash")
15 unless $c->stash->{Repository};
16};
17
18sub find : Chained('base') PathPart('') CaptureArgs(1) {
19 my ($self, $c, $sha1part) = @_;
20 # FIXME - Should not be here!
dcb1b927 21 $c->stash->{Commit} = $c->stash->{Repository}->get_object_or_head($sha1part)
0da7966e 22 or $c->detach('/error404', "Couldn't find a object for '$sha1part' in XXXX!");
23}
24
d361d955 25sub diff : Chained('find') CaptureArgs(0) {}
26
7998de12 27sub diff_fancy : Chained('diff') PathPart('') Args() {
28 my($self, $c, $comparison, @rest) = @_;
29 # FIXME - This ain't pretty
65f0ead5 30 $c->stash(parent => $comparison)
7998de12 31 if $comparison;
65f0ead5 32 $c->stash(filename => $rest[0])
7998de12 33 if @rest;
34}
d361d955 35
65f0ead5 36sub diff_plain : Chained('diff') PathPart('plain') Args() {
37 my($self, $c, $comparison, @rest) = @_;
38 # FIXME - This ain't pretty
39 $c->stash(parent => $comparison)
40 if $comparison;
41 $c->stash(filename => $rest[0])
42 if @rest;
43 $c->stash(no_wrapper => 1);
44 $c->response->content_type('text/plain; charset=utf-8');
8254b171 45}
0da7966e 46
bec3aecb 47sub commit : Chained('find') PathPart('commit') Args(0) {}
0da7966e 48
b6ec181b 49sub tree : Chained('find') Does('FilenameArgs') Args() {}
0da7966e 50
ca06a177 51sub find_blob : Action {
b132dce6 52 my ($self, $c) = @_;
592fa490 53 my($repo, $object) = @{$c->{stash}}{qw(Repository Commit)};
b132dce6 54 # FIXME - Eugh!
592fa490 55 my $h = $object->isa('Gitalist::Git::Object::Commit')
24450117 56 ? $repo->hash_by_path($object->sha1, $c->stash->{filename})
57 : $object->isa('Gitalist::Git::Object::Blob')
592fa490 58 ? $object->sha1
59 : die "Unknown object type for '${\$object->sha1}'";
60 die "No file or sha1 provided."
61 unless $h;
62 $c->stash(blob => $repo->get_object($h)->content);
b132dce6 63}
1f9a47c2 64
ca06a177 65sub blob : Chained('find') Does('FilenameArgs') Args() {
66 my ($self, $c) = @_;
67 $c->forward('find_blob');
68}
1f9a47c2 69
b6ec181b 70sub blame : Chained('find') Does('FilenameArgs') Args() {}
1f9a47c2 71
b6ec181b 72sub history : Chained('find') Does('FilenameArgs') Args() {}
73
0da7966e 741;