Got blob highlighting working with the ContentMangler.
[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
b6ec181b 58sub tree : Chained('find') Does('FilenameArgs') Args() {}
0da7966e 59
ca06a177 60sub find_blob : Action {
b132dce6 61 my ($self, $c) = @_;
592fa490 62 my($repo, $object) = @{$c->{stash}}{qw(Repository Commit)};
b132dce6 63 # FIXME - Eugh!
592fa490 64 my $h = $object->isa('Gitalist::Git::Object::Commit')
24450117 65 ? $repo->hash_by_path($object->sha1, $c->stash->{filename})
66 : $object->isa('Gitalist::Git::Object::Blob')
592fa490 67 ? $object->sha1
68 : die "Unknown object type for '${\$object->sha1}'";
69 die "No file or sha1 provided."
70 unless $h;
71 $c->stash(blob => $repo->get_object($h)->content);
b132dce6 72}
1f9a47c2 73
ca06a177 74sub blob : Chained('find') Does('FilenameArgs') Args() {
75 my ($self, $c) = @_;
76 $c->forward('find_blob');
77}
1f9a47c2 78
b6ec181b 79sub blame : Chained('find') Does('FilenameArgs') Args() {}
1f9a47c2 80
b6ec181b 81sub history : Chained('find') Does('FilenameArgs') Args() {}
82
0da7966e 831;