gitweb: Refactor printing commit message
Separate pretty-printing commit message (comment) into git_print_log and git_print_simplified_log subroutines. As of now the former is used in git_commit, the latter in git_log and git_commitdiff. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jakub Narebski committed
Aug 17, 2006 at 11:21 UTC
d16d093c2dcdd31b71b278591db18a9b0ccdbe90
1 file changed
+67
-65
gitweb/gitweb.perl
+67
-65
@@ -1186,6 +1186,66 @@ sub git_print_page_path {
1186
}
1187
}
1188
1189
+sub git_print_log {
1190
+ my $log = shift;
1191
+
1192
+ # remove leading empty lines
1193
+ while (defined $log->[0] && $log->[0] eq "") {
1194
+ shift @$log;
1195
+ }
1196
+
1197
+ # print log
1198
+ my $signoff = 0;
1199
+ my $empty = 0;
1200
+ foreach my $line (@$log) {
1201
+ # print only one empty line
1202
+ # do not print empty line after signoff
1203
+ if ($line eq "") {
1204
+ next if ($empty || $signoff);
1205
+ $empty = 1;
1206
+ } else {
1207
+ $empty = 0;
1208
+ }
1209
+ if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1210
+ $signoff = 1;
1211
+ print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
1212
+ } else {
1213
+ $signoff = 0;
1214
+ print format_log_line_html($line) . "<br/>\n";
1215
+ }
1216
+ }
1217
+}
1218
+
1219
+sub git_print_simplified_log {
1220
+ my $log = shift;
1221
+ my $remove_title = shift;
1222
+
1223
+ shift @$log if $remove_title;
1224
+ # remove leading empty lines
1225
+ while (defined $log->[0] && $log->[0] eq "") {
1226
+ shift @$log;
1227
+ }
1228
+
1229
+ # simplify and print log
1230
+ my $empty = 0;
1231
+ foreach my $line (@$log) {
1232
+ # remove signoff lines
1233
+ if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1234
+ next;
1235
+ }
1236
+ # print only one empty line
1237
+ if ($line eq "") {
1238
+ next if $empty;
1239
+ $empty = 1;
1240
+ } else {
1241
+ $empty = 0;
1242
+ }
1243
+ print format_log_line_html($line) . "<br/>\n";
1244
+ }
1245
+ # end with single empty line
1246
+ print "<br/>\n" unless $empty;
1247
+}
1248
+
1249
## ......................................................................
1250
## functions printing large fragments of HTML
1251
@@ -2165,27 +2225,10 @@ sub git_log {
2225
"<br/>\n" .
2226
"</div>\n" .
2227
"<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2168
- "</div>\n" .
2169
- "<div class=\"log_body\">\n";
2170
- my $comment = $co{'comment'};
2171
- my $empty = 0;
2172
- foreach my $line (@$comment) {
2173
- if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2174
- next;
2175
- }
2176
- if ($line eq "") {
2177
- if ($empty) {
2178
- next;
2179
- }
2180
- $empty = 1;
2181
- } else {
2182
- $empty = 0;
2183
- }
2184
- print format_log_line_html($line) . "<br/>\n";
2185
- }
2186
- if (!$empty) {
2187
- print "<br/>\n";
2188
- }
2228
+ "</div>\n";
2229
+
2230
+ print "<div class=\"log_body\">\n";
2231
+ git_print_simplified_log($co{'comment'});
2232
print "</div>\n";
2233
}
2234
git_footer_html();
@@ -2266,28 +2309,9 @@ sub git_commit {
2309
}
2310
print "</table>".
2311
"</div>\n";
2312
+
2313
print "<div class=\"page_body\">\n";
2270
- my $comment = $co{'comment'};
2271
- my $empty = 0;
2272
- my $signed = 0;
2273
- foreach my $line (@$comment) {
2274
- # print only one empty line
2275
- if ($line eq "") {
2276
- if ($empty || $signed) {
2277
- next;
2278
- }
2279
- $empty = 1;
2280
- } else {
2281
- $empty = 0;
2282
- }
2283
- if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2284
- $signed = 1;
2285
- print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
2286
- } else {
2287
- $signed = 0;
2288
- print format_log_line_html($line) . "<br/>\n";
2289
- }
2290
- }
2314
+ git_print_log($co{'comment'});
2315
print "</div>\n";
2316
2317
git_difftree_body(\@difftree, $parent);
@@ -2353,29 +2377,7 @@ sub git_commitdiff {
2377
git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2378
git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
2379
print "<div class=\"page_body\">\n";
2356
- my $comment = $co{'comment'};
2357
- my $empty = 0;
2358
- my $signed = 0;
2359
- my @log = @$comment;
2360
- # remove first and empty lines after that
2361
- shift @log;
2362
- while (defined $log[0] && $log[0] eq "") {
2363
- shift @log;
2364
- }
2365
- foreach my $line (@log) {
2366
- if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2367
- next;
2368
- }
2369
- if ($line eq "") {
2370
- if ($empty) {
2371
- next;
2372
- }
2373
- $empty = 1;
2374
- } else {
2375
- $empty = 0;
2376
- }
2377
- print format_log_line_html($line) . "<br/>\n";
2378
- }
2380
+ git_print_simplified_log($co{'comment'}, 1); # skip title
2381
print "<br/>\n";
2382
foreach my $line (@difftree) {
2383
# ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'