Skip to contentSkip to conversation

gitweb: Incremental blame series

PATCH New Jakub Narebski 1 participant 5 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

cover gitweb: Incremental blame series

This series is meant to replace the top 4 commits of 'jn/gitweb-blame' topic branch, those dealing with AJAX-y blame.

* jn/gitweb-blame:
gitweb: Create links leading to 'blame_incremental' using JavaScript
gitweb: Incremental blame (proof of concept)
gitweb: Add optional "time to generate page" info in footer
gitweb: Add -partial_query option to href() subroutine

gitweb: Use light/dark for class names also in 'blame' view
gitweb: Add author initials in 'blame' view, a la "git gui blame"
gitweb: Mark commits with no "previous" in 'blame' view
gitweb: Use "previous" header of git-blame -p in 'blame' view
gitweb: Mark boundary commits in 'blame' view
gitweb: Make .error style generic

The commit adding -partial_query option to href() is no longer necessary, and was removed from this improved series.

This version at last doesn't turn off application/xhtml+xml as content type in gitweb, because blame.js no longer uses innerHTML (and I can debug it in my web browser). Major changes are to second patch in the series.

Table of contents:
==================
[PATCH/RFC 1/3] gitweb: Add optional "time to generate page" info
in footer
[PATCHv3/RFC 2/3] gitweb: Incremental blame (proof of concept) [PATCHv2/RFC 3/3] gitweb: Create links leading to 'blame_incremental'
using JavaScript

Diffstat:
=========

 Makefile           |    6 +-
 git-instaweb.sh    |    7 +
 gitweb/blame.js    |  731 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 gitweb/gitweb.css  |   16 ++
 gitweb/gitweb.perl |  321 +++++++++++++++++------
 5 files changed, 994 insertions(+), 87 deletions(-)
 create mode 100644 gitweb/blame.js
#1 lore raw

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

Add "This page took XXXs 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 setting $t0 variable should be fairly early to have running time of the whole script. The same for $number_of_git_cmds.

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

---
This patch is unchanged from previous version.

Current formatting is very basic, just like before. It simply uses 'page_footer' style. At least "time to generate page" info should be clearly separate from the gitweb footer proper.

 gitweb/gitweb.perl |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)
gitweb/gitweb.perl +29 -0
index 2cb60be..c6894e2 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'};
 }
@@ -394,6 +400,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 {
@@ -507,6 +520,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;
 
@@ -1955,6 +1969,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;
 }
 
@@ -3205,6 +3220,20 @@ sub git_footer_html {
 	}
 	print "</div>\n"; # class="page_footer"
 
+	if (defined $t0 && gitweb_check_feature('timed')) {
+		print "<div id=\"generate_info\" class=\"page_footer\">\n";
+		print 'This page took '.
+		      '<span id="generate_time" class="time_span">'.
+		      Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday()]).'s'.
+		      '</span>'.
+		      ' and '.
+		      '<span id="generate_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 2/3 gitweb: Incremental blame (proof of concept)

In reply to Jakub Narebski

This is tweaked up version of Petr Baudis <[email protected]> patch, which in turn 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 Per 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 from gitweb.perl in JavaScript
* 'blame_incremental' currently always uses "rowspan" attribute, even when it leads to torowspan="1". This is not visible to user.

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.

---
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/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

Changes compared to last version (v2):
* projectUrl now contains '?' or ';' as terminator; the bUrl parameter to startBlame function doesn't need to be href(..., -partial_query), but just href(...).
* Do not use (nonstandard but widely implemented) elem.innerHTML, but elem.firstChild.data (DOM 2 Core: CharacterData). It is less powerfull (only text) and more fragile (text node has to exist, and has to be first child) currently, but a bit faster. Code was modified to ensure that (' ' as tag content as a start value). See comment at beginning of blame.js file.
* Remove commenting out content type negotiation, which prevented sending 'application/xhtml+xml' content type if it is preferred by
browser (gitweb always used 'text/html' in v2). This content type
causes in most browsers turning on strict XML mode; and in Firefox up to 1.5 it turned on strict _JavaScript_ mode, which meant no innerHTML. Now that blame.js doesn't use innerHTML it is no longer necessary to have for me to be able to debug 'blame_incremental' view.

