Skip to contentSkip to conversation

gitweb: Incremental blame series (1 Sep 09)

PATCH In review Jakub Narebski 3 participants 12 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

cover gitweb: Incremental blame series (1 Sep 09)

This series is meant to replace the 'jn/gitweb-blame' topic branch (it is merged into 'pu', b08ae28).

Jakub Narebski (5):
gitweb: Add optional "time to generate page" info in footer
gitweb: Incremental blame (using JavaScript)
gitweb: Colorize 'blame_incremental' view during processing
gitweb: Create links leading to 'blame_incremental' using JavaScript
gitweb: Minify gitweb.js if JSMIN is defined

The "time to generate page" info got its own style, and don't looks bolted on now. Incremental blame patch is no longer marked as proof of concept, or as a work in progress; I think it is mature enough.

Last two patches (creating links and JSMIN) are in active development, and should be considered work in progress (or even proof of concept code).

This series has 3-color colorizing of 'blame_incremental' view is put into separate patch. JavaScript code used to create links leading to 'blame_incremental' view is now put in gitweb.js, which is meant to contain all JavaScript code used by Git.

The last patch (modifying Makefile) was added because of concern that heavily commented gitweb.js could be a burden on server.

 Makefile           |   26 ++-
 git-instaweb.sh    |    7 +
 gitweb/README      |    4 +
 gitweb/gitweb.css  |   23 ++
 gitweb/gitweb.js   |  862 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 gitweb/gitweb.perl |  311 ++++++++++++++------
 6 files changed, 1146 insertions(+), 87 deletions(-)
 create mode 100644 gitweb/gitweb.js
Signature · 2 lines
Jakub Narebski
Poland
#1 lore raw

PATCH v2 1/5 gitweb: Add optional "time to generate page" info in footer

Add "This page took XXX seconds and Y git commands to generate" to page footer, if global feature 'timed' is enabled (disabled by default). Requires Time::HiRes installed for high precision 'wallclock' time.

Note that Time::HiRes is being required unconditionally of 'timed' feature, because setting $t0 variable should be fairly early to have running time of the whole script. If Time::HiRes module was required only if 'timed' feature is enabled, the earliest place where starting time ($t0) could be calculated would be after reading gitweb config, making "time to generate page" info inaccurate.

This code is based on example code by Petr 'Pasky' Baudis.

---
This version adds custom formatting for "time to generate page" information in the page footer, instead of reusing 'page_footer' style. It is now clearly separated from the gitweb footer proper.

While at it the ids were changed from "generate_info" etc. to "generating_info" etc.

There is still a question whether Time::HiRes should be require'd unconditionally, but otherwise this patch is out of RFC stage.

Sidenote: I have noticed that gitweb's CSS rules are unnecessary strict, making rendering slower because of extra non needed checks (the rule is that selectors should be as simple as possible).

 gitweb/gitweb.css  |    7 +++++++
 gitweb/gitweb.perl |   29 +++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)
gitweb/gitweb.css +7 -0
index b59fcaf..00e2e4c 100644
@@ -75,6 +75,13 @@ div.page_footer_text {
 	font-style: italic;
 }
 
