Skip to content

Commit 59e3b14

Browse files
jnarebJunio C Hamano
authored andcommitted
gitweb: New improved formatting of chunk header in diff
If we have provided enough info, and diff is not combined diff, and if provided diff line is chunk header, then: * split chunk header into .chunk_info and .section span elements, first containing proper chunk header, second section heading (aka. which function), for separate styling: the proper chunk header is on non-white background, section heading part uses slightly lighter color. * hyperlink from-file-range to starting line of from-file, if file was not created. * hyperlink to-file-range to starting line of to-file, if file was not deleted. Links are of invisible variety (and "list" class). Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 9954f77 commit 59e3b14

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

gitweb/gitweb.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,13 @@ div.diff.extended_header {
334334
padding: 2px 0px 2px 0px;
335335
}
336336

337+
div.diff a.list,
337338
div.diff a.path,
338339
div.diff a.hash {
339340
text-decoration: none;
340341
}
341342

343+
div.diff a.list:hover,
342344
div.diff a.path:hover,
343345
div.diff a.hash:hover {
344346
text-decoration: underline;
@@ -362,14 +364,25 @@ div.diff.rem {
362364
color: #cc0000;
363365
}
364366

367+
div.diff.chunk_header a,
365368
div.diff.chunk_header {
366369
color: #990099;
370+
}
367371

372+
div.diff.chunk_header {
368373
border: dotted #ffe0ff;
369374
border-width: 1px 0px 0px 0px;
370375
margin-top: 2px;
371376
}
372377

378+
div.diff.chunk_header span.chunk_info {
379+
background-color: #ffeeff;
380+
}
381+
382+
div.diff.chunk_header span.section {
383+
color: #aa22aa;
384+
}
385+
373386
div.diff.incomplete {
374387
color: #cccccc;
375388
}

gitweb/gitweb.perl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,10 @@ sub format_subject_html {
874874
}
875875
}
876876

877+
# format patch (diff) line (rather not to be used for diff headers)
877878
sub format_diff_line {
878879
my $line = shift;
880+
my ($from, $to) = @_;
879881
my $char = substr($line, 0, 1);
880882
my $diff_class = "";
881883

@@ -891,6 +893,25 @@ sub format_diff_line {
891893
$diff_class = " incomplete";
892894
}
893895
$line = untabify($line);
896+
if ($from && $to && $line =~ m/^\@{2} /) {
897+
my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
898+
$line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
899+
900+
$from_lines = 0 unless defined $from_lines;
901+
$to_lines = 0 unless defined $to_lines;
902+
903+
if ($from->{'href'}) {
904+
$from_text = $cgi->a({-href=>"$from->{'href'}#l$from_start",
905+
-class=>"list"}, $from_text);
906+
}
907+
if ($to->{'href'}) {
908+
$to_text = $cgi->a({-href=>"$to->{'href'}#l$to_start",
909+
-class=>"list"}, $to_text);
910+
}
911+
$line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
912+
"<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
913+
return "<div class=\"diff$diff_class\">$line</div>\n";
914+
}
894915
return "<div class=\"diff$diff_class\">" . esc_html($line, -nbsp=>1) . "</div>\n";
895916
}
896917

@@ -2372,7 +2393,7 @@ sub git_patchset_body {
23722393

23732394
next PATCH if ($patch_line =~ m/^diff /);
23742395

2375-
print format_diff_line($patch_line);
2396+
print format_diff_line($patch_line, \%from, \%to);
23762397
}
23772398

23782399
} continue {

0 commit comments

Comments
 (0)