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;
33 The main shim around C<gitweb.pm>.
38 my ( $self, $c ) = @_;
40 # XXX A slippery slope to be sure.
41 if($c->req->param('a')) {
42 my $capture = IO::Capture::Stdout->new();
45 my $action = gitweb::main($c);
54 my $output = join '', $capture->read;
55 $c->stash->{gitweb_output} = $output;
56 $c->stash->{template} = 'gitweb.tt2';
62 Provides the project listing.
66 sub index :Path :Args(0) {
67 my ( $self, $c ) = @_;
69 # Leave actions up to gitweb at this point.
70 return $self->run_gitweb($c)
71 if $c->req->param('a');
73 my $list = $c->model('Git')->list_projects;
75 die "No projects found";
79 searchtext => $c->req->param('searchtext') || '',
87 The blob action i.e the contents of a file.
92 my ( $self, $c ) = @_;
94 my $h = $c->req->param('h')
95 || $c->model('Git')->hash_by_path($c->req->param('f'))
96 || die "No file or sha1 provided.";
97 my $hb = $c->req->param('hb')
98 || $c->model('Git')->head_hash
99 || die "Couldn't discern the corresponding head.";
102 blob => $c->model('Git')->get_object($h)->content,
103 head => $c->model('Git')->get_object($hb),
104 filename => $c->req->param('f') || '',
108 $c->forward('View::SyntaxHighlight');
113 Expose the local reflog. This may go away.
118 my ( $self, $c ) = @_;
120 my @log = $c->model('Git')->reflog(
132 Exposes a given commit.
137 my ( $self, $c ) = @_;
140 commit => $c->model('Git')->get_object($c->req->param('h')),
147 Expose an abbreviated log of a given sha1.
151 sub shortlog : Local {
152 my ( $self, $c ) = @_;
155 commit => $c->model('Git')->get_object($c->req->param('h')),
156 action => 'shortlog',
162 Populate the header and footer. Perhaps not the best location.
169 # XXX Temp hack until a decent solution is invented.
170 $c->model('Git')->project($c->req->param('p'))
171 if $c->req->param('p');
173 # Yes, this is hideous.
178 # XXX This could probably be dropped altogether.
179 use Gitalist::Util qw(to_utf8);
180 # Formally git_header_html
184 my $title = $c->config->{sitename};
186 my $project = $c->req->param('project') || $c->req->param('p');
187 my $action = $c->req->param('action') || $c->req->param('a');
188 my $file_name = $c->req->param('filename') || $c->req->param('f');
189 if(defined $project) {
190 $title .= " - " . to_utf8($project);
191 if (defined $action) {
192 $title .= "/$action";
193 if (defined $file_name) {
194 $title .= " - " . $file_name;
195 if ($action eq "tree" && $file_name !~ m|/$|) {
202 $c->stash->{version} = $c->config->{version};
203 $c->stash->{git_version} = $c->model('Git')->run_cmd('--version');
204 $c->stash->{title} = $title;
206 #$c->stash->{baseurl} = $ENV{PATH_INFO} && uri_escape($base_url);
207 $c->stash->{stylesheet} = $c->config->{stylesheet} || 'gitweb.css';
209 $c->stash->{project} = $project;
212 my %href_params = $self->feed_info($c);
213 $href_params{'-title'} ||= 'log';
215 foreach my $format qw(RSS Atom) {
216 my $type = lc($format);
219 title => "$project - $href_params{'-title'} - $format feed",
221 # XXX A bit hacky and could do with using gitweb::href() features
222 href => "?a=$type;p=$project",
223 type => "application/$type+xml"
227 # XXX This duplication also feels a bit awkward
228 title => "$project - $href_params{'-title'} - $format feed (no merges)",
229 href => "?a=$type;p=$project;opt=--no-merges",
230 type => "application/$type+xml"
236 title => $c->config->{sitename}." projects list",
237 href => '?a=project_index',
238 type => "text/plain; charset=utf-8"
241 title => $c->config->{sitename}." projects feeds",
243 type => "text/plain; charset=utf-8"
247 $c->stash->{favicon} = $c->config->{favicon};
252 logo_url => $c->config->{logo_url},
253 logo_label => $c->config->{logo_label},
254 logo_img => $c->config->{logo},
255 home_link => $c->config->{home_link},
256 home_link_str => $c->config->{home_link_str},
259 if(defined $project) {
261 search_text => ( $c->req->param('s') || $c->req->param('searchtext') ),
262 search_hash => ( $c->req->param('hb') || $c->req->param('hashbase')
263 || $c->req->param('h') || $c->req->param('hash')
269 # Formally git_footer_html
273 my $feed_class = 'rss_logo';
276 my $project = $c->req->param('project') || $c->req->param('p');
277 if(defined $project) {
278 (my $pstr = $project) =~ s[/?\.git$][];
279 my $descr = $c->model('Git')->project_info($project)->{description};
280 $c->stash->{project_description} = defined $descr
284 my %href_params = $self->feed_info($c);
286 $feed_class .= ' generic';
288 $href_params{'-title'} ||= 'log';
292 class => $feed_class,
293 title => "$href_params{'-title'} $_ feed",
294 href => "/?p=$project;a=\L$_",
301 class => $feed_class,
303 href => "/?a=$_->[0]",
305 }, [opml=>'OPML'],[project_index=>'TXT'],
310 # XXX This feels wrong here, should probably be refactored.
311 # returns hash to be passed to href to generate gitweb URL
312 # in -title key it returns description of link
316 my $format = shift || 'Atom';
317 my %res = (action => lc($format));
319 # feed links are possible only for project views
320 return unless $c->req->param('project');
322 # some views should link to OPML, or to generic project feed,
323 # or don't have specific feed yet (so they should use generic)
324 return if $c->req->param('action') =~ /^(?:tags|heads|forks|tag|search)$/x;
327 my $hash = $c->req->param('h') || $c->req->param('hash');
328 my $hash_base = $c->req->param('hb') || $c->req->param('hashbase');
330 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
331 # from tag links; this also makes possible to detect branch links
332 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
333 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
337 # find log type for feed description (title)
339 my $file_name = $c->req->param('f') || $c->req->param('filename');
340 if (defined $file_name) {
341 $type = "history of $file_name";
342 $type .= "/" if $c->req->param('action') eq 'tree';
343 $type .= " on '$branch'" if (defined $branch);
345 $type = "log of $branch" if (defined $branch);
348 $res{-title} = $type;
349 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
350 $res{'file_name'} = $file_name;
356 Attempt to render a view, if needed.
360 sub end : ActionClass('RenderView') {}
368 This library is free software. You can redistribute it and/or modify
369 it under the same terms as Perl itself.
373 __PACKAGE__->meta->make_immutable;