+div#generating_info {
+	margin: 4px;
+	font-size: smaller;
+	text-align: center;
+	color: #505050;
+}
+
 div.page_body {
 	padding: 8px;
 	font-family: monospace;
gitweb/gitweb.perl +29 -0
index ff2d42a..08d410d 100755
@@ -18,6 +18,12 @@ use File::Find qw();
 use File::Basename qw(basename);
 binmode STDOUT, ':utf8';
 
+our $t0;
+if (eval { require Time::HiRes; 1; }) {
+	$t0 = [Time::HiRes::gettimeofday()];
+}
+our $number_of_git_cmds = 0;
+
 BEGIN {
 	CGI->compile() if $ENV{'MOD_PERL'};
 }
@@ -404,6 +410,13 @@ our %feature = (
 		'sub' => \&feature_avatar,
 		'override' => 0,
 		'default' => ['']},
+
+	# Enable displaying how much time and how many git commands
+	# it took to generate and display page.  Disabled by default.
+	# Project specific override is not supported.
+	'timed' => {
+		'override' => 0,
+		'default' => [0]},
 );
 
 sub gitweb_get_feature {
@@ -518,6 +531,7 @@ if (-e $GITWEB_CONFIG) {
 
 # version of the core git binary
 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
+$number_of_git_cmds++;
 
 $projects_list ||= $projectroot;
 
@@ -1969,6 +1983,7 @@ sub get_feed_info {
 
 # returns path to the core git executable and the --git-dir parameter as list
 sub git_cmd {
+	$number_of_git_cmds++;
 	return $GIT, '--git-dir='.$git_dir;
 }
 
@@ -3218,6 +3233,20 @@ sub git_footer_html {
 	}
 	print "</div>\n"; # class="page_footer"
 
+	if (defined $t0 && gitweb_check_feature('timed')) {
+		print "<div id=\"generating_info\">\n";
+		print 'This page took '.
+		      '<span id="generating_time" class="time_span">'.
+		      Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).
+		      ' seconds </span>'.
+		      ' and '.
+		      '<span id="generating_cmd">'.
+		      $number_of_git_cmds.
+		      '</span> git commands '.
+		      " to generate.\n";
+		print "</div>\n"; # class="page_footer"
+	}
+
 	if (-f $site_footer) {
 		insert_file($site_footer);
 	}
Signature · 1 line
1.6.3.3
#2 lore raw

PATCH v5 2/5 gitweb: Incremental blame (using JavaScript)

Add 'blame_incremental' view, which uses "git blame --incremental" and JavaScript (Ajax), where 'blame' use "git blame --porcelain".

* 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 gitweb.js
* startBlame() opens XMLHttpRequest connection to 'blame_data' view, which in turn calls "git blame --incremental" for a file, and streams output of git-blame to JavaScript (gitweb.js)
* XMLHttpRequest event handler updates line info in blame view as soon as it gets data from 'blame_data' (from server), and it also updates progress info
* when 'blame_data' ends, and gitweb.js finishes updating line info, it fixes colors to match (as far as possible) ordinary 'blame' view, and updates information about how long it took to generate page.

Gitweb deals with streamed 'blame_data' server errors by displaying them in the progress info area (just in case).

The 'blame_incremental' view tries to be equivalent to 'blame' action; there are however a few differences in output between 'blame' and 'blame_incremental' view:
* 'blame_incremental' always used query form for this part of link(s) which is generated by JavaScript code. The difference is visible if we use path_info link (pass some or all arguments in path_info). Changing this would require implementing something akin to href() subroutine from gitweb.perl in JavaScript (in gitweb.js).
* 'blame_incremental' always uses "rowspan" attribute, even if rowspan="1". This simplifies code, and is not visible to user.
* The progress bar and progress info are still there even after JavaScript part of 'blame_incremental' finishes work.

Note that currently no link generated by gitweb leads to this new view.

This code is based on patch by Petr Baudis <[email protected]> patch, which in turn was tweaked up version of Fredrik Kuivinen <[email protected]>'s proof of concept patch.

This patch adds GITWEB_JS compile configuration option, and modifies git-instaweb.sh to take gitweb.js into account. The code for git-instaweb.sh was taken from Pasky's patch.

---
References:
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/47614
http://article.gmane.org/gmane.comp.version-control.git/56657
3. New link rewriting and some optimization in Matrin Koegler series introducing some JavaScript support in Git
http://thread.gmane.org/gmane.comp.version-control.git/47902/focus=47905
4. My earlier patches
http://thread.gmane.org/gmane.comp.version-control.git/102657/focus=102712
http://article.gmane.org/gmane.comp.version-control.git/123202
http://thread.gmane.org/gmane.comp.version-control.git/123957/focus=123968
http://thread.gmane.org/gmane.comp.version-control.git/125096/focus=125717

Changes compared to last version (v4):
* The file with JavaScript code for 'blame_incremental' got renamed from 'blame.js' to 'gitweb.js' -- it is now meant to contain all JavaScript code, as per Google and Yahoo! guidelines (there should be one file with JavaScript code, to be cached, as JavaScript loading is blocking).
* Move coloring rows duting 'blame_data' run to a separate commit.
* The debug(str) function and its use (even commented out) was removed; the code is now meant to be in production, and should have leftover debugging statements.
* spacePad(input, width) function, which pads with '&nbsp;' got replaced by more generic padLeftStr(input, width, padstr) function.
* Added information about global variables used by function via @globals annotation (non in JSDoc standard).
* Make prevDataLength and nextReadPos properties (fields) of XMLHttpRequest object, instead of being global variables.
* Pass xhr as parameter to handleError and responseLoaded functions (it shadows xhr as a global variable).
* Move setting onreadystatechange handler before xhr.open()
* Add information about GITWEB_JS Makefile configuration variable to gitweb/README
* Remove unnecessary 'reminder' comments in gitweb.js

TODO for future commits:
* Use W3C Progress Events (progress, error, load) in addition to currently used readystatechange event

    http://www.w3.org/TR/progress-events/
    http://www.w3.org/TR/XMLHttpRequest2/
    http://www.nczonline.net/blog/2009/07/09/firefox-35firebug-xmlhttprequest-and-readystatechange-bug/

if XMLHttpResponse supports it.
* handleResponse is used both as onreadystatechange and pollTimer; if onreadystatechange works for partial responses we can turn off the timer.
* JavaScript is single theraded, therefore there is no need for critical section; remove inProgress global variable (flag), and busy-read while loop.
* Remove (fade out) progress bar and progress info after blame incremental finished run, if possible with large amount of code to deal with browser incompatibilities.

TODO and possible extensions:
* Profile gitweb.js using YUI Profiler (or other JavaScript profile tool)
http://developer.yahoo.com/yui/profiler/
to check whether performance improvements described in articles on NCZOnline blog by Nicholas C. Zakas are required, and would help
http://www.nczonline.net/blog/
* Get rid of global variables, if possible.
* Instead of running startBlame, put it in window.onload handler.

Roads not taken (perhaps that should be part of commit message?):
* Move most (or all) of "git blame --incremental" output parsing to server side, and instead of sending direct output in text/plain, send processed data in JSON format, e.g.

    {"commit": {
       "sha1": "e83c5163316f89bfbde7d9ab23ca2e25604af290",
       "info": "Kay Sievers, 2005-08-07 21:49:46 +0200",
       "author-initials": "KS",
       ...
     },
     "src-line": 13,
     "dst-line": 16,
     "numlines": 3,
     "filename": "README"
     }

(line wrapping added for readibility). This would require however taking care on Perl side to send properly formatted JSON, and on JavaScript side including json2.js code to read JSON in gitweb.js (unless we rely on eval).
* Using some lightweight JavaScript library (framework), like jQuery, Prototype, ExtJS, MooTools, etc. One one hand side this means not having to worry about browser incompatibilities as this would be taken care of by library; on the other hand side we want gitweb to have as few dependences as possible.
* Use 'multipart/x-mixed-replace': first it is not standard, second I don't think this would be a good solution for our problem.

 Makefile           |    6 +-
 git-instaweb.sh    |    7 +
 gitweb/README      |    4 +
 gitweb/gitweb.css  |   11 +
 gitweb/gitweb.js   |  726 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 gitweb/gitweb.perl |  272 ++++++++++++++------
 6 files changed, 939 insertions(+), 87 deletions(-)
 create mode 100644 gitweb/gitweb.js
Makefile +5 -1
index a614347..407b35c 100644
@@ -261,6 +261,7 @@ GITWEB_HOMETEXT = indextext.html
 GITWEB_CSS = gitweb.css
 GITWEB_LOGO = git-logo.png
 GITWEB_FAVICON = git-favicon.png
+GITWEB_JS = gitweb.js
 GITWEB_SITE_HEADER =
 GITWEB_SITE_FOOTER =
 
@@ -1393,13 +1394,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_JS++|$(GITWEB_JS)|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/gitweb.js
 	$(QUIET_GEN)$(RM) $@ $@+ && \
 	sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
 	    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
@@ -1408,6 +1410,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_JS@@/r gitweb/gitweb.js' \
+	    -e '/@@GITWEB_JS@@/d' \
 	    -e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
 	    [email protected] > $@+ && \
 	chmod +x $@+ && \
git-instaweb.sh +7 -0
index d96eddb..701c0d7 100755
@@ -375,8 +375,15 @@ gitweb_css () {
 EOFGITWEB
 }
 
+gitweb_js () {
+	cat > "$1" <<\EOFGITWEB
+@@GITWEB_JS@@
+EOFGITWEB
+}
+
 gitweb_cgi "$GIT_DIR/gitweb/gitweb.cgi"
 gitweb_css "$GIT_DIR/gitweb/gitweb.css"
+gitweb_js  "$GIT_DIR/gitweb/gitweb.js"
 
 case "$httpd" in
 *lighttpd*)
gitweb/README +4 -0
index 66c6a93..b69b0e5 100644
@@ -92,6 +92,10 @@ You can specify the following configuration variables when building GIT:
    web browsers that support favicons (website icons) may display them
    in the browser's URL bar and next to site name in bookmarks).  Relative
    to base URI of gitweb.  [Default: git-favicon.png]
+ * GITWEB_JS
+   Points to the localtion where you put gitweb.js on your web server
+   (or to be more generic URI of JavaScript code used by gitweb).
+   Relative to base URI of gitweb.  [Default: gitweb.js]
  * GITWEB_CONFIG
    This Perl file will be loaded using 'do' and can be used to override any
    of the options above as well as some other options -- see the "Runtime
gitweb/gitweb.css +11 -0
index 00e2e4c..69ef119 100644
@@ -353,6 +353,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.js new file +726 -0

726 lines not on this page · raw message

gitweb/gitweb.perl +187 -87

325 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#3 lore raw

PATCH 3/5 gitweb: Colorize 'blame_incremental' view during processing

This requires using 3 colors, not only two, to be able to choose color different from colors of up to 2 neigbours.

gitweb.js select least used color, if more than one color is possible.

---
This was earlier part of previous commit (adding 'blame_incremental' view).

 gitweb/gitweb.css |    5 ++
 gitweb/gitweb.js  |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 110 insertions(+), 3 deletions(-)
gitweb/gitweb.css +5 -0
index 69ef119..977a013 100644
@@ -262,6 +262,11 @@ tr.no-previous td.linenr {
 	font-weight: bold;
 }
 
+/* for 'blame_incremental', during processing */
+tr.color1 { background-color: #f6fff6; }
+tr.color2 { background-color: #f6f6ff; }
+tr.color3 { background-color: #fff6f6; }
+
 td {
 	padding: 2px 5px;
 	font-size: 100%;
gitweb/gitweb.js +105 -3

132 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#4 lore raw

PATCH 4/5 gitweb: Create links leading to 'blame_incremental' using JavaScript

The new 'blame_incremental' view requires JavaScript to run. Not all web browsers implement JavaScript (e.g. text browsers such as Lynx), and not all users have JavaScript enabled. Therefore instead of unconditionally linking to 'blame_incremental' view, we use JavaScript to convert those links to lead to view utilizing JavaScript, by adding 'js=1' to link.

Currently the only action that takes 'js=1' into account is 'blame', which then acts as if it was called as 'blame_incremental' action. Possible enhancement would be to do JavaScript redirect by setting window.location instead of modifying $format and $action in git_blame_common() subroutine.

The only JavaScript-aware/using view is currently 'blame_incremental'. While at it move reading JavaScript to git_footer_html() subroutine. Note that in this view we do not add 'js=1' currently (even though perhaps we should; note that for consistency we should also add 'js=1' in links added by JavaScript part of 'blame_incremental').

This idea was originally implemented by Petr Baudis in
http://article.gmane.org/gmane.comp.version-control.git/47614
but it added <script> element with fixBlameLinks() function in page header, to be added as onload event using 'onload' attribute of HTML 'body' element: <body onload="fixBlameLinks();">. This version adds script at then end of page (in the page footer), and uses JavaScript 'window.onload=fixLinks();'. Also in Petr version only links marked with 'blamelink' class were modified, and they were modified by replacing "a=blame" by "a=blame_incremental"... which doesn't work for path_info links, and might replace wrong part if there is "a=blame" in project name, ref name or file name.

Slightly different solution was implemented by Martin Koegler in
http://thread.gmane.org/gmane.comp.version-control.git/47902/focus=47905
Here GitAddLinks() function was in gitweb.js file, not as contents of <script> element. It was also included in page header (in <head> element) though, which means waiting for a script to load (and run). It was smarter in that to "fix" (modify) link, it split URL, modified value of 'a' parameter, and then recreated modified link. It avoids trouble with "a=blame" as substring in project name or file name, but it doesn't work with path_info URL/link in the way it was written.

---
This patch is in RFC stage.

Currently fixLinks() is not invoked for 'blame_incremental', but links generated by startBlame (or to be more exact by event handler in gitweb.js) lead to 'blame_incremental' directly. Also the list of "JavaScript-aware actions" is currently hardcoded to 'blame_incremental' (and relies on 'blame' + 'js=1' to change $action).

Also fixLinks() adds 'js=1' to too many links, including $home_link, and links to feeds (where JavaScript is not supported anyway). Alternate solution would be to mark links which lead to action which has JavaScript-requiring alternative, either marking it via 'class' attribute, or providing for example 'alt_href' or 'jshref' attribute with link to JavaScript-requiring variant.

Differences from previous version (v2):
* fixLinks() function is put in gitweb.js together with all JavaScript code required for 'blame_incremental' view, instead of being defined inside <script> element.
* Running startBlame() was moved to git_footer_html, instead of being in git_blame_common
* The link to plain 'blame' view (which do not require JavaScript support enabled in web browser) inside <noscript> element is marked with 'js=0'.
* fixLinks() now doesn't add 'js=1' if links ends with '[?;]js=[01]' (so that e.g. 'js=0' means link to view which do not require JavaScript).
* performance: calculate number of elements in a list before loop

TODO for future commits:
* Use 'click' event to change links to jave 'js=1' parameter appended; this way we would check if JavaScript is enabled at the moment of following (clicking) link, not at the moment of loading the page.

Unfortunately adding event listeners (much better solution than providing/adding 'onclick' attribute) is different in different browsers. Some kind of wrapper around browser incompatibilities would be required.

 gitweb/gitweb.js   |   34 ++++++++++++++++++++++++++++++++++
 gitweb/gitweb.perl |   28 +++++++++++++++++++---------
 2 files changed, 53 insertions(+), 9 deletions(-)
gitweb/gitweb.js +34 -0
index bf38216..66fd64e 100644
@@ -7,6 +7,39 @@
  * @license GPLv2 or later
  */
 
+/* ============================================================ */
+/* functions for generic gitweb actions and views */
+
+/**
+ * used to check if link has 'js' query parameter already (at end),
+ * and other reasons to not add 'js=1' param at the end of link
+ * @constant
+ */
+var jsExceptionsRe = /[;?]js=[01]$/;
+
+/**
+ * Add '?js=1' or ';js=1' to the end of every link in the document
+ * that doesn't have 'js' query parameter set already.
+ *
+ * Links with 'js=1' lead to JavaScript version of given action, if it
+ * exists (currently there is only 'blame_incremental' for 'blame')
+ *
+ * @globals jsExceptionsRe
+ */
+function fixLinks() {
+	var allLinks = document.getElementsByTagName("a") || document.links;
+	for (var i = 0, len = allLinks.length; i < len; i++) {
+		var link = allLinks[i];
+		if (!jsExceptionsRe.test(link)) { // =~ /[;?]js=[01]$/;
+			link.href +=
+				(link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1';
+		}
+	}
+}
+
+
+/* ============================================================ */
+
 /*
  * This code uses DOM methods instead of (nonstandard) innerHTML
  * to modify page.
@@ -89,6 +122,7 @@ function createRequestObject() {
 	return null;
 }
 
+
 /* ============================================================ */
 /* utility/helper functions (and variables) */
 
gitweb/gitweb.perl +19 -9
index 88c91ff..0adfd3f 100755
@@ -571,6 +571,8 @@ our @cgi_param_mapping = (
 	snapshot_format => "sf",
 	extra_options => "opt",
 	search_use_regexp => "sr",
+	# this must be last entry (for manipulation from JavaScript)
+	javascript => "js"
 );
 our %cgi_param_mapping = @cgi_param_mapping;
 
@@ -3255,6 +3257,18 @@ sub git_footer_html {
 		insert_file($site_footer);
 	}
 
+	print qq!<script type="text/javascript" src="$javascript"></script>\n!;
+	if ($action eq 'blame_incremental') {
+		print qq!<script type="text/javascript">\n!.
+		      qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.
+		      qq!           "!. href() .qq!");\n!.
+		      qq!</script>\n!;
+	} else {
+		print qq!<script type="text/javascript">\n!.
+		      qq!window.onload = fixLinks;\n!.
+		      qq!</script>\n!;
+	}
+
 	print "</body>\n" .
 	      "</html>";
 }
@@ -4806,6 +4820,10 @@ sub git_tag {
 
 sub git_blame_common {
 	my $format = shift || 'porcelain';
+	if ($format eq 'porcelain' && $cgi->param('js')) {
+		$format = 'incremental';
+		$action = 'blame_incremental'; # for page title etc
+	}
 
 	# permissions
 	gitweb_check_feature('blame')
@@ -4885,7 +4903,7 @@ sub git_blame_common {
 	if ($format eq 'incremental') {
 		print "<noscript>\n<div class=\"error\"><center><b>\n".
 		      "This page requires JavaScript to run.\n Use ".
-		      $cgi->a({-href => href(action=>'blame',-replay=>1)},
+		      $cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)},
 		              'this page').
 		      " instead.\n".
 		      "</b></center></div>\n</noscript>\n";
@@ -5016,14 +5034,6 @@ sub git_blame_common {
 	close $fd
 		or print "Reading blob failed\n";
 
-	if ($format eq 'incremental') {
-		print qq!<script type="text/javascript" src="$javascript"></script>\n!.
-		      qq!<script type="text/javascript">\n!.
-		      qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.
-		      qq!           "!. href() .qq!");\n!.
-		      qq!</script>\n!;
-	}
-
 	git_footer_html();
 }
 
Signature · 1 line
1.6.3.3
#5 lore raw

PATCH 5/5 gitweb: Minify gitweb.js if JSMIN is defined

It requires that $JSMIN command can function as a filter.

---
This patch is new in series. Comments welcome.

I have not tested it extensively, but JSMIN=cat seems to work correctly.

 Makefile |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
Makefile +20 -0
index 407b35c..f149a36 100644
@@ -194,6 +194,9 @@ all::
 # memory allocators with the nedmalloc allocator written by Niall Douglas.
 #
 # Define NO_REGEX if you have no or inferior regex support in your C library.
+#
+# Define JSMIN to point to JavaScript minifier that functions as
+# a filter to have gitweb.js minified.
 
 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
 	@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -246,6 +249,9 @@ lib = lib
 # DESTDIR=
 pathsep = :
 
+# JavaScript minifier invocation that can function as filter
+JSMIN =
+
 # default configuration for gitweb
 GITWEB_CONFIG = gitweb_config.perl
 GITWEB_CONFIG_SYSTEM = /etc/gitweb.conf
@@ -261,7 +267,11 @@ GITWEB_HOMETEXT = indextext.html
 GITWEB_CSS = gitweb.css
 GITWEB_LOGO = git-logo.png
 GITWEB_FAVICON = git-favicon.png
+ifdef JSMIN
+GITWEB_JS = gitweb.min.js
+else
 GITWEB_JS = gitweb.js
+endif
 GITWEB_SITE_HEADER =
 GITWEB_SITE_FOOTER =
 
@@ -1374,8 +1384,13 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl
 	chmod +x $@+ && \
 	mv $@+ $@
 
+ifdef JSMIN
+OTHER_PROGRAMS += gitweb/gitweb.cgi   gitweb/gitweb.min.js
+gitweb/gitweb.cgi: gitweb/gitweb.perl gitweb/gitweb.min.js
+else
 OTHER_PROGRAMS += gitweb/gitweb.cgi
 gitweb/gitweb.cgi: gitweb/gitweb.perl
+endif
 	$(QUIET_GEN)$(RM) $@ $@+ && \
 	sed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' \
 	    -e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
@@ -1426,6 +1441,11 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)) git-instaweb: % : unimplemented.sh
 	mv $@+ $@
 endif # NO_PERL
 
+ifdef JSMIN
+gitweb/gitweb.min.js: gitweb/gitweb.js
+	$(QUIET_GEN)$(JSMIN) <$< >$@
+endif # JSMIN
+
 configure: configure.ac
 	$(QUIET_GEN)$(RM) $@ $<+ && \
 	sed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
Signature · 1 line
1.6.3.3
#6 lore raw

Re: [PATCHv3/RFC 4/5] gitweb: Create links leading to 'blame_incremental' using JavaScript

In reply to Jakub Narebski

Hi!

gitweb/gitweb.perl sub git_tag { · line 4829

Quoted 11 lines · Jakub Narebski
gitweb/gitweb.perl +4 -0
@@ -4806,6 +4820,10 @@ sub git_tag {
 
 sub git_blame_common {
 	my $format = shift || 'porcelain';
+	if ($format eq 'porcelain' && $cgi->param('js')) {
+		$format = 'incremental';
+		$action = 'blame_incremental'; # for page title etc
+	}
 
 	# permissions
 	gitweb_check_feature('blame')

I'm a bit concerned here. I have somewhat backed out of incremental
blame myself because I have found (in accord with Junio's old findings) that in most cases, incremental blame can be actually slower than normal blame because of slow browsers where it takes long to update the page in each step.

I'm sorry if I missed this in one of your mails, but how fast is
incremental blame in your implementation? If this still might be an issue, I think it should be configurable whether to use incremental blame, or perhaps use some quick heuristic wrt. file size (negative bias) and history length (positive bias) [not sure if that information is quickly available].

Signature · 3 lines
				Petr "Pasky" Baudis
A lot of people have my books on their bookshelves.
That's the problem, they need to read them. -- Don Knuth
#7 lore raw

Re: [PATCHv3/RFC 4/5] gitweb: Create links leading to 'blame_incremental' using JavaScript

Quoted 19 lines · Petr Baudis

gitweb/gitweb.perl sub git_tag { · line 4829

Quoted 11 lines · Jakub Narebski
gitweb/gitweb.perl +4 -0
@@ -4806,6 +4820,10 @@ sub git_tag {
 
 sub git_blame_common {
 	my $format = shift || 'porcelain';
+	if ($format eq 'porcelain' && $cgi->param('js')) {
+		$format = 'incremental';
+		$action = 'blame_incremental'; # for page title etc
+	}
 
 	# permissions
 	gitweb_check_feature('blame')

I'm a bit concerned here. I have somewhat backed out of incremental
blame myself because I have found (in accord with Junio's old findings) that in most cases, incremental blame can be actually slower than normal blame because of slow browsers where it takes long to update the page in each step.

Quoted 6 lines

I'm sorry if I missed this in one of your mails, but how fast is
incremental blame in your implementation? If this still might be an issue, I think it should be configurable whether to use incremental blame, or perhaps use some quick heuristic wrt. file size (negative bias) and history length (positive bias) [not sure if that information is quickly available].

Unfortunately I can't benchmark the speed of incremental blame well because of testing it on a single computer.

What I have found that incremental blame spares at least _server time_, which means that the time to prepare starting view for incremental blame (with the contents of file in blame format, unblamed) plus the time to generate incremental blame data is usually about the same or faster than the time to generate ordinary blame view. Quite faster if file have large number of blamed commits:

  $ git blame -p <file> | grep author-time | wc -l

But even if incremental blame turns out to be slower than incremental blame it still has the advantage of being _incremental_. You have at least some result soon. Even more with current implementation which includes progress report for incremental blame.

What needs to be addressed however is to remove totally unnecessary critical section / locking code, as JavaScript is single threaded. We should take care however that JavaScript code of interactive blame doesn't take all CPU, for example using technique presented in
"Timed array processing in JavaScript" by Nicholas C. Zakas
http://www.nczonline.net/blog/2009/08/11/timed-array-processing-in-javascript/

.....................................................................

If you want below there are very simple benchmark of blame and incremental blame on a _single_ computer:
AMD Athlon 1 GHz, 512MB RAM, Linux 2.6.14-11.1.aur.2, Apache 2.0.54
I don't remember however if it is for the most current code.

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

blob.h             |     2.346s |  0.443s +  (2.244s /   2.921s)
GIT-VERSION-GEN    |     2.449s |  1.346s +  (3.157s /   3.876s)
README             |     2.713s |  0.508s +  (2.952s /   3.659s)
revision.c         |    19.964s |  4.872s + (11.306s /  32.124s)
gitweb/gitweb.perl |    83.912s | 12.069s + (52.922s / 223.133s)
$ git blame --porcelain   gitweb/gitweb.perl >/dev/null
  0m11.437s user + 0m0.740s sys, 66300minor pagefaults
$ git blame --incremental gitweb/gitweb.perl >/dev/null
  0m11.477s user + 0m0.816s sys, 68945minor pagefaults

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

Signature · 2 lines
Jakub Narebski
Poland
#8 lore raw

Re: [PATCHv3/RFC 4/5] gitweb: Create links leading to 'blame_incremental' using JavaScript

Quoted 3 lines · Jakub Narebski

But even if incremental blame turns out to be slower than incremental blame it still has the advantage of being _incremental_. You have at least some result soon.

It wasn't it was slow that bothered me, but early implementations of incremental blame I tried didn't _appear_ as incremental. That was the dissapointing part.

At the protocol and implementation level it certainly was feeding data incrementally to the browser, but the end user experience on the screen was "click....wait...wait...wait...voila the whole blame appears", not "click...trickle...trickle...trickle...ah everything is filled". The latter obviously is what an incremental one should be aiming for.

No I haven't tried your latest code. Probably I should.

#9 lore raw

Re: [PATCHv3/RFC 4/5] gitweb: Create links leading to 'blame_incremental' using JavaScript

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

But even if incremental blame turns out to be slower than incremental blame it still has the advantage of being _incremental_. You have at least some result soon.

It wasn't it was slow that bothered me, but early implementations of incremental blame I tried didn't _appear_ as incremental. That was the dissapointing part.

Quoted 7 lines

At the protocol and implementation level it certainly was feeding data incrementally to the browser, but the end user experience on the screen was "click....wait...wait...wait...voila the whole blame appears", not "click...trickle...trickle...trickle...ah everything is filled". The latter obviously is what an incremental one should be aiming for.

No I haven't tried your latest code. Probably I should.

The problem with earliest versions of incremental blame _in some browsers_ was that 'onreadystatechange' event was not fired as soon as new part of blame data was available (truth to be said the definition of this event is a bit underspecified). That is why newer versions of interactive blame use timer (alarm) to check every 1 second if there is something new.

Perhaps interactive blame should use 'onprogress' event instead, which is well defined... but is in _draft_ of standard (XHR 2.0), and not yet in established standard.

Signature · 2 lines
Jakub Narebski
Poland
#10 lore raw

Re: [PATCHv5 2/5] gitweb: Incremental blame (using JavaScript)

In reply to Jakub Narebski

Hi!

Many thanks for nurturing this patch.

Quoted 17 lines · Jakub Narebski

Roads not taken (perhaps that should be part of commit message?):
* Move most (or all) of "git blame --incremental" output parsing to server side, and instead of sending direct output in text/plain, send processed data in JSON format, e.g.

    {"commit": {
       "sha1": "e83c5163316f89bfbde7d9ab23ca2e25604af290",
       "info": "Kay Sievers, 2005-08-07 21:49:46 +0200",
       "author-initials": "KS",
       ...
     },
     "src-line": 13,
     "dst-line": 16,
     "numlines": 3,
     "filename": "README"
     }
Quoted 4 lines

(line wrapping added for readibility). This would require however taking care on Perl side to send properly formatted JSON, and on JavaScript side including json2.js code to read JSON in gitweb.js (unless we rely on eval).

I don't know that much about web programming, what is wrong with
relying on eval?

(BTW, I have always thought that somewhat inevitable course in the
future will be to provide a web API, and basing it on JSON is probably most natural choice. However, such an initiative needs to come from actual web programmers.)

Quoted 5 lines

* Using some lightweight JavaScript library (framework), like jQuery, Prototype, ExtJS, MooTools, etc. One one hand side this means not having to worry about browser incompatibilities as this would be taken care of by library; on the other hand side we want gitweb to have as few dependences as possible.

Normally, particular version of the library is simply included within
the project. E.g. in Girocco, I use MooTools for the tiny bit of javascript I do. It is probably overkill to include it just for incremental blame, but if we ever do much more, I think the much easier web programming is worth the little trouble.

Signature · 3 lines
				Petr "Pasky" Baudis
A lot of people have my books on their bookshelves.
That's the problem, they need to read them. -- Don Knuth
#11 lore raw

Re: [PATCHv5 2/5] gitweb: Incremental blame (using JavaScript)

Quoted 2 lines · Petr Baudis

Many thanks for nurturing this patch.

You are welcome.

I have learned quite a bit about JavaScript when working on this patch...

Quoted 18 lines · Jakub Narebski
Quoted 17 lines

Roads not taken (perhaps that should be part of commit message?):
* Move most (or all) of "git blame --incremental" output parsing to server side, and instead of sending direct output in text/plain, send processed data in JSON format, e.g.

    {"commit": {
       "sha1": "e83c5163316f89bfbde7d9ab23ca2e25604af290",
       "info": "Kay Sievers, 2005-08-07 21:49:46 +0200",
       "author-initials": "KS",
       ...
     },
     "src-line": 13,
     "dst-line": 16,
     "numlines": 3,
     "filename": "README"
     }
Quoted 7 lines
Quoted 4 lines

(line wrapping added for readibility). This would require however taking care on Perl side to send properly formatted JSON, and on JavaScript side including json2.js code to read JSON in gitweb.js (unless we rely on eval).

I don't know that much about web programming, what is wrong with
relying on eval?

In general it is insecure. In this specific situation it shouldn't.

[...]

Quoted 11 lines
Quoted 5 lines

* Using some lightweight JavaScript library (framework), like jQuery, Prototype, ExtJS, MooTools, etc. One one hand side this means not having to worry about browser incompatibilities as this would be taken care of by library; on the other hand side we want gitweb to have as few dependences as possible.

Normally, particular version of the library is simply included within
the project. E.g. in Girocco, I use MooTools for the tiny bit of javascript I do. It is probably overkill to include it just for incremental blame, but if we ever do much more, I think the much easier web programming is worth the little trouble.

Alternate solution would be to load for example jQuery for example hosted on Google as described in http://code.google.com/apis/ajaxlibs/documentation/

Signature · 2 lines
Jakub Narebski
Poland