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],
34 after diff_fancy => sub {
37 $c->forward('Model::ContentMangler');
40 after diff_plain => sub {
46 my ( $self, $c ) = @_;
47 my $repository = $c->stash->{Repository};
48 my $commit = $c->stash->{Commit};
49 my $tree = $c->stash->{filename}
50 ? $repository->get_object($repository->hash_by_path($commit->sha1, $c->stash->{filename}))
51 : $repository->get_object($commit->tree_sha1)
55 tree_list => [$repository->list_tree($tree->sha1)],
62 my $repository = $c->stash->{Repository};
64 my $blame = $c->stash->{Commit}->blame($c->stash->{filename}, $c->stash->{Commit}->sha1);
67 blob => join("\n", map $_->{line}, @$blame),
70 $c->forward('Model::ContentMangler')
71 unless $c->stash->{no_wrapper};
76 The blob action i.e the contents of a file.
81 my ( $self, $c ) = @_;
83 is_image => File::Type::WebImages::mime_type($c->stash->{blob}),
84 is_binary => Gitalist::Utils::is_binary($c->stash->{blob}),
87 $c->forward('Model::ContentMangler')
88 unless $c->stash->{no_wrapper};
91 after history => sub {
93 my $repository = $c->stash->{Repository};
94 my $filename = $c->stash->{filename};
97 sha1 => $c->stash->{Commit}->sha1,
98 count => 25, #Gitalist->config->{paging}{log} || 25,
99 ($filename ? (file => $filename) : ())
102 my $file = $repository->get_object(
103 $repository->hash_by_path(
104 $repository->head_hash,
109 my $page = $c->req->param('pg') || 0;
110 $logargs{skip} = $c->req->param('pg') * $logargs{count}
111 if $c->req->param('pg');
114 log_lines => [$repository->list_revs(%logargs)],
115 refs => $repository->references,
116 filename => $filename,
117 filetype => $file->type,
121 __PACKAGE__->meta->make_immutable;