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 Expose an abbreviated log of a given sha1.
189 sub shortlog : Local {
190 my ( $self, $c ) = @_;
192 my $commit = $c->model('Git')->get_object($c->req->param('h'));
196 log_lines => [$c->model('Git')->list_revs(rev => $commit->sha1)],
197 action => 'shortlog',
203 Calls shortlog internally. Perhaps that should be reversed ...
207 $_[0]->shortlog($_[1]);
208 $_[1]->stash->{action} = 'log';
213 The tree of a given commit.
218 my ( $self, $c ) = @_;
220 my $commit = $c->model('Git')->get_object($c->req->param('h'));
222 # XXX Useful defaults needed ...
224 tree => $c->model('Git')->get_object($c->req->param('hb')),
225 list_tree => [$c->model('Git')->list_tree($commit->sha1)],
232 Populate the header and footer. Perhaps not the best location.
239 # XXX Temp hack until a decent solution is invented.
240 $c->model('Git')->project($c->req->param('p'))
241 if $c->req->param('p');
243 # Yes, this is hideous.
248 # XXX This could probably be dropped altogether.
249 use Gitalist::Util qw(to_utf8);
250 # Formally git_header_html
254 my $title = $c->config->{sitename};
256 my $project = $c->req->param('project') || $c->req->param('p');
257 my $action = $c->req->param('action') || $c->req->param('a');
258 my $file_name = $c->req->param('filename') || $c->req->param('f');
259 if(defined $project) {
260 $title .= " - " . to_utf8($project);
261 if (defined $action) {
262 $title .= "/$action";
263 if (defined $file_name) {
264 $title .= " - " . $file_name;
265 if ($action eq "tree" && $file_name !~ m|/$|) {
272 $c->stash->{version} = $c->config->{version};
273 $c->stash->{git_version} = $c->model('Git')->run_cmd('--version');
274 $c->stash->{title} = $title;
276 #$c->stash->{baseurl} = $ENV{PATH_INFO} && uri_escape($base_url);
277 $c->stash->{stylesheet} = $c->config->{stylesheet} || 'gitweb.css';
279 $c->stash->{project} = $project;
282 my %href_params = $self->feed_info($c);
283 $href_params{'-title'} ||= 'log';
285 foreach my $format qw(RSS Atom) {
286 my $type = lc($format);
289 title => "$project - $href_params{'-title'} - $format feed",
291 # XXX A bit hacky and could do with using gitweb::href() features
292 href => "?a=$type;p=$project",
293 type => "application/$type+xml"
297 # XXX This duplication also feels a bit awkward
298 title => "$project - $href_params{'-title'} - $format feed (no merges)",
299 href => "?a=$type;p=$project;opt=--no-merges",
300 type => "application/$type+xml"
306 title => $c->config->{sitename}." projects list",
307 href => '?a=project_index',
308 type => "text/plain; charset=utf-8"
311 title => $c->config->{sitename}." projects feeds",
313 type => "text/plain; charset=utf-8"
317 $c->stash->{favicon} = $c->config->{favicon};
322 logo_url => $c->config->{logo_url},
323 logo_label => $c->config->{logo_label},
324 logo_img => $c->config->{logo},
325 home_link => $c->config->{home_link},
326 home_link_str => $c->config->{home_link_str},
329 if(defined $project) {
331 search_text => ( $c->req->param('s') || $c->req->param('searchtext') ),
332 search_hash => ( $c->req->param('hb') || $c->req->param('hashbase')
333 || $c->req->param('h') || $c->req->param('hash')
339 # Formally git_footer_html
343 my $feed_class = 'rss_logo';
346 my $project = $c->req->param('project') || $c->req->param('p');
347 if(defined $project) {
348 (my $pstr = $project) =~ s[/?\.git$][];
349 my $descr = $c->model('Git')->project_info($project)->{description};
350 $c->stash->{project_description} = defined $descr
354 my %href_params = $self->feed_info($c);
356 $feed_class .= ' generic';
358 $href_params{'-title'} ||= 'log';
362 class => $feed_class,
363 title => "$href_params{'-title'} $_ feed",
364 href => "/?p=$project;a=\L$_",
371 class => $feed_class,
373 href => "/?a=$_->[0]",
375 }, [opml=>'OPML'],[project_index=>'TXT'],
380 # XXX This feels wrong here, should probably be refactored.
381 # returns hash to be passed to href to generate gitweb URL
382 # in -title key it returns description of link
386 my $format = shift || 'Atom';
387 my %res = (action => lc($format));
389 # feed links are possible only for project views
390 return unless $c->req->param('project');
392 # some views should link to OPML, or to generic project feed,
393 # or don't have specific feed yet (so they should use generic)
394 return if $c->req->param('action') =~ /^(?:tags|heads|forks|tag|search)$/x;
397 my $hash = $c->req->param('h') || $c->req->param('hash');
398 my $hash_base = $c->req->param('hb') || $c->req->param('hashbase');
400 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
401 # from tag links; this also makes possible to detect branch links
402 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
403 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
407 # find log type for feed description (title)
409 my $file_name = $c->req->param('f') || $c->req->param('filename');
410 if (defined $file_name) {
411 $type = "history of $file_name";
412 $type .= "/" if $c->req->param('action') eq 'tree';
413 $type .= " on '$branch'" if (defined $branch);
415 $type = "log of $branch" if (defined $branch);
418 $res{-title} = $type;
419 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
420 $res{'file_name'} = $file_name;
426 Attempt to render a view, if needed.
430 sub end : ActionClass('RenderView') {}
438 This library is free software. You can redistribute it and/or modify
439 it under the same terms as Perl itself.
443 __PACKAGE__->meta->make_immutable;