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');
75 The blob action i.e the contents of a file.
80 my ( $self, $c ) = @_;
82 is_image => File::Type::WebImages::mime_type($c->stash->{blob}),
83 is_binary => Gitalist::Utils::is_binary($c->stash->{blob}),
85 $c->forward('Model::ContentMangler');
88 after history => sub {
90 my $repository = $c->stash->{Repository};
91 my $filename = $c->stash->{filename};
94 sha1 => $c->stash->{Commit}->sha1,
95 count => 25, #Gitalist->config->{paging}{log} || 25,
96 ($filename ? (file => $filename) : ())
99 my $file = $repository->get_object(
100 $repository->hash_by_path(
101 $repository->head_hash,
106 my $page = $c->req->param('pg') || 0;
107 $logargs{skip} = $c->req->param('pg') * $logargs{count}
108 if $c->req->param('pg');
111 log_lines => [$repository->list_revs(%logargs)],
112 refs => $repository->references,
113 filename => $filename,
114 filetype => $file->type,
118 __PACKAGE__->meta->make_immutable;