@matheusbsbs / matheus-bagliano / commits / 744d0ac33a
Fork 0

gitweb: New improved patchset view

Replace "gitweb diff header" with its full sha1 of blobs and replace it by "git diff" header and extended diff header. Change also somewhat highlighting of diffs. Added `file_type_long' subroutine to convert file mode in octal to file type description (only for file modes which used by git). Changes: * "gitweb diff header" which looked for example like below: file:_<sha1 before>_ -> file:_<sha1 after>_ where 'file' is file type and '<sha1>' is full sha1 of blob is changed to diff --git _a/<file before>_ _b/<file after>_ In both cases links are visible and use default link style. If file is added, a/<file> is not hyperlinked. If file is deleted, b/<file> is not hyperlinked. * there is added "extended diff header", with <path> and <hash> hyperlinked (and <hash> shortened to 7 characters), and <mode> explained: '<mode>' is extended to '<mode> (<file type description>)', where added text is slightly lighter to easy distinguish that it was added (and it is difference from git-diff output). * from-file/to-file two-line header lines have slightly darker color than removed/added lines. * chunk header has now delicate line above for easier finding chunk boundary, and top margin of 2px, both barely visible. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jakub Narebski committed Nov 8, 2006 at 17:59 UTC 744d0ac33ab579845808b8b01e526adc4678a226
2 files changed +173 -76
gitweb/gitweb.css
+54 -12
@@ -298,40 +298,82 @@ td.mode {
298 font-family: monospace;
299 }
300
301 -div.diff a.list {
301 +/* styling of diffs (patchsets): commitdiff and blobdiff views */
302 +div.diff.header,
303 +div.diff.extended_header {
304 + white-space: normal;
305 +}
306 +
307 +div.diff.header {
308 + font-weight: bold;
309 +
310 + background-color: #edece6;
311 +
312 + margin-top: 4px;
313 + padding: 4px 0px 2px 0px;
314 + border: solid #d9d8d1;
315 + border-width: 1px 0px 1px 0px;
316 +}
317 +
318 +div.diff.header a.path {
319 + text-decoration: underline;
320 +}
321 +
322 +div.diff.extended_header,
323 +div.diff.extended_header a.path,
324 +div.diff.extended_header a.hash {
325 + color: #777777;
326 +}
327 +
328 +div.diff.extended_header .info {
329 + color: #b0b0b0;
330 +}
331 +
332 +div.diff.extended_header {
333 + background-color: #f6f5ee;
334 + padding: 2px 0px 2px 0px;
335 +}
336 +
337 +div.diff a.path,
338 +div.diff a.hash {
339 text-decoration: none;
340 }
341
305 -div.diff a.list:hover {
342 +div.diff a.path:hover,
343 +div.diff a.hash:hover {
344 text-decoration: underline;
345 }
346
309 -div.diff.to_file a.list,
310 -div.diff.to_file,
347 +div.diff.to_file a.path,
348 +div.diff.to_file {
349 + color: #007000;
350 +}
351 +
352 div.diff.add {
353 color: #008800;
354 }
355
315 -div.diff.from_file a.list,
316 -div.diff.from_file,
356 +div.diff.from_file a.path,
357 +div.diff.from_file {
358 + color: #aa0000;
359 +}
360 +
361 div.diff.rem {
362 color: #cc0000;
363 }
364
365 div.diff.chunk_header {
366 color: #990099;
367 +
368 + border: dotted #ffe0ff;
369 + border-width: 1px 0px 0px 0px;
370 + margin-top: 2px;
371 }
372
373 div.diff.incomplete {
374 color: #cccccc;
375 }
376
329 -div.diff_info {
330 - font-family: monospace;
331 - color: #000099;
332 - background-color: #edece6;
333 - font-style: italic;
334 -}
377
378 div.index_include {
379 border: solid #d9d8d1;
gitweb/gitweb.perl
+119 -64
@@ -785,6 +785,32 @@ sub file_type {
785 }
786 }
787
788 +# convert file mode in octal to file type description string
789 +sub file_type_long {
790 + my $mode = shift;
791 +
792 + if ($mode !~ m/^[0-7]+$/) {
793 + return $mode;
794 + } else {
795 + $mode = oct $mode;
796 + }
797 +
798 + if (S_ISDIR($mode & S_IFMT)) {
799 + return "directory";
800 + } elsif (S_ISLNK($mode)) {
801 + return "symlink";
802 + } elsif (S_ISREG($mode)) {
803 + if ($mode & S_IXUSR) {
804 + return "executable";
805 + } else {
806 + return "file";
807 + };
808 + } else {
809 + return "unknown";
810 + }
811 +}
812 +
813 +
814 ## ----------------------------------------------------------------------
815 ## functions returning short HTML fragments, or transforming HTML fragments
816 ## which don't beling to other sections
@@ -2171,6 +2197,7 @@ sub git_patchset_body {
2197 my $in_header = 0;
2198 my $patch_found = 0;
2199 my $diffinfo;
2200 + my (%from, %to);
2201
2202 print "<div class=\"patchset\">\n";
2203
@@ -2181,6 +2208,10 @@ sub git_patchset_body {
2208 if ($patch_line =~ m/^diff /) { # "git diff" header
2209 # beginning of patch (in patchset)
2210 if ($patch_found) {
2211 + # close extended header for previous empty patch
2212 + if ($in_header) {
2213 + print "</div>\n" # class="diff extended_header"
2214 + }
2215 # close previous patch
2216 print "</div>\n"; # class="patch"
2217 } else {
@@ -2189,89 +2220,113 @@ sub git_patchset_body {
2220 }
2221 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2222
2223 + # read and prepare patch information
2224 if (ref($difftree->[$patch_idx]) eq "HASH") {
2225 + # pre-parsed (or generated by hand)
2226 $diffinfo = $difftree->[$patch_idx];
2227 } else {
2228 $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]);
2229 }
2230 + $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2231 + $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2232 + if ($diffinfo->{'status'} ne "A") { # not new (added) file
2233 + $from{'href'} = href(action=>"blob", hash_base=>$hash_parent,
2234 + hash=>$diffinfo->{'from_id'},
2235 + file_name=>$from{'file'});
2236 + }
2237 + if ($diffinfo->{'status'} ne "D") { # not deleted file
2238 + $to{'href'} = href(action=>"blob", hash_base=>$hash,
2239 + hash=>$diffinfo->{'to_id'},
2240 + file_name=>$to{'file'});
2241 + }
2242 $patch_idx++;
2243
2199 - if ($diffinfo->{'status'} eq "A") { # added
2200 - print "<div class=\"diff_info\">" . file_type($diffinfo->{'to_mode'}) . ":" .
2201 - $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
2202 - hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
2203 - $diffinfo->{'to_id'}) . " (new)" .
2204 - "</div>\n"; # class="diff_info"
2205 -
2206 - } elsif ($diffinfo->{'status'} eq "D") { # deleted
2207 - print "<div class=\"diff_info\">" . file_type($diffinfo->{'from_mode'}) . ":" .
2208 - $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
2209 - hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
2210 - $diffinfo->{'from_id'}) . " (deleted)" .
2211 - "</div>\n"; # class="diff_info"
2212 -
2213 - } elsif ($diffinfo->{'status'} eq "R" || # renamed
2214 - $diffinfo->{'status'} eq "C" || # copied
2215 - $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
2216 - print "<div class=\"diff_info\">" .
2217 - file_type($diffinfo->{'from_mode'}) . ":" .
2218 - $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
2219 - hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'from_file'})},
2220 - $diffinfo->{'from_id'}) .
2221 - " -> " .
2222 - file_type($diffinfo->{'to_mode'}) . ":" .
2223 - $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
2224 - hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'to_file'})},
2225 - $diffinfo->{'to_id'});
2226 - print "</div>\n"; # class="diff_info"
2227 -
2228 - } else { # modified, mode changed, ...
2229 - print "<div class=\"diff_info\">" .
2230 - file_type($diffinfo->{'from_mode'}) . ":" .
2231 - $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
2232 - hash=>$diffinfo->{'from_id'}, file_name=>$diffinfo->{'file'})},
2233 - $diffinfo->{'from_id'}) .
2234 - " -> " .
2235 - file_type($diffinfo->{'to_mode'}) . ":" .
2236 - $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
2237 - hash=>$diffinfo->{'to_id'}, file_name=>$diffinfo->{'file'})},
2238 - $diffinfo->{'to_id'});
2239 - print "</div>\n"; # class="diff_info"
2244 + # print "git diff" header
2245 + $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2246 + if ($from{'href'}) {
2247 + $patch_line .= $cgi->a({-href => $from{'href'}, -class => "path"},
2248 + 'a/' . esc_path($from{'file'}));
2249 + } else { # file was added
2250 + $patch_line .= 'a/' . esc_path($from{'file'});
2251 + }
2252 + $patch_line .= ' ';
2253 + if ($to{'href'}) {
2254 + $patch_line .= $cgi->a({-href => $to{'href'}, -class => "path"},
2255 + 'b/' . esc_path($to{'file'}));
2256 + } else { # file was deleted
2257 + $patch_line .= 'b/' . esc_path($to{'file'});
2258 }
2259
2242 - #print "<div class=\"diff extended_header\">\n";
2260 + print "<div class=\"diff header\">$patch_line</div>\n";
2261 + print "<div class=\"diff extended_header\">\n";
2262 $in_header = 1;
2263 next LINE;
2245 - } # start of patch in patchset
2264 + }
2265
2266 + if ($in_header) {
2267 + if ($patch_line !~ m/^---/) {
2268 + # match <path>
2269 + if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2270 + $patch_line .= $cgi->a({-href=>$from{'href'}, -class=>"path"},
2271 + esc_path($from{'file'}));
2272 + }
2273 + if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2274 + $patch_line = $cgi->a({-href=>$to{'href'}, -class=>"path"},
2275 + esc_path($to{'file'}));
2276 + }
2277 + # match <mode>
2278 + if ($patch_line =~ m/\s(\d{6})$/) {
2279 + $patch_line .= '<span class="info"> (' .
2280 + file_type_long($1) .
2281 + ')</span>';
2282 + }
2283 + # match <hash>
2284 + if ($patch_line =~ m/^index/) {
2285 + my ($from_link, $to_link);
2286 + if ($from{'href'}) {
2287 + $from_link = $cgi->a({-href=>$from{'href'}, -class=>"hash"},
2288 + substr($diffinfo->{'from_id'},0,7));
2289 + } else {
2290 + $from_link = '0' x 7;
2291 + }
2292 + if ($to{'href'}) {
2293 + $to_link = $cgi->a({-href=>$to{'href'}, -class=>"hash"},
2294 + substr($diffinfo->{'to_id'},0,7));
2295 + } else {
2296 + $to_link = '0' x 7;
2297 + }
2298 + my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2299 + $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2300 + }
2301 + print $patch_line . "<br/>\n";
2302
2248 - if ($in_header && $patch_line =~ m/^---/) {
2249 - #print "</div>\n"; # class="diff extended_header"
2250 - $in_header = 0;
2303 + } else {
2304 + #$in_header && $patch_line =~ m/^---/;
2305 + print "</div>\n"; # class="diff extended_header"
2306 + $in_header = 0;
2307 +
2308 + if ($from{'href'}) {
2309 + $patch_line = '--- a/' .
2310 + $cgi->a({-href=>$from{'href'}, -class=>"path"},
2311 + esc_path($from{'file'}));
2312 + }
2313 + print "<div class=\"diff from_file\">$patch_line</div>\n";
2314
2252 - my $file = $diffinfo->{'from_file'};
2253 - $file ||= $diffinfo->{'file'};
2254 - $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash_parent,
2255 - hash=>$diffinfo->{'from_id'}, file_name=>$file),
2256 - -class => "list"}, esc_path($file));
2257 - $patch_line =~ s|a/.*$|a/$file|g;
2258 - print "<div class=\"diff from_file\">$patch_line</div>\n";
2315 + $patch_line = <$fd>;
2316 + chomp $patch_line;
2317
2260 - $patch_line = <$fd>;
2261 - chomp $patch_line;
2318 + #$patch_line =~ m/^+++/;
2319 + if ($to{'href'}) {
2320 + $patch_line = '+++ b/' .
2321 + $cgi->a({-href=>$to{'href'}, -class=>"path"},
2322 + esc_path($to{'file'}));
2323 + }
2324 + print "<div class=\"diff to_file\">$patch_line</div>\n";
2325
2263 - #$patch_line =~ m/^+++/;
2264 - $file = $diffinfo->{'to_file'};
2265 - $file ||= $diffinfo->{'file'};
2266 - $file = $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
2267 - hash=>$diffinfo->{'to_id'}, file_name=>$file),
2268 - -class => "list"}, esc_path($file));
2269 - $patch_line =~ s|b/.*|b/$file|g;
2270 - print "<div class=\"diff to_file\">$patch_line</div>\n";
2326 + }
2327
2328 next LINE;
2329 }
2274 - next LINE if $in_header;
2330
2331 print format_diff_line($patch_line);
2332 }