1 package Gitalist::Controller::LegacyURI;
4 use namespace::autoclean;
6 BEGIN { extends 'Gitalist::Controller' }
8 my %LEGACY_DISPATCH = (
9 opml => sub { '/opml/opml' },
10 project_index => sub { '/legacyuri/project_index' },
11 '(?:summary|heads|tags)' => sub {
12 my($c, $action, $repos) = @_;
13 return "/repository/$action", [$repos];
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');
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');
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_fancy', [$repos, $ref], $compare, $c->req->param('f');
31 blobdiff_plain => sub {
32 my($c, $action, $repos) = @_;
33 my $ref = $c->req->param('hb') || $c->req->param('h');
34 my $compare = $c->req->param('hbp') || $c->req->param('hp');
35 return '/ref/diff_plain', [$repos, $ref], $compare, $c->req->param('f');
38 my($c, $action, $repos) = @_;
39 my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD';
40 return '/ref/commit', [$repos, $ref];
42 # XXX These can be consolidated with the blob equivalents.
44 my($c, $action, $repos) = @_;
45 my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD';
46 my $compare = $c->req->param('hbp') || $c->req->param('hp');
47 return '/ref/diff_fancy', [$repos, $ref], $compare, $c->req->param('f');
49 commitdiff_plain => sub {
50 my($c, $action, $repos) = @_;
51 my $ref = $c->req->param('hb') || $c->req->param('h');
52 my $compare = $c->req->param('hbp') || $c->req->param('hp');
53 return '/ref/diff_plain', [$repos, $ref || 'HEAD'], $compare, $c->req->param('f');
56 my($c, $action, $repos) = @_;
57 my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD';
58 return '/ref/history', [$repos, $ref], $c->req->param('f');
61 my($c, $action, $repos) = @_;
62 my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD';
63 return '/ref/longlog', [$repos, $ref];
66 my($c, $action, $repos) = @_;
67 my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD';
68 return '/ref/patch', [$repos, $ref];
71 my($c, $action, $repos) = @_;
72 # XXX Is the arg there wrong? It's just copying G::C::R::patch.
73 return '/ref/patches', [$repos, $c->req->param('h') || 'HEAD'], 1;
76 return '/search_help';
79 my($c, $action, $repos) = @_;
80 my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD';
81 return '/ref/shortlog', [$repos, $ref];
84 my($c, $action, $repos) = @_;
85 my $ref = $c->req->param('h') || 'HEAD';
86 return '/ref/snapshot', [$repos, $ref], $c->req->param('sf');
89 my($c, $action, $repos) = @_;
90 my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD';
91 return '/ref/tree', [$repos, $ref], $c->req->param('f');
93 '(?:atom|rss)' => sub {
94 my($c, $action, $repos) = @_;
95 # XXX No support for arbitrary branches or merges/nomerges option :(
96 return "/repository/$action", [$repos], $c->req->param('f');
99 my($c, $action, $repos) = @_;
100 my $ref = $c->req->param('hb') || $c->req->param('h');
101 return '/ref/blame', [$repos, $ref], $c->req->param('f');
106 my($self, $c, $repos, $action) = @_;
111 my @result = grep { $action =~ /^$_$/ } keys %LEGACY_DISPATCH;
112 die "Matched too many actions for '$a' - @result"
118 my($real_action, $captures, @args) = $LEGACY_DISPATCH{$result[0]}->($c, $action, $repos);
120 return $real_action, $captures || [], grep defined, @args;
123 sub handler : Chained('/base') PathPart('legacy') Args() {
124 my ( $self, $c, $repos ) = @_;
126 $repos ||= $c->req->param('p');
128 my ($action, $captures, @args) = $self->_legacy_uri($c, $repos, $c->req->param('a'));
133 $c->res->redirect($c->uri_for_action($action, $captures, @args));
134 $c->res->status(301);
137 sub project_index : Chained('/base') Args(0) {
138 my ( $self, $c ) = @_;
140 $c->response->content_type('text/plain');
142 join "\n", map $_->name, $c->model()->repositories->flatten
143 ) or die 'No repositories found in '. $c->model->repo_dir;
146 __PACKAGE__->meta->make_immutable;