@matheusbsbs / matheus-bagliano / commits / 954a618375
Fork 0

gitweb: make leftmost column of blame less cluttered.

Instead of labelling each and every line with clickable commit object name, this makes the blame output to show them only on the first line of each group of lines from the same revision. Placing too many lines in one group would make the commit object name to appear too widely separated and also makes it consume more memory, the number of lines in one group is capped to 20 lines or so. Also it makes mouse-over to show the minimum authorship and authordate information for extra cuteness ;-). Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Oct 1, 2006 at 02:16 UTC 954a6183756a073723a7c9fd8d2feb13132876b0
1 file changed +86 -13
gitweb/gitweb.perl
+86 -13
@@ -2430,9 +2430,64 @@ sub git_tag {
2430 git_footer_html();
2431 }
2432
2433 +sub git_blame_flush_chunk {
2434 + my ($name, $revdata, $color, $rev, @line) = @_;
2435 + my $label = substr($rev, 0, 8);
2436 + my $line = scalar(@line);
2437 + my $cnt = 0;
2438 + my $pop = '';
2439 +
2440 + if ($revdata->{$rev} ne '') {
2441 + $pop = ' title="' . esc_html($revdata->{$rev}) . '"';
2442 + }
2443 +
2444 + for (@line) {
2445 + my ($lineno, $data) = @$_;
2446 + $cnt++;
2447 + print "<tr class=\"$color\">\n";
2448 + if ($cnt == 1) {
2449 + print "<td class=\"sha1\"$pop";
2450 + if ($line > 1) {
2451 + print " rowspan=\"$line\"";
2452 + }
2453 + print ">";
2454 + print $cgi->a({-href => href(action=>"commit",
2455 + hash=>$rev,
2456 + file_name=>$name)},
2457 + $label);
2458 + print "</td>\n";
2459 + }
2460 + print "<td class=\"linenr\">".
2461 + "<a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2462 + esc_html($lineno) . "</a></td>\n";
2463 + print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
2464 + print "</tr>\n";
2465 + }
2466 +}
2467 +
2468 +# We can have up to N*2 lines. If it is more than N lines, split it
2469 +# into two to avoid orphans.
2470 +sub git_blame_flush_chunk_1 {
2471 + my ($chunk_cap, $name, $revdata, $color, $rev, @chunk) = @_;
2472 + if ($chunk_cap < @chunk) {
2473 + my @first = splice(@chunk, 0, @chunk/2);
2474 + git_blame_flush_chunk($name,
2475 + $revdata,
2476 + $color,
2477 + $rev,
2478 + @first);
2479 + }
2480 + git_blame_flush_chunk($name,
2481 + $revdata,
2482 + $color,
2483 + $rev,
2484 + @chunk);
2485 +}
2486 +
2487 sub git_blame2 {
2488 my $fd;
2489 my $ftype;
2490 + my $chunk_cap = 20;
2491
2492 my ($have_blame) = gitweb_check_feature('blame');
2493 if (!$have_blame) {
@@ -2475,27 +2530,45 @@ sub git_blame2 {
2530 <table class="blame">
2531 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2532 HTML
2533 + my @chunk = ();
2534 + my %revdata = ();
2535 while (<$fd>) {
2536 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2480 - my $full_rev = $1;
2481 - my $rev = substr($full_rev, 0, 8);
2482 - my $lineno = $2;
2483 - my $data = $3;
2484 -
2537 + my ($full_rev, $author, $date, $lineno, $data) =
2538 + /^([0-9a-f]{40}).*?\s\((.*?)\s+([-\d]+ [:\d]+ [-+\d]+)\s+(\d+)\)\s(.*)/;
2539 + if (!exists $revdata{$full_rev}) {
2540 + $revdata{$full_rev} = "$author, $date";
2541 + }
2542 if (!defined $last_rev) {
2543 $last_rev = $full_rev;
2544 } elsif ($last_rev ne $full_rev) {
2545 + git_blame_flush_chunk_1($chunk_cap,
2546 + $file_name,
2547 + \%revdata,
2548 + $rev_color[$current_color],
2549 + $last_rev, @chunk);
2550 + @chunk = ();
2551 $last_rev = $full_rev;
2552 $current_color = ++$current_color % $num_colors;
2553 }
2491 - print "<tr class=\"$rev_color[$current_color]\">\n";
2492 - print "<td class=\"sha1\">" .
2493 - $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
2494 - esc_html($rev)) . "</td>\n";
2495 - print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2496 - esc_html($lineno) . "</a></td>\n";
2497 - print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
2498 - print "</tr>\n";
2554 + elsif ($chunk_cap * 2 < @chunk) {
2555 + # We have more than N*2 lines from the same
2556 + # revision. Flush N lines and leave N lines
2557 + # in @chunk to avoid orphaned lines.
2558 + my @first = splice(@chunk, 0, $chunk_cap);
2559 + git_blame_flush_chunk($file_name,
2560 + \%revdata,
2561 + $rev_color[$current_color],
2562 + $last_rev, @first);
2563 + }
2564 + push @chunk, [$lineno, $data];
2565 + }
2566 + if (@chunk) {
2567 + git_blame_flush_chunk_1($chunk_cap,
2568 + $file_name,
2569 + \%revdata,
2570 + $rev_color[$current_color],
2571 + $last_rev, @chunk);
2572 }
2573 print "</table>\n";
2574 print "</div>";