Provided support for blobdiff legacy URIs.
[catagits/Gitalist.git] / lib / Gitalist / Controller / LegacyURI.pm
CommitLineData
319537bf 1package Gitalist::Controller::LegacyURI;
2use Moose;
9c515df2 3use Moose::Autobox;
319537bf 4use namespace::autoclean;
5
6BEGIN { extends 'Gitalist::Controller' }
7
894b2dc8 8my %LEGACY_DISPATCH = (
7ce87dff 9 opml => sub { '/opml/opml' },
10 project_index => sub { '/legacyuri/project_index' },
894b2dc8 11 '(?:summary|heads|tags)' => sub {
7ce87dff 12 my($c, $action, $repos) = @_;
13 return "/repository/$action", [$repos];
894b2dc8 14 },
15 blob => sub {
7ce87dff 16 my($c, $action, $repos) = @_;
17 my $ref = $c->req->param('hb') || $c->req->param('h');
18 return '/ref/blob', [$repos, $ref], $c->req->param('f');
4a3445c1 19 },
20 blob_plain => sub {
21 my($c, $action, $repos) = @_;
22 my $ref = $c->req->param('hb') || $c->req->param('h');
23 return '/ref/raw', [$repos, $ref], $c->req->param('f');
2a3e4697 24 },
25 blobdiff => sub {
26 my($c, $action, $repos) = @_;
27 my $ref = $c->req->param('hb') || $c->req->param('h');
28 my $compare = $c->req->param('hbp') || $c->req->param('hp');
29 return '/ref/diff', [$repos, $ref], $compare, $c->req->param('f');
894b2dc8 30 },
31);
32
33sub _legacy_uri {
34 my($self, $c, $repos, $action) = @_;
35
36 return
7ce87dff 37 unless $action;
894b2dc8 38
39 my @result = grep { $action =~ /^$_$/ } keys %LEGACY_DISPATCH;
40 die "Matched too many actions for '$a' - @result"
7ce87dff 41 if @result > 1;
894b2dc8 42
43 return $LEGACY_DISPATCH{$result[0]}->($c, $action, $repos)
7ce87dff 44 if $result[0];
894b2dc8 45}
46
319537bf 47sub handler : Chained('/base') PathPart('legacy') Args() {
20503690 48 my ( $self, $c, $repos ) = @_;
894b2dc8 49
50 my ($action, $captures, @args) = $self->_legacy_uri($c, $repos, $c->req->param('a'));
51
52 die("Not supported")
7ce87dff 53 unless $action;
894b2dc8 54
55 $c->res->redirect($c->uri_for_action($action, $captures || [], @args));
ad6d2173 56 $c->res->status(301);
319537bf 57}
58
ad6d2173 59sub project_index : Chained('/base') Args(0) {
9c515df2 60 my ( $self, $c ) = @_;
61
62 $c->response->content_type('text/plain');
63 $c->response->body(
64 join "\n", map $_->name, $c->model()->repositories->flatten
65 ) or die 'No repositories found in '. $c->model->repo_dir;
66}
67
319537bf 68__PACKAGE__->meta->make_immutable;