gitweb: Parse two-line from-file/to-file diff header in git_patchset_body
authorJakub Narebski <jnareb@gmail.com>
Fri, 25 Aug 2006 19:04:13 +0000 (21:04 +0200)
committerJunio C Hamano <junkio@cox.net>
Sat, 26 Aug 2006 02:41:09 +0000 (19:41 -0700)
Parse two-line from-file/to-file unified diff header in
git_patchset_body directly, instead of leaving pretty-printing to
format_diff_line function.  Hashes as from-file/to-file are replaced
by proper from-file and to-file names (from $diffinfo); in the future
we can put hyperlinks there.  This makes possible to do blobdiff with
only blobs hashes.

The lines in two-line unified diff header have now class "from_file"
and "to_file"; the style is chosen to match previous output (classes
"rem" and "add" because of '-' and '+' as first character of patch
line).

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
gitweb/gitweb.css
gitweb/gitweb.perl

index 5eaa24fd24945bcec7d7fc4230755a85238f82e4..0912361ac8f2800b259e1fa7958deb52a76f2e82 100644 (file)
@@ -273,10 +273,12 @@ td.mode {
        font-family: monospace;
 }
 
+div.diff.to_file,
 div.diff.add {
        color: #008800;
 }
 
+div.diff.from_file,
 div.diff.rem {
        color: #cc0000;
 }
index 56a47ab633272c3c8f55abe72f26567e30b5e885..b2159bb820f9b71a4150ccc40eda48234b063236 100755 (executable)
@@ -1706,8 +1706,24 @@ sub git_patchset_body {
 
 
                if ($in_header && $patch_line =~ m/^---/) {
-                       #print "</div>\n"
+                       #print "</div>\n"; # class="diff extended_header"
                        $in_header = 0;
+
+                       my $file = $diffinfo->{'from_file'};
+                       $file  ||= $diffinfo->{'file'};
+                       $patch_line =~ s|a/[0-9a-fA-F]{40}|a/$file|g;
+                       print "<div class=\"diff from_file\">" . esc_html($patch_line) . "</div>\n";
+
+                       $patch_line = <$fd>;
+                       chomp $patch_line;
+
+                       #$patch_line =~ m/^+++/;
+                       $file    = $diffinfo->{'to_file'};
+                       $file  ||= $diffinfo->{'file'};
+                       $patch_line =~ s|b/[0-9a-fA-F]{40}|b/$file|g;
+                       print "<div class=\"diff to_file\">" . esc_html($patch_line) . "</div>\n";
+
+                       next LINE;
                }
                next LINE if $in_header;