diff --git a/src/static/js/revisioncache.js b/src/static/js/revisioncache.js index b5d5d2317..4858b846d 100644 --- a/src/static/js/revisioncache.js +++ b/src/static/js/revisioncache.js @@ -214,14 +214,14 @@ $.Class("RevisionCache", var direction = (to.revnum - from.revnum) < 0; var granularity = 0; - console.log("[findpath] from: %d, to: %d", from.revnum, to.revnum); + //console.log("[findpath] from: %d, to: %d", from.revnum, to.revnum); while (current.lt(to, direction) && !found_discontinuity) { - console.log("\t[findPath] while current: ", current.revnum); + //console.log("\t[findPath] while current: ", current.revnum); var delta_revnum = to.revnum - current.revnum; var direction_edges = direction ? current.previous : current.next; for (granularity in Revision.granularities) { if (Math.abs(delta_revnum) >= Revision.granularities[granularity]) { - console.log("\t\t[findPath] for delta: %d, granularity: %d", delta_revnum, Revision.granularities[granularity]); + //console.log("\t\t[findPath] for delta: %d, granularity: %d", delta_revnum, Revision.granularities[granularity]); /* * the delta is larger than the granularity, let's use the granularity *TODO: what happens if we DON'T have the edge? @@ -231,7 +231,7 @@ $.Class("RevisionCache", * from current to that Revision (at the largest possible granularity) */ var edge = direction_edges[granularity]; - console.log("\t\t[findpath] edge:", edge); + //console.log("\t\t[findpath] edge:", edge); if (edge) { // add this edge to our path path.push(edge); @@ -251,7 +251,7 @@ $.Class("RevisionCache", } } - console.log("[findpath] ------------------"); + //console.log("[findpath] ------------------"); // return either a full path, or a path ending as close as we can get to // the target revision. return {path: path, end_revision: current, granularity: granularity}; @@ -296,7 +296,7 @@ $.Class("RevisionCache", console.log(print_path(res.path)); // we can now request changesets from the end of that partial path // to the target: - _this.requestChangesets(res.end_revision, target_revision, res.granularity, partialTransition); + _this.requestChangesets(res.end_revision, target_revision, partialTransition); } partialTransition(from_revnum); @@ -307,12 +307,11 @@ $.Class("RevisionCache", * from the server. * @param {Revision} from - The start revision. * @param {Revision} to - The end revision. - * @param {number} granularity - The granularity at which to request. * @param {function} changesetsProcessed_callback - A callback triggered * when the requested changesets have been * received and processed (added to the graph) */ - requestChangesets: function (from, to, granularity, changesetsProcessed_callback) { + requestChangesets: function (from, to, changesetsProcessed_callback) { console.log("[revisioncache] requestChangesets: %d -> %d", from.revnum, to.revnum); var delta = to.revnum - from.revnum; var sign = delta > 0 ? 1 : -1; @@ -332,26 +331,28 @@ $.Class("RevisionCache", } + var rounddown = function (a, b) { + return Math.floor(a / b) * b; + }; + var roundup = function (a, b) { + return (Math.floor(a / b)+1) * b; + }; //TODO: it might be better to be stricter about start addresses. //At the moment if you request changesets from 2 -> 12, it will request at granularity 10. //Not sure if we shouldn't only request granularities > 1 when we have a strict multiple of 10,100 etc. //This is compounded by the fact that revisions are 1 based! - /* - *for (var g in Revision.granularities) { - * var granularity = Revision.granularities[g]; - * var num = Math.floor(adelta / granularity); - * adelta = adelta % granularity; - * if (num) { - * this.loader.enqueue(start, granularity, process_received_changesets); - * start = start + (num * granularity); - * } - *} - *if (adelta) { - * //Something went wrong! - *} - */ - console.log(start, granularity); - this.loader.enqueue(start, Revision.granularities[granularity], process_received_changesets); + //console.log("[requestChangesets] start: %d, end: %d, delta: %d, adelta: %d", start, end, delta, adelta); + for (var g in Revision.granularities) { + var granularity = Revision.granularities[g]; + var remainder = Math.floor(adelta / granularity); + //console.log("\t[requestChangesets] start: %d, granularity: %d, adelta: %d, //: %d", start, granularity, adelta, remainder); + //console.log("\t rounddown delta: %d, start: %d", rounddown(adelta, granularity), rounddown(start, granularity)); + if (remainder) { + //this.loader.enqueue(start, granularity, process_received_changesets); + //console.log("\t[requestChangesets] REQUEST start: %d, end: %d, granularity: %d", rounddown(start, granularity), roundup(adelta, granularity), granularity); + this.loader.enqueue(rounddown(start, granularity), granularity, process_received_changesets); + } + } }, } ); @@ -537,7 +538,7 @@ var domline = require("./domline").domline; var linestylefilter = require("./linestylefilter").linestylefilter; $.Class("PadClient", {//static - USE_COMPOSE: true, + USE_COMPOSE: false, }, {//instance /** @@ -592,18 +593,19 @@ $.Class("PadClient", this.revisionCache.transition(this.revision.revnum, revnum, function (path) { console.log("[padclient > applyChangeset_callback] path:", path); var time = _this.timestamp; + var p, changeset = null; //pre-declare, because they're used in both blocks. if (PadClient.USE_COMPOSE) { var composed = path[0]; var _path = path.slice(1); - for (var p in _path) { - var changeset = _path[p]; + for (p in _path) { + changeset = _path[p]; composed = composed.compose(changeset, _this); } composed.apply(_this); time += composed.deltatime * 1000; } else { // Don't compose, just apply - for (var p in path) { - var changeset = path[p]; + for (p in path) { + changeset = path[p]; time += changeset.deltatime * 1000; changeset.apply(_this); }