gitweb: continue consolidation of URL generation.
Further use href() instead of URL generation by string concatenation. Almost all functions are converted now. Signed-off-by: Martin Waitz <tali@admingilde.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Martin Waitz committed
Aug 17, 2006 at 00:28 UTC
756d2f064b2419fcdf9cd9c851f352e2a4f75103
1 file changed
+35
-33
gitweb/gitweb.perl
+35
-33
@@ -204,7 +204,9 @@ sub href(%) {
204
205
my $href = "$my_uri?";
206
$href .= esc_param( join(";",
207
- map { "$mapping{$_}=$params{$_}" } keys %params
207
+ map {
208
+ "$mapping{$_}=$params{$_}" if defined $params{$_}
209
+ } keys %params
210
) );
211
212
return $href;
@@ -1058,7 +1060,7 @@ sub git_footer_html {
1060
}
1061
print $cgi->a({-href => href(action=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1062
} else {
1061
- print $cgi->a({-href => "$my_uri?" . esc_param("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
1063
+ print $cgi->a({-href => href(action=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1064
}
1065
print "</div>\n" .
1066
"</body>\n" .
@@ -1263,7 +1265,7 @@ sub git_difftree_body {
1265
"<td class=\"link\">" .
1266
$cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$file)}, "blob");
1267
if ($to_id ne $from_id) { # modified
1266
- print $cgi->a({-href => href(action=>"blobdiff", hash=>$to_id, hash_parent=>$from_id, hash_base=>$hash, file_name=>$file)}, "diff");
1268
+ print " | " . $cgi->a({-href => href(action=>"blobdiff", hash=>$to_id, hash_parent=>$from_id, hash_base=>$hash, file_name=>$file)}, "diff");
1269
}
1270
print " | " . $cgi->a({-href => href(action=>"history", hash_base=>$hash, file_name=>$file)}, "history") . "\n";
1271
print "</td>\n";
@@ -1674,16 +1676,16 @@ sub git_project_list {
1676
print "<tr class=\"light\">\n";
1677
}
1678
$alternate ^= 1;
1677
- print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary"),
1679
+ print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
1680
-class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
1681
"<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
1682
"<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
1683
print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" .
1684
$pr->{'commit'}{'age_string'} . "</td>\n" .
1685
"<td class=\"link\">" .
1684
- $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary")}, "summary") . " | " .
1685
- $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=shortlog")}, "shortlog") . " | " .
1686
- $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=log")}, "log") .
1686
+ $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
1687
+ $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
1688
+ $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") .
1689
"</td>\n" .
1690
"</tr>\n";
1691
}
@@ -2051,11 +2053,11 @@ sub git_tree {
2053
my $refs = git_get_references();
2054
my $ref = format_ref_marker($refs, $hash_base);
2055
git_header_html();
2054
- my $base_key = "";
2056
+ my %base_key = ();
2057
my $base = "";
2058
my $have_blame = git_get_project_config_bool ('blame');
2059
if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2058
- $base_key = ";hb=$hash_base";
2060
+ $base_key{hash_base} = $hash_base;
2061
git_print_page_nav('tree','', $hash_base);
2062
git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
2063
} else {
@@ -2086,23 +2088,23 @@ sub git_tree {
2088
print "<td class=\"mode\">" . mode_str($t_mode) . "</td>\n";
2089
if ($t_type eq "blob") {
2090
print "<td class=\"list\">" .
2089
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name"), -class => "list"}, esc_html($t_name)) .
2091
+ $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key), -class => "list"}, esc_html($t_name)) .
2092
"</td>\n" .
2093
"<td class=\"link\">" .
2092
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob");
2094
+ $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key)}, "blob");
2095
if ($have_blame) {
2094
- print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame");
2096
+ print " | " . $cgi->a({-href => href(action=>"blame", hash=>$t_hash, file_name=>"$base$t_name", %base_key)}, "blame");
2097
}
2096
- print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
2097
- " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
2098
+ print " | " . $cgi->a({-href => href(action=>"history", hash=>$t_hash, hash_base=>$hash_base, file_name=>"$base$t_name")}, "history") .
2099
+ " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$t_hash, file_name=>"$base$t_name")}, "raw") .
2100
"</td>\n";
2101
} elsif ($t_type eq "tree") {
2102
print "<td class=\"list\">" .
2101
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html($t_name)) .
2103
+ $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)}, esc_html($t_name)) .
2104
"</td>\n" .
2105
"<td class=\"link\">" .
2104
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
2105
- " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
2106
+ $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)}, "tree") .
2107
+ " | " . $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, file_name=>"$base$t_name")}, "history") .
2108
"</td>\n";
2109
}
2110
print "</tr>\n";
@@ -2291,7 +2293,7 @@ sub git_blobdiff {
2293
git_header_html();
2294
if (defined $hash_base && (my %co = parse_commit($hash_base))) {
2295
my $formats_nav =
2294
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2296
+ $cgi->a({-href => href(action=>"blobdiff_plain", hash=>$hash, hash_parent=>$hash_parent)}, "plain");
2297
git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2298
git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
2299
} else {
@@ -2302,9 +2304,9 @@ sub git_blobdiff {
2304
git_print_page_path($file_name, "blob");
2305
print "<div class=\"page_body\">\n" .
2306
"<div class=\"diff_info\">blob:" .
2305
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2307
+ $cgi->a({-href => href(action=>"blob", hash=>$hash_parent, hash_base=>$hash_base, file_name=>$file_name)}, $hash_parent) .
2308
" -> blob:" .
2307
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2309
+ $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)}, $hash) .
2310
"</div>\n";
2311
git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2312
print "</div>";
@@ -2339,7 +2341,7 @@ sub git_commitdiff {
2341
my $refs = git_get_references();
2342
my $ref = format_ref_marker($refs, $co{'id'});
2343
my $formats_nav =
2342
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2344
+ $cgi->a({-href => href(action=>"commitdiff_plain", hash=>$hash, hash_parent=>$hash_parent)}, "plain");
2345
git_header_html(undef, $expires);
2346
git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2347
git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
@@ -2382,22 +2384,22 @@ sub git_commitdiff {
2384
my $file = validate_input(unquote($6));
2385
if ($status eq "A") {
2386
print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
2385
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2387
+ $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$file)}, $to_id) . "(new)" .
2388
"</div>\n";
2389
git_diff_print(undef, "/dev/null", $to_id, "b/$file");
2390
} elsif ($status eq "D") {
2391
print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
2390
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash_parent;f=$file")}, $from_id) . "(deleted)" .
2392
+ $cgi->a({-href => href(action=>"blob", hash=>$from_id, hash_base=>$hash_parent, file_name=>$file)}, $from_id) . "(deleted)" .
2393
"</div>\n";
2394
git_diff_print($from_id, "a/$file", undef, "/dev/null");
2395
} elsif ($status eq "M") {
2396
if ($from_id ne $to_id) {
2397
print "<div class=\"diff_info\">" .
2398
file_type($from_mode) . ":" .
2397
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash_parent;f=$file")}, $from_id) .
2399
+ $cgi->a({-href => href(action=>"blob", hash=>$from_id, hash_base=>$hash_parent, file_name=>$file)}, $from_id) .
2400
" -> " .
2401
file_type($to_mode) . ":" .
2400
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2402
+ $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$file)}, $to_id) .
2403
print "</div>\n";
2404
git_diff_print($from_id, "a/$file", $to_id, "b/$file");
2405
}
@@ -2559,7 +2561,7 @@ sub git_search {
2561
print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2562
"<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2563
"<td>" .
2562
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" . esc_html(chop_str($co{'title'}, 50)) . "</b><br/>");
2564
+ $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}) -class => "list"}, "<b>" . esc_html(chop_str($co{'title'}, 50)) . "</b><br/>");
2565
my $comment = $co{'comment'};
2566
foreach my $line (@$comment) {
2567
if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
@@ -2574,8 +2576,8 @@ sub git_search {
2576
}
2577
print "</td>\n" .
2578
"<td class=\"link\">" .
2577
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2578
- " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2579
+ $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
2580
+ " | " . $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
2581
print "</td>\n" .
2582
"</tr>\n";
2583
}
@@ -2612,18 +2614,18 @@ sub git_search {
2614
print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2615
"<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2616
"<td>" .
2615
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2617
+ $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list"}, "<b>" .
2618
esc_html(chop_str($co{'title'}, 50)) . "</b><br/>");
2619
while (my $setref = shift @files) {
2620
my %set = %$setref;
2619
- print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2621
+ print $cgi->a({-href => href(action=>"blob", hash=>$set{'id'}, hash_base=>$co{'id'}, file_name=>$set{'file'}), class => "list"},
2622
"<span class=\"match\">" . esc_html($set{'file'}) . "</span>") .
2623
"<br/>\n";
2624
}
2625
print "</td>\n" .
2626
"<td class=\"link\">" .
2625
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2626
- " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2627
+ $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
2628
+ " | " . $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
2629
print "</td>\n" .
2630
"</tr>\n";
2631
}
@@ -2656,7 +2658,7 @@ sub git_shortlog {
2658
my $next_link = '';
2659
if ($#revlist >= (100 * ($page+1)-1)) {
2660
$next_link =
2659
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)),
2661
+ $cgi->a({-href => href(action=>"shortlog", hash=>$hash, page=>$page+1),
2662
-title => "Alt-n"}, "next");
2663
}
2664