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 sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {}
15 my $commit = $c->stash->{Commit};
16 my %filename = $c->stash->{filename} ? (filename => $c->stash->{filename}) : ();
17 my($tree, $patch) = $c->stash->{Repository}->diff(
19 parent => $c->stash->{parent},
26 # XXX Hack hack hack, see View::SyntaxHighlight
27 blobs => [map $_->{diff}, @$patch],
33 after diff_fancy => sub {
36 $c->forward('View::SyntaxHighlight');
39 after diff_plain => sub {
42 $c->response->content_type('text/plain; charset=utf-8');
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)],
56 path => $c->stash->{filename}, # FIXME?
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' : ''),
90 $c->forward('View::SyntaxHighlight')
91 unless $c->stash->{no_wrapper};
94 after history => sub {
96 my $repository = $c->stash->{Repository};
97 my $filename = $c->stash->{filename};
100 sha1 => $c->stash->{Commit}->sha1,
101 count => 25, #Gitalist->config->{paging}{log} || 25,
102 ($filename ? (file => $filename) : ())
105 my $file = $repository->get_object(
106 $repository->hash_by_path(
107 $repository->head_hash,
112 my $page = $c->req->param('pg') || 0;
113 $logargs{skip} = $c->req->param('pg') * $logargs{count}
114 if $c->req->param('pg');
117 log_lines => [$repository->list_revs(%logargs)],
118 refs => $repository->references,
119 filename => $filename,
120 filetype => $file->type,
124 __PACKAGE__->meta->make_immutable;