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 A summary of what's happening in the repo.
92 my ( $self, $c ) = @_;
94 my $commit = $c->model('Git')->get_object($c->model('Git')->head_hash);
97 info => $c->model('Git')->project_info($c->model('Git')->project),
98 log_lines => [$c->model('Git')->list_revs(rev => $commit->sha1, count => 17)],
99 heads => [$c->model('Git')->heads],
106 The current list of heads (aka branches) in the repo.
111 my ( $self, $c ) = @_;
114 commit => $c->model('Git')->get_object($c->model('Git')->head_hash),
115 heads => [$c->model('Git')->heads],
122 The blob action i.e the contents of a file.
127 my ( $self, $c ) = @_;
129 my $h = $c->req->param('h')
130 || $c->model('Git')->hash_by_path($c->req->param('f'))
131 || die "No file or sha1 provided.";
132 my $hb = $c->req->param('hb')
133 || $c->model('Git')->head_hash
134 || die "Couldn't discern the corresponding head.";
137 blob => $c->model('Git')->get_object($h)->content,
138 head => $c->model('Git')->get_object($hb),
139 filename => $c->req->param('f') || '',
143 $c->forward('View::SyntaxHighlight');
148 Expose the local reflog. This may go away.
153 my ( $self, $c ) = @_;
155 my @log = $c->model('Git')->reflog(
167 Exposes a given commit.
172 my ( $self, $c ) = @_;
174 my $commit = $c->model('Git')->get_object($c->req->param('h'));
177 diff_tree => [$c->model('Git')->diff_tree($commit)],
178 branches_on => [$c->model('Git')->refs_for($commit->sha1)],
185 Exposes a given diff of a commit.
189 sub commitdiff : Local {
190 my ( $self, $c ) = @_;
192 my $commit = $c->model('Git')->get_object($c->req->param('h'));
195 diff_tree => [$c->model('Git')->diff_tree($commit)],
196 diff => [$c->model('Git')->diff($commit->parent_sha1, $commit->sha1)],
197 action => 'commitdiff',
203 Expose an abbreviated log of a given sha1.
207 sub shortlog : Local {
208 my ( $self, $c ) = @_;
210 my $commit = $c->model('Git')->get_object($c->req->param('h'));
214 log_lines => [$c->model('Git')->list_revs(rev => $commit->sha1)],
215 action => 'shortlog',
221 Calls shortlog internally. Perhaps that should be reversed ...
225 $_[0]->shortlog($_[1]);
226 $_[1]->stash->{action} = 'log';
231 The tree of a given commit.
236 my ( $self, $c ) = @_;
238 my $commit = $c->model('Git')->get_object($c->req->param('h'));
240 # XXX Useful defaults needed ...
242 tree => $c->model('Git')->get_object($c->req->param('hb')),
243 list_tree => [$c->model('Git')->list_tree($commit->sha1)],
250 Populate the header and footer. Perhaps not the best location.
257 # XXX Temp hack until a decent solution is invented.
258 $c->model('Git')->project($c->req->param('p'))
259 if $c->req->param('p');
261 # Yes, this is hideous.
266 # XXX This could probably be dropped altogether.
267 use Gitalist::Util qw(to_utf8);
268 # Formally git_header_html
272 my $title = $c->config->{sitename};
274 my $project = $c->req->param('project') || $c->req->param('p');
275 my $action = $c->req->param('action') || $c->req->param('a');
276 my $file_name = $c->req->param('filename') || $c->req->param('f');
277 if(defined $project) {
278 $title .= " - " . to_utf8($project);
279 if (defined $action) {
280 $title .= "/$action";
281 if (defined $file_name) {
282 $title .= " - " . $file_name;
283 if ($action eq "tree" && $file_name !~ m|/$|) {
290 $c->stash->{version} = $c->config->{version};
291 $c->stash->{git_version} = $c->model('Git')->run_cmd('--version');
292 $c->stash->{title} = $title;
294 #$c->stash->{baseurl} = $ENV{PATH_INFO} && uri_escape($base_url);
295 $c->stash->{stylesheet} = $c->config->{stylesheet} || 'gitweb.css';
297 $c->stash->{project} = $project;
300 my %href_params = $self->feed_info($c);
301 $href_params{'-title'} ||= 'log';
303 foreach my $format qw(RSS Atom) {
304 my $type = lc($format);
307 title => "$project - $href_params{'-title'} - $format feed",
309 # XXX A bit hacky and could do with using gitweb::href() features
310 href => "?a=$type;p=$project",
311 type => "application/$type+xml"
315 # XXX This duplication also feels a bit awkward
316 title => "$project - $href_params{'-title'} - $format feed (no merges)",
317 href => "?a=$type;p=$project;opt=--no-merges",
318 type => "application/$type+xml"
324 title => $c->config->{sitename}." projects list",
325 href => '?a=project_index',
326 type => "text/plain; charset=utf-8"
329 title => $c->config->{sitename}." projects feeds",
331 type => "text/plain; charset=utf-8"
335 $c->stash->{favicon} = $c->config->{favicon};
340 logo_url => $c->config->{logo_url},
341 logo_label => $c->config->{logo_label},
342 logo_img => $c->config->{logo},
343 home_link => $c->config->{home_link},
344 home_link_str => $c->config->{home_link_str},
347 if(defined $project) {
349 search_text => ( $c->req->param('s') || $c->req->param('searchtext') ),
350 search_hash => ( $c->req->param('hb') || $c->req->param('hashbase')
351 || $c->req->param('h') || $c->req->param('hash')
357 # Formally git_footer_html
361 my $feed_class = 'rss_logo';
364 my $project = $c->req->param('project') || $c->req->param('p');
365 if(defined $project) {
366 (my $pstr = $project) =~ s[/?\.git$][];
367 my $descr = $c->model('Git')->project_info($project)->{description};
368 $c->stash->{project_description} = defined $descr
372 my %href_params = $self->feed_info($c);
374 $feed_class .= ' generic';
376 $href_params{'-title'} ||= 'log';
380 class => $feed_class,
381 title => "$href_params{'-title'} $_ feed",
382 href => "/?p=$project;a=\L$_",
389 class => $feed_class,
391 href => "/?a=$_->[0]",
393 }, [opml=>'OPML'],[project_index=>'TXT'],
398 # XXX This feels wrong here, should probably be refactored.
399 # returns hash to be passed to href to generate gitweb URL
400 # in -title key it returns description of link
404 my $format = shift || 'Atom';
405 my %res = (action => lc($format));
407 # feed links are possible only for project views
408 return unless $c->req->param('project');
410 # some views should link to OPML, or to generic project feed,
411 # or don't have specific feed yet (so they should use generic)
412 return if $c->req->param('action') =~ /^(?:tags|heads|forks|tag|search)$/x;
415 my $hash = $c->req->param('h') || $c->req->param('hash');
416 my $hash_base = $c->req->param('hb') || $c->req->param('hashbase');
418 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
419 # from tag links; this also makes possible to detect branch links
420 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
421 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
425 # find log type for feed description (title)
427 my $file_name = $c->req->param('f') || $c->req->param('filename');
428 if (defined $file_name) {
429 $type = "history of $file_name";
430 $type .= "/" if $c->req->param('action') eq 'tree';
431 $type .= " on '$branch'" if (defined $branch);
433 $type = "log of $branch" if (defined $branch);
436 $res{-title} = $type;
437 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
438 $res{'file_name'} = $file_name;
444 Attempt to render a view, if needed.
448 sub end : ActionClass('RenderView') {}
456 This library is free software. You can redistribute it and/or modify
457 it under the same terms as Perl itself.
461 __PACKAGE__->meta->make_immutable;