git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] [gitweb] Blame "linenr" link jumps to previous state at "orig_lineno"

From
LTLuben Tuikov <ltuikov@yahoo.com>
Date
Jan 5, 2007, 02:37 UTC
Message-ID
<605150.6351.qm@web31807.mail.mud.yahoo.com>

Blame currently displays the commit id which introduced a block of one or more lines, the line numbers wrt the current listing of the file and the file's line contents.

The commit id displayed is hyperlinked to the commit.

Currently the linenr links are hyperlinked to the same commit id displayed to the left, which is _no_ different than the block of lines displayed, since it is the _same commit_ that is hyperlinked. And thus clicking on it leads to the same state of the file for that chunk of lines. I.e. data mining is not currently possible with gitweb given a chunk of lines introduced by a commit.

This patch makes such data mining possible.

The line numbers are now hyperlinked to the parent of the commit id of the block of lines. Furthermore they are linked to the line where that block was introduced.

Thus clicking on a linenr link will show you the file's line(s) state prior to the commit id you were viewing.

So clicking continually on a linenr link shows you how this line and its line number changed over time, leading to the initial commit where it was first introduced.

Signed-off-by: Luben Tuikov <ltuikov@yahoo.com>
---
 gitweb/gitweb.perl |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

A quick show-and-tell of this patch is after applying it, open "blame" on a file, click on a linenr link of a block which has only a single line changed -- the diff between what you're seeing now and before is at least that line. This you can data-mine with gitweb back to where the line was introduced. Similar argument applies to blocks of more than one line.

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index ac602ae..c87c61d 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3208,9 +3208,14 @@ HTML
 				      esc_html($rev));
 			print "</td>\n";
 		}
+		open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^")
+			or die_error("could not open git-rev-parse");
+		my $parent_commit = <$dd>;
+		close $dd;
+		chomp($parent_commit);
 		my $blamed = href(action => 'blame',
 				  file_name => $meta->{'filename'},
-				  hash_base => $full_rev);
+				  hash_base => $parent_commit);
 		print "<td class=\"linenr\">";
 		print $cgi->a({ -href => "$blamed#l$orig_lineno",
 				-id => "l$lineno",
-- 
1.5.0.rc0.g90e5
Next: Junio C Hamano
Message 1 of 3 in “[gitweb] Blame "linenr" link jumps to previous state at "orig_lineno"”
  1. [gitweb] Blame "linenr" link jumps to previous state at "orig_lineno"Luben Tuikov, Jan 5, 2007
  2. Junio C HamanoJan 5, 2007
  3. Luben TuikovJan 5, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.