Skip to contentSkip to conversation

gitweb: 'blame' view improvements

PATCH Superseded Jakub Narebski 3 participants 11 messages Jun 15, 2016 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover gitweb: 'blame' view improvements

This patch series was inspired by the study before sending proposal for git-blame improvements; I have noticed that "previous"/"parent" blame header was already implemented, just not documented:
Subject: git-blame: Documenting "previous" header
Message-ID: <[email protected]>
http://thread.gmane.org/gmane.comp.version-control.git/122837

Therefore proposal got cut down to tree blame:
Subject: [RFC] Tree blame (git blame <directory>)
Message-ID: <[email protected]>
http://thread.gmane.org/gmane.comp.version-control.git/122830

Using "previous" header should improve gitweb performance and (as I have noticed during implementing it) allow to follow 'linenr' links correctly through rename in a blamed commit.

Marking "boundary" somewhat was required to make it possible to distinguish which 'linenr' links would lead to parent of a blame commit (to previous version of a file), and which would elad to blamed commit. Current styling is up to debate.

After implementing using "previous" header in 'blame' view (which would allow to do the same for proposed 'blame_incremental' view) I remembered that last version of implementing 'blame_incremental' added author initials a'la "git gui blame". So I did the same for non-incremental 'blame' view. Exact formatting is up to debate.

Table of contents:
==================
[PATCH 1/3] gitweb: Mark boundary commits in 'blame' view
[PATCH 2/3] gitweb: Use "previous" header of git-blame -p in 'blame' view [PATCH 3/3] gitweb: Add author initials in 'blame' view, a la "git gui blame"

Jakub Narebski (3):
gitweb: Mark boundary commits in 'blame' view
gitweb: Use "previous" header of git-blame -p in 'blame' view
gitweb: Add author initials in 'blame' view, a la "git gui blame"

 gitweb/gitweb.css  |    4 ++++
 gitweb/gitweb.perl |   51 ++++++++++++++++++++++++++++++++++++---------------
 2 files changed, 40 insertions(+), 15 deletions(-)
Signature · 2 lines
Jakub Narebski
Poland
#1 lore raw

PATCH 1/3 gitweb: Mark boundary commits in 'blame' view

Use "boundary" class to mark boundary commits, which currently results in using bold weight font for SHA-1 of a commit (to be more exact for all text in the cell that contains SHA-1 of a commit).

Detecting boundary commits is done by watching for "boundary" header in "git blame -p" output. Because this header doesn't carry additional data the regular expression for blame header fields had to be adjusted.

With current gitweb API only root (parentless) commits can be boundary commits.

---
Formatting (styling) of boundary commits is currently very minimal. I'd like to see what other possible solution would you like to have.

Bikeshedding open!

 gitweb/gitweb.css  |    4 ++++
 gitweb/gitweb.perl |    6 ++++--
 2 files changed, 8 insertions(+), 2 deletions(-)
gitweb/gitweb.css +4 -0
index d05bc37..5e2f629 100644
@@ -242,6 +242,10 @@ tr.dark:hover {
 	background-color: #edece6;
 }
 
