gitweb: Refactoring git_project_list
Slightly reworking git_project_list, including moving setting $order, as it is used only in this action. Mostly reindent. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jakub Narebski committed
Aug 1, 2006 at 02:59 UTC
6326b60cfd9c953e64ddab9659587afeedccd95b
1 file changed
+35
-22
gitweb/gitweb.cgi
+35
-22
@@ -81,14 +81,6 @@ if (defined $action) {
81
}
82
}
83
84
-our $order = $cgi->param('o');
85
-if (defined $order) {
86
- if ($order =~ m/[^0-9a-zA-Z_]/) {
87
- undef $order;
88
- die_error(undef, "Invalid order parameter.");
89
- }
90
-}
91
-
84
our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
85
if (defined $project) {
86
$project =~ s|^/||; $project =~ s|/$||;
@@ -1297,10 +1289,15 @@ sub git_logo {
1289
}
1290
1291
sub git_project_list {
1292
+ my $order = $cgi->param('o');
1293
+ if (defined $order && $order !~ m/project|descr|owner|age/) {
1294
+ die_error(undef, "Invalid order parameter '$order'.");
1295
+ }
1296
+
1297
my @list = git_read_projects();
1298
my @projects;
1299
if (!@list) {
1303
- die_error(undef, "No project found.");
1300
+ die_error(undef, "No projects found.");
1301
}
1302
foreach my $pr (@list) {
1303
my $head = git_read_head($pr->{'path'});
@@ -1322,6 +1319,7 @@ sub git_project_list {
1319
}
1320
push @projects, $pr;
1321
}
1322
+
1323
git_header_html();
1324
if (-f $home_text) {
1325
print "<div class=\"index_include\">\n";
@@ -1332,29 +1330,42 @@ sub git_project_list {
1330
}
1331
print "<table class=\"project_list\">\n" .
1332
"<tr>\n";
1335
- if (!defined($order) || (defined($order) && ($order eq "project"))) {
1333
+ $order ||= "project";
1334
+ if ($order eq "project") {
1335
@projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1336
print "<th>Project</th>\n";
1337
} else {
1339
- print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=project")}, "Project") . "</th>\n";
1338
+ print "<th>" .
1339
+ $cgi->a({-href => "$my_uri?" . esc_param("o=project"),
1340
+ -class => "header"}, "Project") .
1341
+ "</th>\n";
1342
}
1341
- if (defined($order) && ($order eq "descr")) {
1343
+ if ($order eq "descr") {
1344
@projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1345
print "<th>Description</th>\n";
1346
} else {
1345
- print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=descr")}, "Description") . "</th>\n";
1347
+ print "<th>" .
1348
+ $cgi->a({-href => "$my_uri?" . esc_param("o=descr"),
1349
+ -class => "header"}, "Description") .
1350
+ "</th>\n";
1351
}
1347
- if (defined($order) && ($order eq "owner")) {
1352
+ if ($order eq "owner") {
1353
@projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1354
print "<th>Owner</th>\n";
1355
} else {
1351
- print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=owner")}, "Owner") . "</th>\n";
1356
+ print "<th>" .
1357
+ $cgi->a({-href => "$my_uri?" . esc_param("o=owner"),
1358
+ -class => "header"}, "Owner") .
1359
+ "</th>\n";
1360
}
1353
- if (defined($order) && ($order eq "age")) {
1361
+ if ($order eq "age") {
1362
@projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1363
print "<th>Last Change</th>\n";
1364
} else {
1357
- print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=age")}, "Last Change") . "</th>\n";
1365
+ print "<th>" .
1366
+ $cgi->a({-href => "$my_uri?" . esc_param("o=age"),
1367
+ -class => "header"}, "Last Change") .
1368
+ "</th>\n";
1369
}
1370
print "<th></th>\n" .
1371
"</tr>\n";
@@ -1366,14 +1377,16 @@ sub git_project_list {
1377
print "<tr class=\"light\">\n";
1378
}
1379
$alternate ^= 1;
1369
- print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
1380
+ print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary"),
1381
+ -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
1382
"<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
1383
"<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
1372
- print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" . $pr->{'commit'}{'age_string'} . "</td>\n" .
1384
+ print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" .
1385
+ $pr->{'commit'}{'age_string'} . "</td>\n" .
1386
"<td class=\"link\">" .
1374
- $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary")}, "summary") .
1375
- " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=shortlog")}, "shortlog") .
1376
- " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=log")}, "log") .
1387
+ $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary")}, "summary") . " | " .
1388
+ $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=shortlog")}, "shortlog") . " | " .
1389
+ $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=log")}, "log") .
1390
"</td>\n" .
1391
"</tr>\n";
1392
}