* remove '#"' used to help with confused syntax highlighting
* remove tr.colorN:hover style (doesn't work well with commit groups, i.e. blamed commit being responsible/blamed for several consecutive lines)
* use document fragment to (try to) speed up DOM manipulation, if possible (if browser supports createDocumentFragment())
* use generic "padLeft(num, 2, '0')" in place of specilized "zeroPad(num)"; remove zeroPad() function
* added JSDoc documentation and other comments
* comment out debug(...) calls
* extended copyright statement
* future-proof so 'var = Commmit(sha1);' works as 'var = new Commit(sha1);' (nice trick, but probably not necessary)

TODO list:
* Use W3C Progress Events in addition/instead of readystatechange

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

event, if XMLHttpResponse supports it
* handleResponse is used both as onreadystatechange and pollTimer; if onreadystatechange works for partial responses we can turn off the timer.
* handleResponse is protected from concurrent running by global inProgress variable; we could instead pass XMLHttpResponse object as a parameter (see comment in startBlame).
* Instead of running startBlame, put it in window.onload handler
* Rename blame.js to gitweb.js to have all JavaScript in a single file. Note that this would require changes to next commit in series (enabling 'blame_incremental' view if browser has javaScript turned on).

TODO for future commits:
* Remove (fade out) progress bar and progress info after blame incremental finished run (left for a separate commit).
* Profile blame.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/
* Check whether it is worth to do some server processing of incremental blame output, and send e.g. JSON and not text/plain of raw 'git blame --incremental' output.
* Check whether it would make sense to use some lightweight JavaScript library (framework) like jQuery, Prototype, ExtJS, MooTools, etc.
* Minify JavaScript during building gitweb/gitweb.cgi, if minification tool is found.

 Makefile           |    6 +-
 git-instaweb.sh    |    7 +
 gitweb/blame.js    |  731 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 gitweb/gitweb.css  |   16 ++
 gitweb/gitweb.perl |  271 +++++++++++++------
 5 files changed, 944 insertions(+), 87 deletions(-)
 create mode 100644 gitweb/blame.js
Makefile +5 -1
index daf4296..cb93aa3 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 =
 
@@ -1407,13 +1408,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' \
@@ -1422,6 +1424,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 32f6496..15dfb96 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 +731 -0

731 lines not on this page · raw message

gitweb/gitweb.css +16 -0
index 8f68fe3..c9a7501 100644
@@ -250,6 +250,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%;
@@ -341,6 +346,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 +186 -87

324 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#4 lore raw

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

In reply to Jakub Narebski

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 link to 'blame_incremental' view, we use JavaScript to convert those links to lead to view utilizing JavaScript, by adding 'js=1' to link.

The only JavaScript-aware/using view is currently 'blame_incremental'. As first, it might want to have links to non-JavaScript version, and second, it should also use window.onload, we do not add nor run fixLinks() for such views (currently hardcoded 'blame_incremental')

Possible enhancement would be to do JavaScript redirect by setting window.location instead of modifying $format and $action in git_blame_common() subroutine.

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. This might be a better solution (although I think it would be better to split JavaScript file and load only parts that are required). 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 is nearly the same as previous (first) version, it only doesn't have unrelated changes to blame.js that were included in earlier version by mistake.

TODO list:
* Put fixLinks() function in gitweb.js, together with all code required for 'blame_incremental' view.
* Better solution to "don't invoke for JavaScript-aware actions" problem. Currently hardcoded 'blame_incremental'.

The problem to be solved is that we might want in views utilizing JavaScript to have fallback links to version not using JavaScript.

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.

 gitweb/gitweb.perl |   21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)
gitweb/gitweb.perl +21 -0
index b94ce10..32cbb20 100755
@@ -3242,6 +3242,23 @@ sub git_footer_html {
 		insert_file($site_footer);
 	}
 
+	if ($action ne 'blame_incremental') {
+		print <<'HTML';
+<script type="text/javascript">/* <![CDATA[ */
+function fixLinks() {
+	//var allLinks = document.getElementsByTagName("a");
+	var allLinks = document.links;
+	for (var i = 0; i < allLinks.length; i++) {
+		var link = allLinks[i];
+		link.href +=
+			(link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1';
+	}
+}
+window.onload = fixLinks;
+/* ]]> */</script>
+HTML
+	}
+
 	print "</body>\n" .
 	      "</html>";
 }