+tr.boundary td.sha1 {
+	font-weight: bold;
+}
+
 td {
 	padding: 2px 5px;
 	font-size: 100%;
gitweb/gitweb.perl +4 -2
index 6a1b5b5..fe73c2c 100755
@@ -4826,7 +4826,7 @@ HTML
 		while ($data = <$fd>) {
 			chomp $data;
 			last if ($data =~ s/^\t//); # contents of line
-			if ($data =~ /^(\S+) (.*)$/) {
+			if ($data =~ /^(\S+)(?: (.*))?$/) {
 				$meta->{$1} = $2;
 			}
 		}
@@ -4838,7 +4838,9 @@ HTML
 		if ($group_size) {
 			$current_color = ($current_color + 1) % $num_colors;
 		}
-		print "<tr id=\"l$lineno\" class=\"$rev_color[$current_color]\">\n";
+		my $tr_class = $rev_color[$current_color];
+		$tr_class .= ' boundary' if (exists $meta->{'boundary'});
+		print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
 		if ($group_size) {
 			print "<td class=\"sha1\"";
 			print " title=\"". esc_html($author) . ", $date\"";
Signature · 1 line
1.6.3.3
#2 lore raw

PATCH 2/3 gitweb: Use "previous" header of git-blame -p in 'blame' view

In reply to Jakub Narebski

Luben Tuikov changed 'lineno' link (line number link) from pointing to 'blame' view at given line at blamed commit, to the one at parent of blamed commit in
244a70e (Blame "linenr" link jumps to previous state at

           "orig_lineno", 2007-01-04).

This made it possible to do data mining using 'blame' view, by going through history of a line using mentioned line number link.

Original implementation called "git rev-parse <commit>^" to find SHA-1 of a parent of a given commit once per each blamed line. In
39c19ce (gitweb: cache $parent_commit info in git_blame(),

           2008-12-11)

this was improved so rev-parse was called once per each unique commit in git-blame output. Alternate solution would be to relax validation for 'hb' parameter by allowing extended SHA-1 syntax of the form <rev>^ (perhaps redirecting to gitweb URL with <rev>^ resolved, in practice moving call to rev-parse to 'the other side of link').

This solution had a bug that it didn't work for boundary commits, which did not have parents, so "git rev-parse <commit>^" returned literal "<commit>^" (which didn't exists), which gitweb passed as 'hb' parameter in 'linenr' link... following which gave
400 - Invalid hash base parameter
error. This bug could have been fixed by checking if commit is boundary commit, or check if rev-parse result is unchanged (still ends in '^' prefix).

The solution employing rev-parse to find parent of commit had inherent problem if blamed commit renamed file; then name of file would be different in its parent. Solving this outside git-blame would be difficult and costly (at least cost of additional fork for extra git command).

Currently gitweb uses information in "previous" header, which was introduced by Junio C Hamano in
96e1170 (blame: show "previous" information in

           --porcelain/--incremental format, 2008-06-04)

This (currently undocumented) header has the following format:
"previous <sha1 of parent commit> <filename at parent>"
Using "previous" header solves both problem of performance and the problem that blamed commit could have renaming blamed file.

Because "previous" header can be repeated for the same commit when blamed commit is merge (has more than one parent), and we are interested usually in _first_ parent, currently we store only first value if blame header repeats. Using first parent (first "previous" line) was what gitweb did before; without this change gitweb would use last parent instead.

While at it introduce helper subroutine unquote_maybe(), which unquotes filename if it is needed, which is marked by filename being surrounded in doublequotes (which are not part of name, and which are stripped by unquote_maybe() - which makes this function idempotent). Currently unquote_maybe() us used only in git_blame.

If there is no previous commit 'linenr' link points to blamed commit and blamed filename, making it work correctly for boundary commits.

---

IMHO more important is that result is MORE CORRECT, not the better performance.

In the table below you can see simple benchmark comparing gitweb performance before and after this patch. Operating system used was Linux 2.6.14, on 1 GHz AMD Athlon processor (2002.43 BogoMIPS). As there is one "git rev-parse <rev>^" per each individual commit in blame output, it would be much worse 'before' for operating systems with costly fork.

File | C[1] || Time0[2] | Before[3] | After[3]
=================================================================

revision.c            |   121 ||   2.820s |    5.548s |   5.172s
gitweb/gitweb.perl[4] |   428 ||  11.749s |   19.797s |  17.293s

Table footnotes:
~~~~~~~~~~~~~~~~
[1] Individual commits in blame output:

    $ git blame -p <file> | grep author-time | wc -l
[2] Time for running "git blame -p" (user time, single run):
    $ time git blame -p <file> >/dev/null
[3] Time to run gitweb as Perl script from command line:
    $ time gitweb-run.sh "p=.git;a=blame;f=<file>" >/dev/null 2>&1
[4] Starting at 'origin', which is v1.6.3.3-412-gf581de1
Quoted 2 lines

git blame -p origin -- gitweb/gitweb.perl
"p=.git;a=blame;hb=origin;f=gitweb/gitweb.perl"

For comparison there is similar table for my 39c19ce (gitweb: cache $parent_commit info in git_blame(), 2008-12-11):

File | L[1] | C[2] || Time0[3] | Before[4] | After[4]
====================================================================

blob.h             |   18 |    4 || 0m1.727s |  0m2.545s |  0m2.474s
GIT-VERSION-GEN    |   42 |   13 || 0m2.165s |  0m2.448s |  0m2.071s
README             |   46 |    6 || 0m1.593s |  0m2.727s |  0m2.242s
revision.c         | 1923 |  121 || 0m2.357s | 0m30.365s |  0m7.028s
gitweb/gitweb.perl | 6291 |  428 || 0m8.080s | 1m37.244s | 0m20.627s

File | L/C | Before/After
=========================================

blob.h             |  4.5 |         1.03
GIT-VERSION-GEN    |  3.2 |         1.18
README             |  7.7 |         1.22
revision.c         | 15.9 |         4.32
gitweb/gitweb.perl | 14.7 |         4.71

As you can see the greater ratio of lines in file to unique commits in blame output, the greater gain from the new implementation.

Legend:

[1] Number of lines:

      $ wc -l <file>
  [2] Number of unique commits in the blame output:
      $ git blame -p <file> | grep author-time | wc -l
  [3] Time for running "git blame -p" (user time, single run):
      $ time git blame -p <file> >/dev/null
  [4] Time to run gitweb as Perl script from command line:
      $ gitweb-run.sh "p=.git;a=blame;f=<file>" > /dev/null 2>&1
 gitweb/gitweb.perl |   37 ++++++++++++++++++++++++-------------
 1 files changed, 24 insertions(+), 13 deletions(-)
gitweb/gitweb.perl +25 -14
index fe73c2c..36b1ce5 100755
@@ -1187,6 +1187,16 @@ sub unquote {
 	return $str;
 }
 
+# if filename is surrounded in double quotes, it need to be unquoted
+sub unquote_maybe {
+	my $str = shift;
+
+	if ($str =~ /^"(.*)"$/) {
+		return unquote($1);
+	}
+	return $str;
+}
+
 # escape tabs (convert tabs to spaces)
 sub untabify {
 	my $line = shift;
@@ -4827,7 +4837,7 @@ HTML
 			chomp $data;
 			last if ($data =~ s/^\t//); # contents of line
 			if ($data =~ /^(\S+)(?: (.*))?$/) {
-				$meta->{$1} = $2;
+				$meta->{$1} = $2 unless exists $meta->{$1};
 			}
 		}
 		my $short_rev = substr($full_rev, 0, 8);
@@ -4852,20 +4862,21 @@ HTML
 			              esc_html($short_rev));
 			print "</td>\n";
 		}
-		my $parent_commit;
-		if (!exists $meta->{'parent'}) {
-			open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^")
-				or die_error(500, "Open git-rev-parse failed");
-			$parent_commit = <$dd>;
-			close $dd;
-			chomp($parent_commit);
-			$meta->{'parent'} = $parent_commit;
-		} else {
-			$parent_commit = $meta->{'parent'};
-		}
+		# 'previous' <sha1 of parent commit> <filename at commit>
+		if (exists $meta->{'previous'} &&
+		    $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
+			$meta->{'parent'} = $1;
+			$meta->{'file_parent'} = unquote_maybe($2);
+		}
+		my $linenr_commit =
+			exists($meta->{'parent'}) ?
+			$meta->{'parent'} : $full_rev;
+		my $linenr_filename =
+			exists($meta->{'file_parent'}) ?
+			$meta->{'file_parent'} : unquote_maybe($meta->{'filename'});
 		my $blamed = href(action => 'blame',
-		                  file_name => $meta->{'filename'},
-		                  hash_base => $parent_commit);
+		                  file_name => $linenr_filename,
+		                  hash_base => $linenr_commit);
 		print "<td class=\"linenr\">";
 		print $cgi->a({ -href => "$blamed#l$orig_lineno",
 		                -class => "linenr" },
Signature · 1 line
1.6.3.3
#3 lore raw

Re: [PATCH 2/3] gitweb: Use "previous" header of git-blame -p in 'blame' view

Quoted 7 lines · Jakub Narebski

Luben Tuikov changed 'lineno' link (line number link) from pointing to 'blame' view at given line at blamed commit, to the one at parent of blamed commit in
244a70e (Blame "linenr" link jumps to previous state at

           "orig_lineno", 2007-01-04).

This made it possible to do data mining using 'blame' view, by going through history of a line using mentioned line number link.

I was playing with this feature the other day (and I think you can guess what I was writing when I was doing so as preparation). I was mildly annoyed that these links on the commit object names go to the commit view.

I think going to commitdiff view would make it far more useful while digging.

Suppose if you were somehow interested in the recent commit by Peff, "Makefile: install 'git' in execdir". You go to:

    http://repo.or.cz/w/alt-git.git

and look at commitdiff of the commit from the shortlog part.

You read the diff, understand what the changed Makefile does, but you get curious to see the blame. Nicely, the commitdiff view has a list of the files changed, and each entry in the list has "blame" link.

Clicking it would give you the blame on each line from the Makefile.

So far, very smooth experience. Then you scroll to an area of the file you are interested in, and click on one of the commits.

Oops.

It does not show the change of the commit made by this one, even though it does list Makefile in the list of files changed, and it has a blame link, the commit view without diff disrupts the thought process I had in the previous blame page, and I have to go to commitdiff to reorient myself.

#4 lore raw

Re: [PATCH 2/3] gitweb: Use "previous" header of git-blame -p in 'blame' view

Quoted 10 lines · Junio C Hamano
Quoted 7 lines · Jakub Narebski

Luben Tuikov changed 'lineno' link (line number link) from pointing to 'blame' view at given line at blamed commit, to the one at parent of blamed commit in
244a70e (Blame "linenr" link jumps to previous state at

           "orig_lineno", 2007-01-04).

This made it possible to do data mining using 'blame' view, by going through history of a line using mentioned line number link.

Quoted 6 lines

I was playing with this feature the other day (and I think you can guess what I was writing when I was doing so as preparation). I was mildly annoyed that these links on the commit object names go to the commit view.

I think going to commitdiff view would make it far more useful while digging.

[...]

Also with a slight extension of diff part of 'commitdiff', by adding line numbers for preimage in chunk and line numbers for postimage in chunk, like e.g. in 'commit' view on GitHub[1] or on Gitorious[2] or in SVN::Web[3] or in Atlassian FishEye, and adding anchors for those line numbers we could go to given line in dif/patch output and examine how it looked like before.

[1] http://github.com/jnareb/softsnow-xchat2-filter/commit/7b68fcd777f94534f0b794c5dc2e109c49938395
[2] http://gitorious.org/softsnow-xchat2-filter/mainline/commit/7b68fcd777f94534f0b794c5dc2e109c49938395
[3] http://jc.ngo.org.uk/svnweb/jc/diff/nik/CPAN/SVN-Web/trunk/README?revs=1283&revs=981

(This would probably require adding 'fmt' / 'format' parameter, where one could choose between possible ways to view diff, or possible ways to view log or log-like view.)

P.S. BTW. 'blame' view passes _original_ filename (not filename at blamed commit) to 'commit' view link... but it doesn't matter because 'commit' view does not use 'f'/$file_name parameter.

Signature · 2 lines
Jakub Narebski
Poland
#7 lore raw

PATCH 3/3 gitweb: Add author initials in 'blame' view, a la "git gui blame"

In reply to Jakub Narebski

For example for "Junio C Hamano" initials would be "JH". Of course initials are added (below shortened SHA-1 of blamed commit) only if group of lines has 2 lines or more in it.

---
Let the bikeshedding begin!

Should it be "JH" or perhaps "J.H." for "Junio C Hamano"? Or perhaps username part of author email would be better solution than initials? Should we use different style for those initials?

This patch was inspired by me adding the same feature in similar 'blame_incremental' view in
http://thread.gmane.org/gmane.comp.version-control.git/102657/focus=102712

 gitweb/gitweb.perl |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
gitweb/gitweb.perl +8 -0
index 36b1ce5..5336c92 100755
@@ -4860,6 +4860,14 @@ HTML
 			                             hash=>$full_rev,
 			                             file_name=>$file_name)},
 			              esc_html($short_rev));
