Prune images that are only referenced by tags which are not currently alive.

This commit is contained in:
Jake Moshenko 2015-02-11 16:24:19 -05:00
parent f32bd748e4
commit d81e6c7a4d

View file

@ -485,6 +485,9 @@ ImageHistoryTree.prototype.buildRoot_ = function() {
maxChildHeight = Math.max(maxChildHeight, key);
});
// Recursively prune the nodes that are not referenced by a tag
this.pruneUnreferenced_(root);
// Compact the graph so that any single chain of three (or more) images becomes a collapsed
// section. We only do this if the max width is > 1 (since for a single width tree, no long
// chain will hide a branch).
@ -505,6 +508,23 @@ ImageHistoryTree.prototype.buildRoot_ = function() {
};
/**
* Prunes images which are not referenced either directly or indireclty by any tag.
*/
ImageHistoryTree.prototype.pruneUnreferenced_ = function(node) {
if (node.children) {
var surviving_children = []
for (var i = 0; i < node.children.length; ++i) {
if (!this.pruneUnreferenced_(node.children[i])) {
surviving_children.push(node.children[i]);
}
}
node.children = surviving_children;
}
return (node.children.length == 0 && node.tags.length == 0);
};
/**
* Determines the height of the tree at its longest chain.
*/