(tree, depth)
| 1150 | |
| 1151 | // To ensure we don't grow the revision tree infinitely, we stem old revisions |
| 1152 | function stem(tree, depth) { |
| 1153 | // First we break out the tree into a complete list of root to leaf paths |
| 1154 | var paths = rootToLeaf(tree); |
| 1155 | var stemmedRevs; |
| 1156 | |
| 1157 | var result; |
| 1158 | for (var i = 0, len = paths.length; i < len; i++) { |
| 1159 | // Then for each path, we cut off the start of the path based on the |
| 1160 | // `depth` to stem to, and generate a new set of flat trees |
| 1161 | var path$$1 = paths[i]; |
| 1162 | var stemmed = path$$1.ids; |
| 1163 | var node; |
| 1164 | if (stemmed.length > depth) { |
| 1165 | // only do the stemming work if we actually need to stem |
| 1166 | if (!stemmedRevs) { |
| 1167 | stemmedRevs = {}; // avoid allocating this object unnecessarily |
| 1168 | } |
| 1169 | var numStemmed = stemmed.length - depth; |
| 1170 | node = { |
| 1171 | pos: path$$1.pos + numStemmed, |
| 1172 | ids: pathToTree(stemmed, numStemmed) |
| 1173 | }; |
| 1174 | |
| 1175 | for (var s = 0; s < numStemmed; s++) { |
| 1176 | var rev = (path$$1.pos + s) + '-' + stemmed[s].id; |
| 1177 | stemmedRevs[rev] = true; |
| 1178 | } |
| 1179 | } else { // no need to actually stem |
| 1180 | node = { |
| 1181 | pos: path$$1.pos, |
| 1182 | ids: pathToTree(stemmed, 0) |
| 1183 | }; |
| 1184 | } |
| 1185 | |
| 1186 | // Then we remerge all those flat trees together, ensuring that we don't |
| 1187 | // connect trees that would go beyond the depth limit |
| 1188 | if (result) { |
| 1189 | result = doMerge(result, node, true).tree; |
| 1190 | } else { |
| 1191 | result = [node]; |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | // this is memory-heavy per Chrome profiler, avoid unless we actually stemmed |
| 1196 | if (stemmedRevs) { |
| 1197 | traverseRevTree(result, function (isLeaf, pos, revHash) { |
| 1198 | // some revisions may have been removed in a branch but not in another |
| 1199 | delete stemmedRevs[pos + '-' + revHash]; |
| 1200 | }); |
| 1201 | } |
| 1202 | |
| 1203 | return { |
| 1204 | tree: result, |
| 1205 | revs: stemmedRevs ? Object.keys(stemmedRevs) : [] |
| 1206 | }; |
| 1207 | } |
| 1208 | |
| 1209 | function merge(tree, path$$1, depth) { |
no test coverage detected
searching dependent graphs…