+			if ($group_size >= 2) {
+				my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
+				if (@author_initials) {
+					print "<br />" .
+					      esc_html(join('', @author_initials));
+					#           or join('.', ...)
+				}
+			}
 			print "</td>\n";
 		}
 		# 'previous' <sha1 of parent commit> <filename at commit>
Signature · 1 line
1.6.3.3
#8 lore raw
In reply to Jakub Narebski
Quoted 6 lines · Jakub Narebski

Table of contents:
==================
 [PATCH 1/3] gitweb: Mark boundary commits in 'blame' view
 [PATCH 2/3] gitweb: Use "previous" header of git-blame -p in 'blame' view [PATCH 3/3] gitweb: Add author initials in 'blame' view, a la "git gui blame"

By the way I plan on submitting 'blame_incremental' view similar to the one in "[RFC/PATCH 4/3] gitweb: Incremental blame (proof of concept)"

http://thread.gmane.org/gmane.comp.version-control.git/102657/focus=102712

This time having the same (or nearly the same) features as ordinary 'blame' view.

Signature · 2 lines
Jakub Narebski
Poland
#5 lore raw

Re: [PATCH 2/3] gitweb: Use "previous" header of git-blame -p in 'blame' view

In reply to Jakub Narebski

gitweb/gitweb.perl sub unquote { · line 1198

Quoted 9 lines · Jakub Narebski
gitweb/gitweb.perl +9 -0
+# if filename is surrounded in double quotes, it need to be unquoted
+sub unquote_maybe {
+       my $str = shift;
+
+       if ($str =~ /^"(.*)"$/) {
+               return unquote($1);
+       }
+       return $str;
+}

I'm sorry about that, but this is totally unnecessary, as unquote == unquote_maybe (unquotes only when necessary).

Signature · 2 lines
Jakub Narebski
Poland
Acked-by on v1 2/3
#6 lore raw

Re: [PATCH 2/3] gitweb: Use "previous" header of git-blame -p in 'blame' view

In reply to Jakub Narebski

Junio, can you also verify that this patch doesn't alter behaviour in code data mining, before accepting it.

Thanks,
Luben

________________________________
From: Jakub Narebski <[email protected]>
To: [email protected]
Cc: Luben Tuikov <[email protected]>; Junio C Hamano <[email protected]>
Sent: Friday, July 10, 2009 2:57:42 PM
Subject: [PATCH 2/3] gitweb: Use "previous" header of git-blame -p in 'blame' view

Luben Tuikov changed 'lineno' link (line number link) from pointing to 'blame' view at given line at blamed commit, to the one at parent of blamed commit in
244a70e (Blame "linenr" link jumps to previous state at

           "orig_lineno", 2007-01-04).

This made it possible to do data mining using 'blame' view, by going through history of a line using mentioned line number link.

Original implementation called "git rev-parse <commit>^" to find SHA-1 of a parent of a given commit once per each blamed line. In
39c19ce (gitweb: cache $parent_commit info in git_blame(),

           2008-12-11)

this was improved so rev-parse was called once per each unique commit in git-blame output. Alternate solution would be to relax validation for 'hb' parameter by allowing extended SHA-1 syntax of the form <rev>^ (perhaps redirecting to gitweb URL with <rev>^ resolved, in practice moving call to rev-parse to 'the other side of link').

This solution had a bug that it didn't work for boundary commits, which did not have parents, so "git rev-parse <commit>^" returned literal "<commit>^" (which didn't exists), which gitweb passed as 'hb' parameter in 'linenr' link... following which gave
400 - Invalid hash base parameter
error. This bug could have been fixed by checking if commit is boundary commit, or check if rev-parse result is unchanged (still ends in '^' prefix).

