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 %diff_args = ( patch => 1 );
18 foreach my $arg qw/filename parent/ {
19 if (defined $c->stash->{$arg}) {
20 $diff_args{$arg} = $c->stash->{$arg};
23 my ($tree, $patch) = $c->stash->{Commit}->diff(
29 # XXX Hack hack hack, see View::SyntaxHighlight
30 blobs => [map $_->{diff}, @$patch],
35 after diff_fancy => sub {
38 $c->forward('Model::ContentMangler');
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 blob => join("\n", map $_->{line}, @$blame),
71 $c->forward('Model::ContentMangler');
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}),
86 $c->forward('Model::ContentMangler');
89 after history => sub {
91 my $repository = $c->stash->{Repository};
92 my $filename = $c->stash->{filename};
95 sha1 => $c->stash->{Commit}->sha1,
96 count => 25, #Gitalist->config->{paging}{log} || 25,
97 ($filename ? (file => $filename) : ())
100 my $file = $repository->get_object(
101 $repository->hash_by_path(
102 $repository->head_hash,
107 my $page = $c->req->param('pg') || 0;
108 $logargs{skip} = $c->req->param('pg') * $logargs{count}
109 if $c->req->param('pg');
112 log_lines => [$repository->list_revs(%logargs)],
113 refs => $repository->references,
114 filename => $filename,
115 filetype => $file->type,
119 __PACKAGE__->meta->make_immutable;