@@ -4793,6 +4810,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')
Signature · 1 line
1.6.3.3
#3 lore raw

PATCH 2/3 gitweb: Incremental blame (WIP)

In reply to Jakub Narebski

This is tweaked up version of Petr Baudis <[email protected]> patch, which in turn 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 Per 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 neighboring 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 from gitweb.perl in JavaScript
* 'blame_incremental' always uses "rowspan" attribute, even if rowspan="1". This is not visible to user. (The code actually could work without it).

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.

---
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/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

Changes compared to last version (v3):
* Try yet another method (window.createrequest()) in createRequestObject() function.
* Rename variable holding XMLHttpRequest object from 'http' to 'xhr'
* Separate data about group of lines which are changed by the smae commit (which blame the same commit): srcline, resline, numlines, and put it in curGroup variable instead of using Commit object (curCommit) for that. handleLine() function acquires 'group' as second parameter.
* delete no longer needed Commit properties (to be removed)
* Simplify logic and code of selecting unprocessed part of XMLHttpRequest responseText for processing. nextLine global variable is now named nextReadPos, code now check first if there are any complete unprocessed lines before doing split('\n'), and there is now no need to remove incomplete line from 'lines'. This code which was inside handleResponse() can now be found in processData subroutine.
* Separate parts of handleResponse() as a cleanup and in preparation for having (simpler) event handlers for 'progress', 'load' and 'error' W3C Progress Events, and having 'readystatechange' handler to be just dispatcher for those event handlers. Introduce functions:
processBlameLines, processData, handleError and responseLoaded
* Use DOM 2 HTML "elem.style.cssText = value;" instead of DOM 2 Core "elem.setAttribute('style', value);"
* Add a few 'work in progress' comments.
* Remove comment about 'multipart/x-mixed-replace': it is non-standard, and it requires server to know when chunks ands to send replacements, something that cannot easily be done: incremental git-blame sends data in chunks, but gitweb doesn't know when they end.

TODO list:
* Use W3C Progress Events instead of '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, 'readystatechange' event + poll timer otherwise.
* handleResponse is used both as onreadystatechange and pollTimer; if onreadystatechange works for partial responses we can turn off the timer.
* Clean up handling concurrency, i.e. dealing with situation when handleResponse event handler is called before previous call finished working. Currently it is done using inProgress flag, and busy-read while loop.
* Get rid of global variables, if possible.
* Instead of running startBlame, put it in window.onload handler
* Rename blame.js to gitweb.js to have all JavaScript in a single file. Note that this would require changes to next commit in series (enabling 'blame_incremental' view if browser has javaScript turned on).

TODO for future commits:
* Remove (fade out) progress bar and progress info after blame incremental finished run (left for a separate commit).
* Profile blame.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/
* Check whether it is worth to do some server processing of incremental blame output, and send e.g. JSON and not text/plain of raw 'git blame --incremental' output.
* Check how supported is 'multipart/x-mixed-replace' mimetype for data pushed from server (and how to correctly implement it); perhaps that would be a solution to concurrency problem?
* Check whether it would make sense to use some lightweight JavaScript library (framework) like jQuery, Prototype, ExtJS, MooTools, etc.
* Minify JavaScript during building gitweb/gitweb.cgi, if minification tool is found.

 Makefile           |    6 +-
 git-instaweb.sh    |    7 +
 gitweb/blame.js    |  819 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 gitweb/gitweb.css  |   16 +
 gitweb/gitweb.perl |  271 ++++++++++++------
 5 files changed, 1032 insertions(+), 87 deletions(-)
 create mode 100644 gitweb/blame.js
Makefile +5 -1
index daf4296..cb93aa3 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 =
 
@@ -1407,13 +1408,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' \
@@ -1422,6 +1424,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 5f5cac7..0288450 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 +819 -0

819 lines not on this page · raw message

gitweb/gitweb.css +16 -0
index 8f68fe3..c9a7501 100644
@@ -250,6 +250,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%;
@@ -341,6 +346,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 +186 -87

324 lines not on this page · raw message

Signature · 1 line
1.6.3.3