The solution employing rev-parse to find parent of commit had inherent problem if blamed commit renamed file; then name of file would be different in its parent. Solving this outside git-blame would be difficult and costly (at least cost of additional fork for extra git command).

Currently gitweb uses information in "previous" header, which was introduced by Junio C Hamano in
96e1170 (blame: show "previous" information in

           --porcelain/--incremental format, 2008-06-04)

This (currently undocumented) header has the following format:
"previous <sha1 of parent commit> <filename at parent>"
Using "previous" header solves both problem of performance and the problem that blamed commit could have renaming blamed file.

Because "previous" header can be repeated for the same commit when blamed commit is merge (has more than one parent), and we are interested usually in _first_ parent, currently we store only first value if blame header repeats. Using first parent (first "previous" line) was what gitweb did before; without this change gitweb would use last parent instead.

While at it introduce helper subroutine unquote_maybe(), which unquotes filename if it is needed, which is marked by filename being surrounded in doublequotes (which are not part of name, and which are stripped by unquote_maybe() - which makes this function idempotent). Currently unquote_maybe() us used only in git_blame.

If there is no previous commit 'linenr' link points to blamed commit and blamed filename, making it work correctly for boundary commits.

---

IMHO more important is that result is MORE CORRECT, not the better performance.

In the table below you can see simple benchmark comparing gitweb performance before and after this patch. Operating system used was Linux 2.6.14, on 1 GHz AMD Athlon processor (2002.43 BogoMIPS). As there is one "git rev-parse <rev>^" per each individual commit in blame output, it would be much worse 'before' for operating systems with costly fork.

