all files / lib/deps/merge/ rootToLeaf.js

100% Statements 21/21
100% Branches 4/4
100% Functions 1/1
100% Lines 21/21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32          20384× 20384× 20384× 20384× 418841× 418841× 418841× 418841× 418841× 418841×   418841× 418841× 418841× 345718×   418841× 198219×     20384×    
"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'];