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 ();
12 use JSON::XS qw(encode_json);
14 sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {}
18 my %diff_args = ( patch => 1 );
19 foreach my $arg qw/filename parent/ {
20 if (defined $c->stash->{$arg}) {
21 $diff_args{$arg} = $c->stash->{$arg};
24 my ($tree, $patch) = $c->stash->{Commit}->diff(
30 # XXX Hack hack hack, see View::SyntaxHighlight
31 blobs => [map $_->{diff}, @$patch],
36 after diff_fancy => sub {
39 $c->forward('Model::ContentMangler');
42 after diff_plain => sub {
48 my ( $self, $c ) = @_;
49 my $repository = $c->stash->{Repository};
50 my $commit = $c->stash->{Commit};
51 my $tree = $c->stash->{filename}
52 ? $repository->get_object($repository->hash_by_path($commit->sha1, $c->stash->{filename}))
53 : $repository->get_object($commit->tree_sha1)
57 tree_list => [$repository->list_tree($tree->sha1)],
64 my $repository = $c->stash->{Repository};
66 my $blame = $c->stash->{Commit}->blame($c->stash->{filename}, $c->stash->{Commit}->sha1);
69 blob => join("\n", map $_->{line}, @$blame),
72 $c->forward('Model::ContentMangler');
77 The blob action i.e the contents of a file.
82 my ( $self, $c ) = @_;
84 is_image => File::Type::WebImages::mime_type($c->stash->{blob}),
85 is_binary => Gitalist::Utils::is_binary($c->stash->{blob}),
87 $c->forward('Model::ContentMangler');
90 after history => sub {
92 my $repository = $c->stash->{Repository};
93 my $filename = $c->stash->{filename};
96 sha1 => $c->stash->{Commit}->sha1,
97 count => 25, #Gitalist->config->{paging}{log} || 25,
98 ($filename ? (file => $filename) : ())
101 my $file = $repository->get_object(
102 $repository->hash_by_path(
103 $repository->head_hash,
108 my $page = $c->req->param('pg') || 0;
109 $logargs{skip} = $c->req->param('pg') * $logargs{count}
110 if $c->req->param('pg');
113 log_lines => [$repository->list_revs(%logargs)],
114 refs => $repository->references,
115 filename => $filename,
116 filetype => $file->type,
120 after file_commit_info => sub {
123 my $repository = $c->stash->{Repository};
125 my($commit) = $repository->list_revs(
126 sha1 => $c->stash->{Commit}->sha1,
128 file => $c->stash->{filename},
131 my $json_obj = !$commit
134 sha1 => $commit->sha1,
135 comment => $c->stash->{short_cmt}->($commit->comment),
136 age => $c->stash->{time_since}->($commit->authored_time),
139 $c->response->content_type('application/json');
140 # XXX Make use of the json branch
141 $c->response->body( encode_json $json_obj );
144 __PACKAGE__->meta->make_immutable;