"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
// build up a list of all the paths to the leafs in this revision tree
function rootToLeaf(revs) {
var paths = [];
var toVisit = revs.slice();
var node;
while (node = toVisit.pop()) {
var pos = node.pos;
var tree = node.ids;
var id = tree[0];
var opts = tree[1];
var branches = tree[2];
var isLeaf = branches.length === 0;
var history = node.history ? node.history.slice() : [];
history.push({ id: id, opts: opts });
if (isLeaf) {
paths.push({ pos: pos + 1 - history.length, ids: history });
}
for (var i = 0, len = branches.length; i < len; i++) {
toVisit.push({ pos: pos + 1, ids: branches[i], history: history });
}
}
return paths.reverse();
}
exports.default = rootToLeaf;
module.exports = exports['default']; |