1 package Gitalist::Controller::Root;
3 use namespace::autoclean;
5 BEGIN { extends 'Catalyst::Controller' }
8 # Sets the actions in this controller to be registered with no prefix
9 # so they function identically to actions created in MyApp.pm
11 __PACKAGE__->config->{namespace} = '';
15 Gitalist::Controller::Root - Root Controller for Gitalist
19 [enter your description here]
29 use IO::Capture::Stdout;
30 use File::Slurp qw(slurp);
33 my ( $self, $c ) = @_;
35 # XXX A slippery slope to be sure.
36 if($c->req->param('a')) {
37 my $capture = IO::Capture::Stdout->new();
40 my $action = gitweb::main($c);
49 my $output = join '', $capture->read;
50 $c->stash->{gitweb_output} = $output;
51 $c->stash->{template} = 'gitweb.tt2';
55 sub index :Path :Args(0) {
56 my ( $self, $c ) = @_;
58 # Leave actions up to gitweb at this point.
59 return $self->run_gitweb($c)
60 if $c->req->param('a');
62 my $list = $c->model('Git')->list_projects;
64 die "No projects found";
68 searchtext => $c->req->param('searchtext') || '',
75 my ( $self, $c ) = @_;
77 my $git = $c->model('Git');
79 my $proj = $req->param('p');
80 my $filename = $req->param('f') || $req->param('filename');
81 my $hash = $req->param('hb') || $git->get_head_hash($proj);
82 my $filehash = $req->param('h') || $git->get_hash_by_path($proj, $hash, $filename, 'blob');
84 my $blob = $git->run_cmd('cat-file' => blob => $filehash);
93 my ( $self, $c ) = @_;
95 my @log = $c->model('Git')->reflog(
96 # XXX The project parameter should probably be passed into the Model.
110 # Yes, this is hideous.
115 # XXX This could probably be dropped altogether.
116 use Gitalist::Util qw(to_utf8);
117 # Formally git_header_html
121 my $title = $c->config->{sitename};
123 my $project = $c->req->param('project') || $c->req->param('p');
124 my $action = $c->req->param('action') || $c->req->param('a');
125 my $file_name = $c->req->param('filename') || $c->req->param('f');
126 if(defined $project) {
127 $title .= " - " . to_utf8($project);
128 if (defined $action) {
129 $title .= "/$action";
130 if (defined $file_name) {
131 $title .= " - " . $file_name;
132 if ($action eq "tree" && $file_name !~ m|/$|) {
139 $c->stash->{version} = $c->config->{version};
140 $c->stash->{git_version} = $c->model('Git')->run_cmd('--version');
141 $c->stash->{title} = $title;
143 #$c->stash->{baseurl} = $ENV{PATH_INFO} && uri_escape($base_url);
144 $c->stash->{stylesheet} = $c->config->{stylesheet} || 'gitweb.css';
146 $c->stash->{project} = $project;
149 my %href_params = $self->feed_info($c);
150 $href_params{'-title'} ||= 'log';
152 foreach my $format qw(RSS Atom) {
153 my $type = lc($format);
156 title => "$project - $href_params{'-title'} - $format feed",
158 # XXX A bit hacky and could do with using gitweb::href() features
159 href => "?a=$type;p=$project",
160 type => "application/$type+xml"
164 # XXX This duplication also feels a bit awkward
165 title => "$project - $href_params{'-title'} - $format feed (no merges)",
166 href => "?a=$type;p=$project;opt=--no-merges",
167 type => "application/$type+xml"
173 title => $c->config->{sitename}." projects list",
174 href => '?a=project_index',
175 type => "text/plain; charset=utf-8"
178 title => $c->config->{sitename}." projects feeds",
180 type => "text/plain; charset=utf-8"
184 $c->stash->{favicon} = $c->config->{favicon};
189 logo_url => $c->config->{logo_url},
190 logo_label => $c->config->{logo_label},
191 logo_img => $c->config->{logo},
192 home_link => $c->config->{home_link},
193 home_link_str => $c->config->{home_link_str},
196 if(defined $project) {
198 search_text => ( $c->req->param('s') || $c->req->param('searchtext') ),
199 search_hash => ( $c->req->param('hb') || $c->req->param('hashbase')
200 || $c->req->param('h') || $c->req->param('hash')
206 # Formally git_footer_html
210 my $feed_class = 'rss_logo';
213 my $project = $c->req->param('project') || $c->req->param('p');
214 if(defined $project) {
215 (my $pstr = $project) =~ s[/?\.git$][];
216 my $descr = $c->model('Git')->project_info($project)->{description};
217 $c->stash->{project_description} = defined $descr
221 my %href_params = $self->feed_info($c);
223 $feed_class .= ' generic';
225 $href_params{'-title'} ||= 'log';
229 class => $feed_class,
230 title => "$href_params{'-title'} $_ feed",
231 href => "/?p=$project;a=\L$_",
238 class => $feed_class,
240 href => "/?a=$_->[0]",
242 }, [opml=>'OPML'],[project_index=>'TXT'],
247 # XXX This feels wrong here, should probably be refactored.
248 # returns hash to be passed to href to generate gitweb URL
249 # in -title key it returns description of link
253 my $format = shift || 'Atom';
254 my %res = (action => lc($format));
256 # feed links are possible only for project views
257 return unless $c->req->param('project');
259 # some views should link to OPML, or to generic project feed,
260 # or don't have specific feed yet (so they should use generic)
261 return if $c->req->param('action') =~ /^(?:tags|heads|forks|tag|search)$/x;
264 my $hash = $c->req->param('h') || $c->req->param('hash');
265 my $hash_base = $c->req->param('hb') || $c->req->param('hashbase');
267 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
268 # from tag links; this also makes possible to detect branch links
269 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
270 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
274 # find log type for feed description (title)
276 my $file_name = $c->req->param('f') || $c->req->param('filename');
277 if (defined $file_name) {
278 $type = "history of $file_name";
279 $type .= "/" if $c->req->param('action') eq 'tree';
280 $type .= " on '$branch'" if (defined $branch);
282 $type = "log of $branch" if (defined $branch);
285 $res{-title} = $type;
286 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
287 $res{'file_name'} = $file_name;
293 Attempt to render a view, if needed.
297 sub end : ActionClass('RenderView') {}
305 This library is free software. You can redistribute it and/or modify
306 it under the same terms as Perl itself.
310 __PACKAGE__->meta->make_immutable;