| 953 | |
| 954 | // build up a list of all the paths to the leafs in this revision tree |
| 955 | function rootToLeaf(revs) { |
| 956 | var paths = []; |
| 957 | var toVisit = revs.slice(); |
| 958 | var node; |
| 959 | while ((node = toVisit.pop())) { |
| 960 | var pos = node.pos; |
| 961 | var tree = node.ids; |
| 962 | var id = tree[0]; |
| 963 | var opts = tree[1]; |
| 964 | var branches = tree[2]; |
| 965 | var isLeaf = branches.length === 0; |
| 966 | |
| 967 | var history = node.history ? node.history.slice() : []; |
| 968 | history.push({id, opts}); |
| 969 | if (isLeaf) { |
| 970 | paths.push({pos: (pos + 1 - history.length), ids: history}); |
| 971 | } |
| 972 | for (var i = 0, len = branches.length; i < len; i++) { |
| 973 | toVisit.push({pos: pos + 1, ids: branches[i], history}); |
| 974 | } |
| 975 | } |
| 976 | return paths.reverse(); |
| 977 | } |
| 978 | |
| 979 | // for a better overview of what this is doing, read: |
| 980 | |