@matheusbsbs / matheus-bagliano / commits / 8e85cdc4ef
Fork 0

gitweb: use a hash to lookup the sub for an action

Signed-off-by: Matthias Lederhofer <matled@gmx.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Matthias Lederhofer committed Jul 31, 2006 at 23:46 UTC 8e85cdc4efd15fa70dfbbfebaf3ef9a758c2772c
1 file changed +25 -56
gitweb/gitweb.cgi
+25 -56
@@ -161,65 +161,34 @@ if (defined $searchtext) {
161 }
162
163 # dispatch
164 -if (!defined $action || $action eq "summary") {
165 - git_summary();
166 - exit;
167 -} elsif ($action eq "heads") {
168 - git_heads();
169 - exit;
170 -} elsif ($action eq "tags") {
171 - git_tags();
172 - exit;
173 -} elsif ($action eq "blob") {
174 - git_blob();
175 - exit;
176 -} elsif ($action eq "blob_plain") {
177 - git_blob_plain();
178 - exit;
179 -} elsif ($action eq "tree") {
180 - git_tree();
181 - exit;
182 -} elsif ($action eq "rss") {
183 - git_rss();
184 - exit;
185 -} elsif ($action eq "commit") {
186 - git_commit();
187 - exit;
188 -} elsif ($action eq "log") {
189 - git_log();
190 - exit;
191 -} elsif ($action eq "blobdiff") {
192 - git_blobdiff();
193 - exit;
194 -} elsif ($action eq "blobdiff_plain") {
195 - git_blobdiff_plain();
196 - exit;
197 -} elsif ($action eq "commitdiff") {
198 - git_commitdiff();
199 - exit;
200 -} elsif ($action eq "commitdiff_plain") {
201 - git_commitdiff_plain();
202 - exit;
203 -} elsif ($action eq "history") {
204 - git_history();
205 - exit;
206 -} elsif ($action eq "search") {
207 - git_search();
208 - exit;
209 -} elsif ($action eq "shortlog") {
210 - git_shortlog();
211 - exit;
212 -} elsif ($action eq "tag") {
213 - git_tag();
214 - exit;
215 -} elsif ($action eq "blame") {
216 - git_blame2();
217 - exit;
218 -} else {
164 +my %actions = (
165 + "blame" => \&git_blame2,
166 + "blobdiff" => \&git_blobdiff,
167 + "blobdiff_plain" => \&git_blobdiff_plain,
168 + "blob" => \&git_blob,
169 + "blob_plain" => \&git_blob_plain,
170 + "commitdiff" => \&git_commitdiff,
171 + "commitdiff_plain" => \&git_commitdiff_plain,
172 + "commit" => \&git_commit,
173 + "heads" => \&git_heads,
174 + "history" => \&git_history,
175 + "log" => \&git_log,
176 + "rss" => \&git_rss,
177 + "search" => \&git_search,
178 + "shortlog" => \&git_shortlog,
179 + "summary" => \&git_summary,
180 + "tag" => \&git_tag,
181 + "tags" => \&git_tags,
182 + "tree" => \&git_tree,
183 +);
184 +
185 +$action = 'summary' if (!defined($action));
186 +if (!defined($actions{$action})) {
187 undef $action;
188 die_error(undef, "Unknown action.");
221 - exit;
189 }
190 +$actions{$action}->();
191 +exit;
192
193 ## ======================================================================
194 ## validation, quoting/unquoting and escaping