File | C[1] || Time0[2] | Before[3] | After[3]
=================================================================

revision.c            |   121 ||   2.820s |    5.548s |   5.172s
gitweb/gitweb.perl[4] |   428 ||  11.749s |   19.797s |  17.293s

Table footnotes:
~~~~~~~~~~~~~~~~
[1] Individual commits in blame output:

    $ git blame -p <file> | grep author-time | wc -l
[2] Time for running "git blame -p" (user time, single run):
    $ time git blame -p <file> >/dev/null
[3] Time to run gitweb as Perl script from command line:
    $ time gitweb-run.sh "p=.git;a=blame;f=<file>" >/dev/null 2>&1
[4] Starting at 'origin', which is v1.6.3.3-412-gf581de1
Quoted 2 lines

git blame -p origin -- gitweb/gitweb.perl
"p=.git;a=blame;hb=origin;f=gitweb/gitweb.perl"

For comparison there is similar table for my 39c19ce (gitweb: cache $parent_commit info in git_blame(), 2008-12-11):

File | L[1] | C[2] || Time0[3] | Before[4] | After[4]
====================================================================

blob.h             |   18 |    4 || 0m1.727s |  0m2.545s |  0m2.474s
GIT-VERSION-GEN    |   42 |   13 || 0m2.165s |  0m2.448s |  0m2.071s
README             |   46 |    6 || 0m1.593s |  0m2.727s |  0m2.242s
revision.c         | 1923 |  121 || 0m2.357s | 0m30.365s |  0m7.028s
gitweb/gitweb.perl | 6291 |  428 || 0m8.080s | 1m37.244s | 0m20.627s

File | L/C | Before/After
=========================================

blob.h             |  4.5 |         1.03
GIT-VERSION-GEN    |  3.2 |         1.18
README             |  7.7 |         1.22
revision.c         | 15.9 |         4.32
gitweb/gitweb.perl | 14.7 |         4.71

As you can see the greater ratio of lines in file to unique commits in blame output, the greater gain from the new implementation.

Legend:

[1] Number of lines:

      $ wc -l <file>
  [2] Number of unique commits in the blame output:
      $ git blame -p <file> | grep author-time | wc -l
  [3] Time for running "git blame -p" (user time, single run):
      $ time git blame -p <file> >/dev/null
  [4] Time to run gitweb as Perl script from command line:
      $ gitweb-run.sh "p=.git;a=blame;f=<file>" > /dev/null 2>&1

gitweb/gitweb.perl | 37 ++++++++++++++++++++++++-------------

1 files changed, 24 insertions(+), 13 deletions(-)
gitweb/gitweb.perl +0 -0
index fe73c2c..36b1ce5 100755
@@ -1187,6 +1187,16 @@ sub unquote {
    return $str;

}

+# if filename is surrounded in double quotes, it need to be unquoted +sub unquote_maybe {
+ my $str = shift;
+
+ if ($str =~ /^"(.*)"$/) {
+ return unquote($1);
+ }
+ return $str;
+}
+

# escape tabs (convert tabs to spaces)
sub untabify {
    my $line = shift;
@@ -4827,7 +4837,7 @@ HTML
            chomp $data;
            last if ($data =~ s/^\t//); # contents of line
            if ($data =~ /^(\S+)(?: (.*))?$/) {
-                $meta->{$1} = $2;
+                $meta->{$1} = $2 unless exists $meta->{$1};
            }
        }
        my $short_rev = substr($full_rev, 0, 8);
@@ -4852,20 +4862,21 @@ HTML
                          esc_html($short_rev));
            print "</td>\n";
        }
