]> git.ipfire.org Git - thirdparty/git.git/commitdiff
gitweb: New improved formatting of chunk header in diff
authorJakub Narebski <jnareb@gmail.com>
Sat, 18 Nov 2006 22:35:40 +0000 (23:35 +0100)
committerJunio C Hamano <junkio@cox.net>
Tue, 21 Nov 2006 22:35:40 +0000 (14:35 -0800)
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>
gitweb/gitweb.css
gitweb/gitweb.perl

index 974b47f19ca61bd5d12ec88229957c3434d23265..7177c6e86b8e8c3dc1e5d0db4bce4122cbe2430a 100644 (file)
@@ -334,11 +334,13 @@ div.diff.extended_header {
        padding: 2px 0px 2px 0px;
 }
 
+div.diff a.list,
 div.diff a.path,
 div.diff a.hash {
        text-decoration: none;
 }
 
+div.diff a.list:hover,
 div.diff a.path:hover,
 div.diff a.hash:hover {
        text-decoration: underline;
@@ -362,14 +364,25 @@ div.diff.rem {
        color: #cc0000;
 }
 
+div.diff.chunk_header a,
 div.diff.chunk_header {
        color: #990099;
+}
 
+div.diff.chunk_header {
        border: dotted #ffe0ff;
        border-width: 1px 0px 0px 0px;
        margin-top: 2px;
 }
 
+div.diff.chunk_header span.chunk_info {
+       background-color: #ffeeff;
+}
+
+div.diff.chunk_header span.section {
+       color: #aa22aa;
+}
+
 div.diff.incomplete {
        color: #cccccc;
 }
index 19b3d36d159aa030bb827bd904274ac4922e1b33..5875ba0846a342e80179aab66abe46a87fcc1fc8 100755 (executable)
@@ -874,8 +874,10 @@ sub format_subject_html {
        }
 }
 
+# format patch (diff) line (rather not to be used for diff headers)
 sub format_diff_line {
        my $line = shift;
+       my ($from, $to) = @_;
        my $char = substr($line, 0, 1);
        my $diff_class = "";
 
@@ -891,6 +893,25 @@ sub format_diff_line {
                $diff_class = " incomplete";
        }
        $line = untabify($line);
+       if ($from && $to && $line =~ m/^\@{2} /) {
+               my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
+                       $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
+
+               $from_lines = 0 unless defined $from_lines;
+               $to_lines   = 0 unless defined $to_lines;
+
+               if ($from->{'href'}) {
+                       $from_text = $cgi->a({-href=>"$from->{'href'}#l$from_start",
+                                            -class=>"list"}, $from_text);
+               }
+               if ($to->{'href'}) {
+                       $to_text   = $cgi->a({-href=>"$to->{'href'}#l$to_start",
+                                            -class=>"list"}, $to_text);
+               }
+               $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
+                       "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
+               return "<div class=\"diff$diff_class\">$line</div>\n";
+       }
        return "<div class=\"diff$diff_class\">" . esc_html($line, -nbsp=>1) . "</div>\n";
 }
 
@@ -2372,7 +2393,7 @@ sub git_patchset_body {
 
                        next PATCH if ($patch_line =~ m/^diff /);
 
-                       print format_diff_line($patch_line);
+                       print format_diff_line($patch_line, \%from, \%to);
                }
 
        } continue {