]> Lady’s Gitweb - Gitweb/commitdiff
gitweb: extend blame to show links to diff and previous
authorLuben Tuikov <redacted>
Tue, 26 Sep 2006 23:45:31 +0000 (16:45 -0700)
committerLady <redacted>
Mon, 6 Apr 2026 04:07:10 +0000 (00:07 -0400)
git_blame2() now has two more columns, "Prev" and "Diff",
before the "Commit" column, as follows:

Prev Diff Commit Line Data
SHA     Diff    SHA        N    ...
...

The "Prev" column shows the SHA of the parent commit,
between which this line changed.  Clicking on it shows the
blame of the file as of the parent commit, for that line.

So clicking repeatedly on "Prev" would show you the blame
of that file, from the point of view of the changes
of that particular line whose "Prev" you're clicking on.

The "Diff" column shows "Diff" which is a link to blobdiff
between "Prev" and "Commit" commits _for that line_.

So clicking on "Diff" would show you the blobdiff (HTML)
between the parent commit and this commit which changed
that particular line.

Signed-off-by: Luben Tuikov <redacted>
Signed-off-by: Junio C Hamano <redacted>
gitweb.perl

index a4f13bbfd52a3440b125758b3c32040c117d5fdb3650ca4bb659da07d799a370..932f15eb459a08b4730f27c89ac650bd07c48baa71444e4bfb92d7e424376631 100755 (executable)
@@ -2439,7 +2439,7 @@ sub git_blame2 {
        print <<HTML;
 <div class="page_body">
 <table class="blame">
        print <<HTML;
 <div class="page_body">
 <table class="blame">
-<tr><th>Commit</th><th>Line</th><th>Data</th></tr>
+<tr><th>Prev</th><th>Diff</th><th>Commit</th><th>Line</th><th>Data</th></tr>
 HTML
        while (<$fd>) {
                /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
 HTML
        while (<$fd>) {
                /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
@@ -2447,6 +2447,8 @@ HTML
                my $rev = substr($full_rev, 0, 8);
                my $lineno = $2;
                my $data = $3;
                my $rev = substr($full_rev, 0, 8);
                my $lineno = $2;
                my $data = $3;
+               my %pco = parse_commit($full_rev);
+               my $parent = $pco{'parent'};
 
                if (!defined $last_rev) {
                        $last_rev = $full_rev;
 
                if (!defined $last_rev) {
                        $last_rev = $full_rev;
@@ -2455,11 +2457,25 @@ HTML
                        $current_color = ++$current_color % $num_colors;
                }
                print "<tr class=\"$rev_color[$current_color]\">\n";
                        $current_color = ++$current_color % $num_colors;
                }
                print "<tr class=\"$rev_color[$current_color]\">\n";
+               # Print the Prev link
+               print "<td class=\"sha1\">";
+               print $cgi->a({-href => href(action=>"blame", hash_base=>$parent, file_name=>$file_name)},
+                             esc_html(substr($parent, 0, 8)));
+               print "</td>\n";
+               # Print the Diff (blobdiff) link
+               print "<td>";
+               print $cgi->a({-href => href(action=>"blobdiff", file_name=>$file_name, hash_parent_base=>$parent,
+                                            hash_base=>$full_rev)},
+                             esc_html("Diff"));
+               print "</td>\n";
+               # Print the Commit link
                print "<td class=\"sha1\">" .
                        $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
                                esc_html($rev)) . "</td>\n";
                print "<td class=\"sha1\">" .
                        $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
                                esc_html($rev)) . "</td>\n";
+               # Print the Line number
                print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
                      esc_html($lineno) . "</a></td>\n";
                print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
                      esc_html($lineno) . "</a></td>\n";
+               # Print the Data
                print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
                print "</tr>\n";
        }
                print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
                print "</tr>\n";
        }
This page took 0.325783 seconds and 4 git commands to generate.