-        my $parent_commit;
-        if (!exists $meta->{'parent'}) {
-            open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^")
-                or die_error(500, "Open git-rev-parse failed");
-            $parent_commit = <$dd>;
-            close $dd;
-            chomp($parent_commit);
-            $meta->{'parent'} = $parent_commit;
-        } else {
-            $parent_commit = $meta->{'parent'};
-        }
+        # 'previous' <sha1 of parent commit> <filename at commit>
+        if (exists $meta->{'previous'} &&
+            $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
+            $meta->{'parent'} = $1;
+            $meta->{'file_parent'} = unquote_maybe($2);
+        }
+        my $linenr_commit =
+            exists($meta->{'parent'}) ?
+            $meta->{'parent'} : $full_rev;
+        my $linenr_filename =
+            exists($meta->{'file_parent'}) ?
+            $meta->{'file_parent'} : unquote_maybe($meta->{'filename'});
        my $blamed = href(action => 'blame',
-                          file_name => $meta->{'filename'},
-                          hash_base => $parent_commit);
+                          file_name => $linenr_filename,
+                          hash_base => $linenr_commit);
        print "<td class=\"linenr\">";
        print $cgi->a({ -href => "$blamed#l$orig_lineno",
                        -class => "linenr" },
Signature · 1 line
1.6.3.3
#9 lore raw

[RFC PATCH 5/3] gitweb: Incremental blame (proof of concept)

In reply to Jakub Narebski

This is tweaked up further version of Petr Baudis <[email protected]> patch, which was tweaked up version of Fredrik Kuivinen <[email protected]>'s proof of concept patch. It adds 'blame_incremental' view, which incrementally displays line data in blame view using JavaScript (AJAX).

This patch does not (contrary to the one by Petr Baudis) enable this view in gitweb: there are no links leading to 'blame_incremental' action. You would have to generate URL 'by hand' (e.g. changing 'blame' or 'blob' in gitweb URL to 'blame_incremental'). Having links in gitweb lead to this new action (e.g. by rewriting them like in previous patch), if JavaScript is enabled in browser, is left for later.

Like earlier patch by Petr Baudis it avoids code duplication, but it goes one step further and use git_blame_common for ordinary blame view, for incremental blame, and (which is change from previous patch) for incremental blame data.

How the 'blame_incremental' view works:
* gitweb generates initial info by putting file contents (from git-cat-file) together with line numbers in blame table
* then gitweb makes web browser JavaScript engine call startBlame() function from blame.js
* startBlame() opens connection to 'blame_data' view, which in turn calls "git blame --incremental" for a file, and streams output of git-blame to JavaScript (blame.js)
* blame.js updates line info in blame view, coloring it, and updating progress info; note that it has to use 3 colors to ensure that different neighbour groups have different styles
* when 'blame_data' ends, and blame.js finishes updating line info, it fixes colors to match (as far as possible) ordinary 'blame' view, and updates generating time info.

It deals with streamed 'blame_data' server error by notifying about them in the progress info area (just in case).

Differences between 'blame_incremental' and original 'blame' view:
* 'blame_incremental' always used (partial) query form for links generated by JavaScript. The difference is visible if we use path_info link (pass some or all arguments in path_info), e.g. in 'blame' view called using:
http://git.example.com/w/git.git/blame/HEAD:/README
we have 'linenr' links using the same form:

    http://git.example.com/w/git.git/blame/e83c5163316f89bfbde7d9ab23ca2e25604af290:/README#l4
  while in 'blame_incremental' view called with:
    http://git.example.com/w/git.git/blame_incremental/HEAD:/README
  we have "partial query" form
    http://git.example.com/w/git.git?;a=blame_incremental;hb=e83c5163316f89bfbde7d9ab23ca2e25604af290;f=README#l4

Changing this would require implementing something akin to href() subroutine in JavaScript
* 'blame_incremental' always uses "rowspan" attribute, even if rowspan="1". This simplifies code, and is not visible to user.
+ sometimes 'blame_incremental' and corresponding 'blame' view show different widths for "Line" column. I don't know what is the case of this; it might be even bug in web browser I use.

This patch adds GITWEB_BLAMEJS compile configuration option, and modifies git-instaweb.sh to take blame.js into account, but it does not update gitweb/README file (as it is only proof of concept patch). The code for git-instaweb.sh was taken from Pasky's patch.

This patch also adds showing time (in seconds) it took to generate a page in page footer (based on example code by Pasky), even though it is independent change, to be able to evaluate incremental blame in gitweb better. In proper patch series it would be independent commit; and it probably would provide fallback if Time::HiRes is not available (by e.g. not showing generating time info), even though this is unlikely.

Some benchmarks:
^^^^^^^^^^^^^^^^
Web server (Apache + mod_cgi) and web browser (Mozilla 1.17.2) both are running on the same single core single CPU computer (AMD Athlon)

File | 'blame'[1] | 'blame_incremental'[2]
================================================================

blob.h             |     3.838s | 0.525s +  (3.227s /   4.019s)
GIT-VERSION-GEN    |     4.869s | 0.469s +  (4.359s /   5.134s)
README             |     6.564s | 0.581s +  (4.445s /   5.253s)
revision.c         |    27.817s | 4.562s + (13.619s /  38.307s)
gitweb/gitweb.perl |    81.495s | 9.922s + (50.761s / 242.591s)

Footnotes:
~~~~~~~~~~
[1] Total wall-clock time as returned by gitweb in the page footer.
[2] XXs + (XXs server blame_data / XXs client JavaScript).

---
Refrences:
1. Original patch by Frederik Kuivinen
http://article.gmane.org/gmane.comp.version-control.git/41361
2. Tweaked up version by Petr Baudis
http://article.gmane.org/gmane.comp.version-control.git/56657
3. First and second version by me
http://thread.gmane.org/gmane.comp.version-control.git/102657/focus=102712

Adding 'generated in XXX seconds' is based on snipped by Petr Baudis:
http://article.gmane.org/gmane.comp.version-control.git/83306

REQUEST: Please, if possible, test if 'blame_incremental' works correctly (without errors in JavaScript console or equivalent) in other browsers than my old Mozilla 1.17.2 (Gecko / Rhino). I'd like to have test for:
* Firefox 2.0, 3.0 and 3.5
* Internet Explorer 7 and 8 (perhaps also IE6)
* Safari (and other WebKit based browsers)
* Konqueror
* Opera
* Google Chrome

Changes compared to the last version:
* Perl code (gitweb.perl) updated to latest version, which uses information from "previous" header in "git blame -p" output, and which can deal with boundary commits. JavaScript code was updated to do the same. This change made 'linenr' links lead to equivalent views, contrary to previous version.
* JavaScript code (blame.js) uses now the same date format as 'blame' view in Perl code (gitweb.perl), i.e. "2005-08-07 21:49:46 +0200" where time is in localtime of given timezone.
* JavaScript code (blame.js) got cleaned up and reordered; more comments were added, some variables and functions have slightly different names, some code got factored out into separate functions, we use switch/case instead of ling if-else-if chain.

TODO list:
* While blame.js should now deal with filenames containing characters special to URI like '?', '%' or ';' thanks to use of encodeURIComponent(), it doesn't yet do unquoting of space quoted filenames, so it won't work correctly for filenames e.g. containing space, tab or quote character.
* handleResponse is used both as onreadystatechange and pollTimer; if onreadystatechange works for partial responses we can turn off the timer. It is protected from concurrent running by global inProgress variable; we could instead pass XMLHttpResponse object as a parameter (see comment in startBlame).
* Probably 'blame_data' should use multipart/x-mixed-replace as content type, instead of (in addition to?) text/plain. I am not sure about that; I am not knowledgeable in AJAX and Comet.
* Remove timing code, or move it to separate commit, and make it optional / configurable (we probably don't want to show such info on site open to wide public).
* Move td.error -> .error to separate commit. td.error is remain from old git-annotate based git_blame; 'blame_interactive' uses span.warning to notify about errors (like e.g. JavaScript turned off for 'blame_incremental' view).
* Remove or move to separate commit changes which help CPerl mode for GNU Emacs to deal with syntax highlighting (#', #").

A few questions about this patch:
* Should progress info be removed after 'blame_data' finishes?
* Should 3-coloring of blame in progress be removed, or perhaps just put in a separate patch for better reviewability (and better bisectability)?
* Should debug statements (conditional on DEBUG global variable) be removed from source? There is separate mechanism to inform user about errors.
* Should we use <element>.className = <value> instead of DOM Core <element>.setAttribute('class', <value>)? What about getter?
* Should we convert some regexps to string manipulation (e.g. split)? What is better for JavaScript performance?

Questions for the future:
* Should we split JavaScript scripts into separate files, e.g. one with common utilities (gitweb.js), and one dealing specifically with 'blame_incremental' view (gitweb-blame.js)? How to configure it (some scripts might be loaded in page header, some at the end of page to not block progressive loading)?

* Should we use some light-weight JavaScript framework (perhaps loaded from Google[1]), instead of / in addition to handcrafted JavaScript (as fallback)[2]? What framework to use: jQuery, Prototype, YUI? CGI::Ajax?

[1] http://www.google.com/jsapi and google.load, or something
[2] http://stackoverflow.com/questions/1014203/best-way-to-use-googles-hosted-jquery-but-fall-back-to-my-hosted-library-on-goo

* Perhaps 'blame_data' should pre-process data from git-blame to reduce amount of work JavaScript has to do, and e.g. pre-parse data and transform to JSON / JSONP?

* To reduce size of JavaScript file user has to download to use 'blame_incremental' view, while keeping clean and easy to modify original code, perhaps we could run some JavaScript minimizing tool when building gitweb, something like Douglas Crockford's JSMin[3] (if the tool is available during install / build)?

[3] http://www.crockford.com/javascript/jsmin.html

* Should we use JSDoc comments? But no other parts of code use similar structured comments (Doxygen, ROBODoc, Natural Docs)...

 Makefile           |    6 +-
 git-instaweb.sh    |    7 +
 gitweb/blame.js    |  561 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 gitweb/gitweb.css  |   21 ++-
 gitweb/gitweb.perl |  286 ++++++++++++++++++---------
 5 files changed, 788 insertions(+), 93 deletions(-)
 create mode 100644 gitweb/blame.js
Makefile +5 -1
index bde27ed..95b577c 100644
@@ -265,6 +265,7 @@ GITWEB_HOMETEXT = indextext.html
 GITWEB_CSS = gitweb.css
 GITWEB_LOGO = git-logo.png
 GITWEB_FAVICON = git-favicon.png
+GITWEB_BLAMEJS = blame.js
 GITWEB_SITE_HEADER =
 GITWEB_SITE_FOOTER =
 
@@ -1406,13 +1407,14 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl
 	    -e 's|++GITWEB_CSS++|$(GITWEB_CSS)|g' \
 	    -e 's|++GITWEB_LOGO++|$(GITWEB_LOGO)|g' \
 	    -e 's|++GITWEB_FAVICON++|$(GITWEB_FAVICON)|g' \
+	    -e 's|++GITWEB_BLAMEJS++|$(GITWEB_BLAMEJS)|g' \
 	    -e 's|++GITWEB_SITE_HEADER++|$(GITWEB_SITE_HEADER)|g' \
 	    -e 's|++GITWEB_SITE_FOOTER++|$(GITWEB_SITE_FOOTER)|g' \
 	    $< >$@+ && \
 	chmod +x $@+ && \
 	mv $@+ $@
 
-git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css
+git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css gitweb/blame.js
 	$(QUIET_GEN)$(RM) $@ $@+ && \
 	sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
 	    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
@@ -1421,6 +1423,8 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css
 	    -e '/@@GITWEB_CGI@@/d' \
 	    -e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \
 	    -e '/@@GITWEB_CSS@@/d' \
+	    -e '/@@GITWEB_BLAMEJS@@/r gitweb/blame.js' \
+	    -e '/@@GITWEB_BLAMEJS@@/d' \
 	    -e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
 	    [email protected] > $@+ && \
 	chmod +x $@+ && \
git-instaweb.sh +7 -0
index 5f4419b..fd6341a 100755
@@ -331,8 +331,15 @@ gitweb_css () {
 EOFGITWEB
 }
 
+gitweb_blamejs () {
+	cat > "$1" <<\EOFGITWEB
+@@GITWEB_BLAMEJS@@
+EOFGITWEB
+}
+
 gitweb_cgi "$GIT_DIR/gitweb/gitweb.cgi"
 gitweb_css "$GIT_DIR/gitweb/gitweb.css"
+gitweb_blamejs "$GIT_DIR/gitweb/blame.js"
 
 case "$httpd" in
 *lighttpd*)
gitweb/blame.js new file +561 -0

561 lines not on this page · raw message

gitweb/gitweb.css +20 -1
index 4e4f8aa..ac9033f 100644
@@ -248,6 +248,14 @@ tr.boundary td.sha1 {
 	font-weight: bold;
 }
 
+tr.color1:hover { background-color: #e6ede6; }
+tr.color2:hover { background-color: #e6e6ed; }
+tr.color3:hover { background-color: #ede6e6; }
+
+tr.color1 { background-color: #f6fff6; }
+tr.color2 { background-color: #f6f6ff; }
+tr.color3 { background-color: #fff6f6; }
+
 td {
 	padding: 2px 5px;
 	font-size: 100%;
@@ -268,7 +276,7 @@ td.sha1 {
 	font-family: monospace;
 }
 
-td.error {
+.error {
 	color: red;
 	background-color: yellow;
 }
@@ -339,6 +347,17 @@ td.mode {
 	font-family: monospace;
 }
 
+/* progress of blame_interactive */
+div#progress_bar {
+	height: 2px;
+	margin-bottom: -2px;
+	background-color: #d8d9d0;
+}
+div#progress_info {
+	float: right;
+	text-align: right;
+}
+
 /* styling of diffs (patchsets): commitdiff and blobdiff views */
 div.diff.header,
 div.diff.extended_header {
gitweb/gitweb.perl +196 -92

375 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#10 lore raw

[PATCH 4/3] gitweb: Use light/dark class also in 'blame' view

In reply to Jakub Narebski

Instead of using "light2" and "dark2" for class names in 'blame' view (in place of "light" and "dark" classes in other places) to avoid changing style on hover in 'blame' view while doing it for other views (like 'shortlog'), use more advanced CSS, relying on the fact that more specific selector wins.

While at it add a few comments to gitweb CSS file, and consolidate some repeated info.

---
This is an RFC because

1. I am not sure if I did it correctly. I had to fiddle a bit with CSS (using "table.blame .light:hover" in place of "table.blame tr.light:hover") to get the same behaviour (well, the same as far as I have checked it).

2. Commit message could use improvements (single sentence, blergh).

 gitweb/gitweb.css  |   16 +++++++++-------
 gitweb/gitweb.perl |    2 +-
 2 files changed, 10 insertions(+), 8 deletions(-)
gitweb/gitweb.css +9 -7
index 5e2f629..4e4f8aa 100644
@@ -226,22 +226,24 @@ th {
 	text-align: left;
 }
 
-tr.light:hover {
-	background-color: #edece6;
-}
-
-tr.dark {
-	background-color: #f6f6f0;
+/* do not change row style on hover for 'blame' view */
+tr.light,
+table.blame .light:hover {
+	background-color: #ffffff;
 }
 
-tr.dark2 {
+tr.dark,
+table.blame .dark:hover {
 	background-color: #f6f6f0;
 }
 
+/* currently both use the same, but it can change */
+tr.light:hover,
 tr.dark:hover {
 	background-color: #edece6;
 }
 
+/* boundary commits in 'blame' view */
 tr.boundary td.sha1 {
 	font-weight: bold;
 }
gitweb/gitweb.perl +1 -1
index 5336c92..bb7a5a9 100755
@@ -4811,7 +4811,7 @@ sub git_blame {
 	git_print_page_path($file_name, $ftype, $hash_base);
 
 	# page body
-	my @rev_color = qw(light2 dark2);
+	my @rev_color = qw(light dark);
 	my $num_colors = scalar(@rev_color);
 	my $current_color = 0;
 	my %metainfo = ();
Signature · 1 line
1.6.3.3