Commit | Line | Data |
319537bf |
1 | package Gitalist::Controller::LegacyURI; |
2 | use Moose; |
9c515df2 |
3 | use Moose::Autobox; |
319537bf |
4 | use namespace::autoclean; |
5 | |
6 | BEGIN { extends 'Gitalist::Controller' } |
7 | |
592fa490 |
8 | my %LEGACY_DISPATCH = ( |
6806ac0d |
9 | opml => sub { '/opml/opml' }, |
10 | project_index => sub { '/legacyuri/project_index' }, |
592fa490 |
11 | '(?:summary|heads|tags)' => sub { |
6806ac0d |
12 | my($c, $action, $repos) = @_; |
13 | return "/repository/$action", [$repos]; |
592fa490 |
14 | }, |
15 | blob => sub { |
6806ac0d |
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'); |
24450117 |
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'); |
6565d71a |
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'); |
f3be32b4 |
29 | return '/ref/diff_fancy', [$repos, $ref], $compare, $c->req->param('f'); |
65f0ead5 |
30 | }, |
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'); |
592fa490 |
36 | }, |
f3be32b4 |
37 | commit => sub { |
38 | my($c, $action, $repos) = @_; |
39 | my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD'; |
40 | return '/ref/commit', [$repos, $ref]; |
41 | }, |
42 | # XXX These can be consolidated with the blob equivalents. |
43 | commitdiff => sub { |
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'); |
48 | }, |
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'); |
54 | }, |
55 | history => sub { |
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'); |
59 | }, |
60 | log => sub { |
61 | my($c, $action, $repos) = @_; |
62 | my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD'; |
63 | return '/ref/longlog', [$repos, $ref]; |
64 | }, |
65 | patch => sub { |
66 | my($c, $action, $repos) = @_; |
67 | my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD'; |
68 | return '/ref/patch', [$repos, $ref]; |
69 | }, |
70 | patches => sub { |
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; |
74 | }, |
75 | search_help => sub { |
76 | return '/search_help'; |
77 | }, |
78 | shortlog => sub { |
79 | my($c, $action, $repos) = @_; |
80 | my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD'; |
81 | return '/ref/shortlog', [$repos, $ref]; |
82 | }, |
83 | snapshot => sub { |
84 | my($c, $action, $repos) = @_; |
85 | my $ref = $c->req->param('h') || 'HEAD'; |
86 | return '/ref/snapshot', [$repos, $ref], $c->req->param('sf'); |
87 | }, |
88 | tree => sub { |
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'); |
92 | }, |
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'); |
97 | }, |
98 | blame => sub { |
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'); |
102 | }, |
592fa490 |
103 | ); |
104 | |
105 | sub _legacy_uri { |
106 | my($self, $c, $repos, $action) = @_; |
107 | |
108 | return |
6806ac0d |
109 | unless $action; |
592fa490 |
110 | |
111 | my @result = grep { $action =~ /^$_$/ } keys %LEGACY_DISPATCH; |
112 | die "Matched too many actions for '$a' - @result" |
6806ac0d |
113 | if @result > 1; |
592fa490 |
114 | |
f3be32b4 |
115 | return |
116 | unless $result[0]; |
117 | |
118 | my($real_action, $captures, @args) = $LEGACY_DISPATCH{$result[0]}->($c, $action, $repos); |
119 | |
120 | return $real_action, $captures || [], grep defined, @args; |
592fa490 |
121 | } |
122 | |
319537bf |
123 | sub handler : Chained('/base') PathPart('legacy') Args() { |
20503690 |
124 | my ( $self, $c, $repos ) = @_; |
592fa490 |
125 | |
acbba306 |
126 | $repos ||= $c->req->param('p'); |
127 | |
592fa490 |
128 | my ($action, $captures, @args) = $self->_legacy_uri($c, $repos, $c->req->param('a')); |
129 | |
130 | die("Not supported") |
6806ac0d |
131 | unless $action; |
592fa490 |
132 | |
f3be32b4 |
133 | $c->res->redirect($c->uri_for_action($action, $captures, @args)); |
ad6d2173 |
134 | $c->res->status(301); |
319537bf |
135 | } |
136 | |
ad6d2173 |
137 | sub project_index : Chained('/base') Args(0) { |
9c515df2 |
138 | my ( $self, $c ) = @_; |
139 | |
140 | $c->response->content_type('text/plain'); |
141 | $c->response->body( |
142 | join "\n", map $_->name, $c->model()->repositories->flatten |
a46cb152 |
143 | ) or die 'No repositories found in ' . ref($c->model) . ' ' . $c->model->debug_string; |
9c515df2 |
144 | } |
145 | |
319537bf |
146 | __PACKAGE__->meta->make_immutable; |