gitweb: Separate main part of git_history into git_history_body
Separates main part of git_history into git_history_body subroutine, and makes output more similar to git_shortlog. Adds "diff to current" link only for history of regular file (blob). Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jakub Narebski committed
Aug 14, 2006 at 02:09 UTC
581860e1b8ac01c2cdcb5d98862ef7a80e789781
1 file changed
+60
-36
gitweb/gitweb.perl
+60
-36
@@ -1117,6 +1117,64 @@ sub git_shortlog_body {
1117
print "</table>\n";
1118
}
1119
1120
+sub git_history_body {
1121
+ # Warning: assumes constant type (blob or tree) during history
1122
+ my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1123
+
1124
+ print "<table class=\"history\" cellspacing=\"0\">\n";
1125
+ my $alternate = 0;
1126
+ while (my $line = <$fd>) {
1127
+ if ($line !~ m/^([0-9a-fA-F]{40})/) {
1128
+ next;
1129
+ }
1130
+
1131
+ my $commit = $1;
1132
+ my %co = parse_commit($commit);
1133
+ if (!%co) {
1134
+ next;
1135
+ }
1136
+
1137
+ my $ref = format_ref_marker($refs, $commit);
1138
+
1139
+ if ($alternate) {
1140
+ print "<tr class=\"dark\">\n";
1141
+ } else {
1142
+ print "<tr class=\"light\">\n";
1143
+ }
1144
+ $alternate ^= 1;
1145
+ print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1146
+ # shortlog uses chop_str($co{'author_name'}, 10)
1147
+ "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1148
+ "<td>";
1149
+ # originally git_history used chop_str($co{'title'}, 50)
1150
+ print format_subject_html($co{'title'}, $co{'title_short'}, "p=$project;a=commit;h=$commit", $ref);
1151
+ print "</td>\n" .
1152
+ "<td class=\"link\">" .
1153
+ $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") . " | " .
1154
+ $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") . " | " .
1155
+ $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$ftype;hb=$commit;f=$file_name")}, $ftype);
1156
+
1157
+ if ($ftype eq 'blob') {
1158
+ my $blob_current = git_get_hash_by_path($hash_base, $file_name);
1159
+ my $blob_parent = git_get_hash_by_path($commit, $file_name);
1160
+ if (defined $blob_current && defined $blob_parent &&
1161
+ $blob_current ne $blob_parent) {
1162
+ print " | " .
1163
+ $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$blob_current;hp=$blob_parent;hb=$commit;f=$file_name")},
1164
+ "diff to current");
1165
+ }
1166
+ }
1167
+ print "</td>\n" .
1168
+ "</tr>\n";
1169
+ }
1170
+ if (defined $extra) {
1171
+ print "<tr>\n" .
1172
+ "<td colspan=\"4\">$extra</td>\n" .
1173
+ "</tr>\n";
1174
+ }
1175
+ print "</table>\n";
1176
+}
1177
+
1178
sub git_tags_body {
1179
# uses global variable $project
1180
my ($taglist, $from, $to, $extra) = @_;
@@ -2297,42 +2355,8 @@ sub git_history {
2355
2356
open my $fd, "-|",
2357
$GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2300
- print "<table cellspacing=\"0\">\n";
2301
- my $alternate = 0;
2302
- while (my $line = <$fd>) {
2303
- if ($line =~ m/^([0-9a-fA-F]{40})/){
2304
- my $commit = $1;
2305
- my %co = parse_commit($commit);
2306
- if (!%co) {
2307
- next;
2308
- }
2309
- my $ref = format_ref_marker($refs, $commit);
2310
- if ($alternate) {
2311
- print "<tr class=\"dark\">\n";
2312
- } else {
2313
- print "<tr class=\"light\">\n";
2314
- }
2315
- $alternate ^= 1;
2316
- print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2317
- "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2318
- "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2319
- esc_html(chop_str($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2320
- "<td class=\"link\">" .
2321
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
2322
- " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2323
- " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$ftype;hb=$commit;f=$file_name")}, $ftype);
2324
- my $blob = git_get_hash_by_path($hash_base, $file_name);
2325
- my $blob_parent = git_get_hash_by_path($commit, $file_name);
2326
- if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2327
- print " | " .
2328
- $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2329
- "diff to current");
2330
- }
2331
- print "</td>\n" .
2332
- "</tr>\n";
2333
- }
2334
- }
2335
- print "</table>\n";
2358
+ git_history_body($fd, $refs, $hash_base, $ftype);
2359
+
2360
close $fd;
2361
git_footer_html();
2362
}