1 package Gitalist::Controller::Fragment::Ref;
3 use namespace::autoclean;
5 BEGIN { extends 'Gitalist::Controller' }
7 Gitalist::URIStructure::Ref
8 Gitalist::URIStructure::Fragment::WithLog
11 use File::Type::WebImages ();
13 sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {}
17 my $commit = $c->stash->{Commit};
18 my %filename = $c->stash->{filename} ? (filename => $c->stash->{filename}) : ();
19 my($tree, $patch) = $c->stash->{Repository}->diff(
21 parent => $c->stash->{parent},
28 # XXX Hack hack hack, see View::SyntaxHighlight
29 blobs => [map $_->{diff}, @$patch],
35 after diff_fancy => sub {
38 $c->forward('View::SyntaxHighlight');
41 after diff_plain => sub {
47 my ( $self, $c ) = @_;
48 my $repository = $c->stash->{Repository};
49 my $commit = $c->stash->{Commit};
50 my $tree = $c->stash->{filename}
51 ? $repository->get_object($repository->hash_by_path($commit->sha1, $c->stash->{filename}))
52 : $repository->get_object($commit->tree_sha1)
56 tree_list => [$repository->list_tree($tree->sha1)],
63 my $repository = $c->stash->{Repository};
65 my $blame = $c->stash->{Commit}->blame($c->stash->{filename}, $c->stash->{Commit}->sha1);
68 # XXX Hack hack hack, see View::SyntaxHighlight
69 language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''),
70 blob => join("\n", map $_->{line}, @$blame),
73 $c->forward('View::SyntaxHighlight')
74 unless $c->stash->{no_wrapper};
79 The blob action i.e the contents of a file.
84 my ( $self, $c ) = @_;
86 # XXX Hack hack hack, see View::SyntaxHighlight
87 language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''),
88 is_image => File::Type::WebImages::mime_type($c->stash->{blob}),
89 is_binary => -B $c->stash->{blob},
92 $c->forward('View::SyntaxHighlight')
93 unless $c->stash->{no_wrapper};
96 after history => sub {
98 my $repository = $c->stash->{Repository};
99 my $filename = $c->stash->{filename};
102 sha1 => $c->stash->{Commit}->sha1,
103 count => 25, #Gitalist->config->{paging}{log} || 25,
104 ($filename ? (file => $filename) : ())
107 my $file = $repository->get_object(
108 $repository->hash_by_path(
109 $repository->head_hash,
114 my $page = $c->req->param('pg') || 0;
115 $logargs{skip} = $c->req->param('pg') * $logargs{count}
116 if $c->req->param('pg');
119 log_lines => [$repository->list_revs(%logargs)],
120 refs => $repository->references,
121 filename => $filename,
122 filetype => $file->type,
126 __PACKAGE__->meta->make_immutable;