gitweb: use blame --porcelain
This makes gitweb (git_blame2) use "blame --porcelain", which lets the caller to figure out which line in the original version each line comes from. Using this information, change the behaviour of clicking the line number to go to the line of the blame output for the original commit. Before, clicking the line number meant "scoll up to show this line at the beginning of the page", which was not all that useful. The new behaviour lets you click on the line you are interested in to view the line in the context it was introduced, and keep digging deeper as you examine it. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Oct 5, 2006 at 13:55 UTC
eeef88cd20f2965325cde66e97a616bce4a757f0
1 file changed
+44
-21
gitweb/gitweb.perl
+44
-21
@@ -974,6 +974,9 @@ sub parse_date {
974
$date{'hour_local'} = $hour;
975
$date{'minute_local'} = $min;
976
$date{'tz_local'} = $tz;
977
+ $date{'iso-tz'} = sprintf ("%04d-%02d-%02d %02d:%02d:%02d %s",
978
+ 1900+$year, $mon+1, $mday,
979
+ $hour, $min, $sec, $tz);
980
return %date;
981
}
982
@@ -2501,7 +2504,8 @@ sub git_blame2 {
2504
if ($ftype !~ "blob") {
2505
die_error("400 Bad Request", "Object is not a blob");
2506
}
2504
- open ($fd, "-|", git_cmd(), "blame", '-l', '--', $file_name, $hash_base)
2507
+ open ($fd, "-|", git_cmd(), "blame", '--porcelain', '--',
2508
+ $file_name, $hash_base)
2509
or die_error(undef, "Open git-blame failed");
2510
git_header_html();
2511
my $formats_nav =
@@ -2525,33 +2529,52 @@ sub git_blame2 {
2529
<table class="blame">
2530
<tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2531
HTML
2528
- while (<$fd>) {
2529
- my ($full_rev, $author, $date, $lineno, $data) =
2530
- /^([0-9a-f]{40}).*?\s\((.*?)\s+([-\d]+ [:\d]+ [-+\d]+)\s+(\d+)\)\s(.*)/;
2532
+ my %metainfo = ();
2533
+ while (1) {
2534
+ $_ = <$fd>;
2535
+ last unless defined $_;
2536
+ my ($full_rev, $lineno, $orig_lineno, $group_size) =
2537
+ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2538
+ if (!exists $metainfo{$full_rev}) {
2539
+ $metainfo{$full_rev} = {};
2540
+ }
2541
+ my $meta = $metainfo{$full_rev};
2542
+ while (<$fd>) {
2543
+ last if (s/^\t//);
2544
+ if (/^(\S+) (.*)$/) {
2545
+ $meta->{$1} = $2;
2546
+ }
2547
+ }
2548
+ my $data = $_;
2549
my $rev = substr($full_rev, 0, 8);
2532
- my $print_c8 = 0;
2533
-
2534
- if (!defined $last_rev) {
2535
- $last_rev = $full_rev;
2536
- $print_c8 = 1;
2537
- } elsif ($last_rev ne $full_rev) {
2538
- $last_rev = $full_rev;
2550
+ my $author = $meta->{'author'};
2551
+ my %date = parse_date($meta->{'author-time'},
2552
+ $meta->{'author-tz'});
2553
+ my $date = $date{'iso-tz'};
2554
+ if ($group_size) {
2555
$current_color = ++$current_color % $num_colors;
2540
- $print_c8 = 1;
2556
}
2557
print "<tr class=\"$rev_color[$current_color]\">\n";
2543
- print "<td class=\"sha1\"";
2544
- if ($print_c8 == 1) {
2558
+ if ($group_size) {
2559
+ print "<td class=\"sha1\"";
2560
print " title=\"$author, $date\"";
2546
- }
2547
- print ">";
2548
- if ($print_c8 == 1) {
2549
- print $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
2561
+ print " rowspan=\"$group_size\"" if ($group_size > 1);
2562
+ print ">";
2563
+ print $cgi->a({-href => href(action=>"commit",
2564
+ hash=>$full_rev,
2565
+ file_name=>$file_name)},
2566
esc_html($rev));
2567
+ print "</td>\n";
2568
}
2552
- print "</td>\n";
2553
- print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2554
- esc_html($lineno) . "</a></td>\n";
2569
+ my $blamed = href(action => 'blame',
2570
+ file_name => $meta->{'filename'},
2571
+ hash_base => $full_rev);
2572
+ print "<td class=\"linenr\">";
2573
+ print $cgi->a({ -href => "$blamed#l$orig_lineno",
2574
+ -id => "l$lineno",
2575
+ -class => "linenr" },
2576
+ esc_html($lineno));
2577
+ print "</td>";
2578
print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
2579
print "</tr>\n";
2580
}