Merge branch 'jn/gitweb-js-blame' into next
* jn/gitweb-js-blame: gitweb.js: use setTimeout rather than setInterval in blame_incremental.js gitweb.js: No need for loop in blame_incremental's handleResponse() gitweb.js: No need for inProgress in blame_incremental.js
This commit is contained in:
@ -29,7 +29,6 @@
|
|||||||
/* ............................................................ */
|
/* ............................................................ */
|
||||||
/* utility/helper functions (and variables) */
|
/* utility/helper functions (and variables) */
|
||||||
|
|
||||||
var xhr; // XMLHttpRequest object
|
|
||||||
var projectUrl; // partial query + separator ('?' or ';')
|
var projectUrl; // partial query + separator ('?' or ';')
|
||||||
|
|
||||||
// 'commits' is an associative map. It maps SHA1s to Commit objects.
|
// 'commits' is an associative map. It maps SHA1s to Commit objects.
|
||||||
@ -420,8 +419,6 @@ function handleLine(commit, group) {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
var inProgress = false; // are we processing response
|
|
||||||
|
|
||||||
/**#@+
|
/**#@+
|
||||||
* @constant
|
* @constant
|
||||||
*/
|
*/
|
||||||
@ -433,8 +430,6 @@ var endRe = /^END ?([^ ]*) ?(.*)/;
|
|||||||
var curCommit = new Commit();
|
var curCommit = new Commit();
|
||||||
var curGroup = {};
|
var curGroup = {};
|
||||||
|
|
||||||
var pollTimer = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse output from 'git blame --incremental [...]', received via
|
* Parse output from 'git blame --incremental [...]', received via
|
||||||
* XMLHttpRequest from server (blamedataUrl), and call handleLine
|
* XMLHttpRequest from server (blamedataUrl), and call handleLine
|
||||||
@ -535,43 +530,51 @@ function processData(unprocessed, nextReadPos) {
|
|||||||
* Handle XMLHttpRequest errors
|
* Handle XMLHttpRequest errors
|
||||||
*
|
*
|
||||||
* @param {XMLHttpRequest} xhr: XMLHttpRequest object
|
* @param {XMLHttpRequest} xhr: XMLHttpRequest object
|
||||||
|
* @param {Number} [xhr.pollTimer] ID of the timeout to clear
|
||||||
*
|
*
|
||||||
* @globals pollTimer, commits, inProgress
|
* @globals commits
|
||||||
*/
|
*/
|
||||||
function handleError(xhr) {
|
function handleError(xhr) {
|
||||||
errorInfo('Server error: ' +
|
errorInfo('Server error: ' +
|
||||||
xhr.status + ' - ' + (xhr.statusText || 'Error contacting server'));
|
xhr.status + ' - ' + (xhr.statusText || 'Error contacting server'));
|
||||||
|
|
||||||
clearInterval(pollTimer);
|
if (typeof xhr.pollTimer === "number") {
|
||||||
|
clearTimeout(xhr.pollTimer);
|
||||||
|
delete xhr.pollTimer;
|
||||||
|
}
|
||||||
commits = {}; // free memory
|
commits = {}; // free memory
|
||||||
|
|
||||||
inProgress = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called after XMLHttpRequest finishes (loads)
|
* Called after XMLHttpRequest finishes (loads)
|
||||||
*
|
*
|
||||||
* @param {XMLHttpRequest} xhr: XMLHttpRequest object (unused)
|
* @param {XMLHttpRequest} xhr: XMLHttpRequest object
|
||||||
|
* @param {Number} [xhr.pollTimer] ID of the timeout to clear
|
||||||
*
|
*
|
||||||
* @globals pollTimer, commits, inProgress
|
* @globals commits
|
||||||
*/
|
*/
|
||||||
function responseLoaded(xhr) {
|
function responseLoaded(xhr) {
|
||||||
clearInterval(pollTimer);
|
if (typeof xhr.pollTimer === "number") {
|
||||||
|
clearTimeout(xhr.pollTimer);
|
||||||
|
delete xhr.pollTimer;
|
||||||
|
}
|
||||||
|
|
||||||
fixColorsAndGroups();
|
fixColorsAndGroups();
|
||||||
writeTimeInterval();
|
writeTimeInterval();
|
||||||
commits = {}; // free memory
|
commits = {}; // free memory
|
||||||
|
|
||||||
inProgress = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* handler for XMLHttpRequest onreadystatechange event
|
* handler for XMLHttpRequest onreadystatechange event
|
||||||
* @see startBlame
|
* @see startBlame
|
||||||
*
|
*
|
||||||
* @globals xhr, inProgress
|
* @param {XMLHttpRequest} xhr: XMLHttpRequest object
|
||||||
|
* @param {Number} xhr.prevDataLength: previous value of xhr.responseText.length
|
||||||
|
* @param {Number} xhr.nextReadPos: start of unread part of xhr.responseText
|
||||||
|
* @param {Number} [xhr.pollTimer] ID of the timeout (to reset or cancel)
|
||||||
|
* @param {Boolean} fromTimer: if handler was called from timer
|
||||||
*/
|
*/
|
||||||
function handleResponse() {
|
function handleResponse(xhr, fromTimer) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xhr.readyState
|
* xhr.readyState
|
||||||
@ -609,32 +612,31 @@ function handleResponse() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case we were called before finished processing
|
|
||||||
if (inProgress) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
inProgress = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// extract new whole (complete) lines, and process them
|
// extract new whole (complete) lines, and process them
|
||||||
while (xhr.prevDataLength !== xhr.responseText.length) {
|
if (xhr.prevDataLength !== xhr.responseText.length) {
|
||||||
if (xhr.readyState === 4 &&
|
|
||||||
xhr.prevDataLength === xhr.responseText.length) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
xhr.prevDataLength = xhr.responseText.length;
|
xhr.prevDataLength = xhr.responseText.length;
|
||||||
var unprocessed = xhr.responseText.substring(xhr.nextReadPos);
|
var unprocessed = xhr.responseText.substring(xhr.nextReadPos);
|
||||||
xhr.nextReadPos = processData(unprocessed, xhr.nextReadPos);
|
xhr.nextReadPos = processData(unprocessed, xhr.nextReadPos);
|
||||||
} // end while
|
|
||||||
|
|
||||||
// did we finish work?
|
|
||||||
if (xhr.readyState === 4 &&
|
|
||||||
xhr.prevDataLength === xhr.responseText.length) {
|
|
||||||
responseLoaded(xhr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inProgress = false;
|
// did we finish work?
|
||||||
|
if (xhr.readyState === 4) {
|
||||||
|
responseLoaded(xhr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we get from timer, we have to restart it
|
||||||
|
// otherwise onreadystatechange gives us partial response, timer not needed
|
||||||
|
if (fromTimer) {
|
||||||
|
setTimeout(function () {
|
||||||
|
handleResponse(xhr, true);
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
} else if (typeof xhr.pollTimer === "number") {
|
||||||
|
clearTimeout(xhr.pollTimer);
|
||||||
|
delete xhr.pollTimer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
@ -649,11 +651,11 @@ function handleResponse() {
|
|||||||
* Called from 'blame_incremental' view after loading table with
|
* Called from 'blame_incremental' view after loading table with
|
||||||
* file contents, a base for blame view.
|
* file contents, a base for blame view.
|
||||||
*
|
*
|
||||||
* @globals xhr, t0, projectUrl, div_progress_bar, totalLines, pollTimer
|
* @globals t0, projectUrl, div_progress_bar, totalLines
|
||||||
*/
|
*/
|
||||||
function startBlame(blamedataUrl, bUrl) {
|
function startBlame(blamedataUrl, bUrl) {
|
||||||
|
|
||||||
xhr = createRequestObject();
|
var xhr = createRequestObject();
|
||||||
if (!xhr) {
|
if (!xhr) {
|
||||||
errorInfo('ERROR: XMLHttpRequest not supported');
|
errorInfo('ERROR: XMLHttpRequest not supported');
|
||||||
return;
|
return;
|
||||||
@ -672,8 +674,9 @@ function startBlame(blamedataUrl, bUrl) {
|
|||||||
xhr.prevDataLength = -1; // used to detect if we have new data
|
xhr.prevDataLength = -1; // used to detect if we have new data
|
||||||
xhr.nextReadPos = 0; // where unread part of response starts
|
xhr.nextReadPos = 0; // where unread part of response starts
|
||||||
|
|
||||||
xhr.onreadystatechange = handleResponse;
|
xhr.onreadystatechange = function () {
|
||||||
//xhr.onreadystatechange = function () { handleResponse(xhr); };
|
handleResponse(xhr, false);
|
||||||
|
};
|
||||||
|
|
||||||
xhr.open('GET', blamedataUrl);
|
xhr.open('GET', blamedataUrl);
|
||||||
xhr.setRequestHeader('Accept', 'text/plain');
|
xhr.setRequestHeader('Accept', 'text/plain');
|
||||||
@ -681,7 +684,9 @@ function startBlame(blamedataUrl, bUrl) {
|
|||||||
|
|
||||||
// not all browsers call onreadystatechange event on each server flush
|
// not all browsers call onreadystatechange event on each server flush
|
||||||
// poll response using timer every second to handle this issue
|
// poll response using timer every second to handle this issue
|
||||||
pollTimer = setInterval(xhr.onreadystatechange, 1000);
|
xhr.pollTimer = setTimeout(function () {
|
||||||
|
handleResponse(xhr, true);
|
||||||
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* end of blame_incremental.js */
|
/* end of blame_incremental.js */
|
||||||
|
Reference in New Issue
Block a user