moved another function to graph

This commit is contained in:
Peter Cottle 2013-12-23 10:15:16 -08:00
parent c3c3a50bdd
commit e7d9b76b98
3 changed files with 44 additions and 42 deletions

View file

@ -6,7 +6,14 @@ var Branch = Git.Branch;
var Tag = Git.Tag;
var Ref = Git.Ref;
function invariant(truthy, reason) {
if (!truthy) {
throw new Error(reason);
}
}
var Graph = {
getOrMakeRecursive: function(
tree,
createdSoFar,
@ -118,6 +125,30 @@ var Graph = {
return result;
},
getUpstreamSet: function(engine, ancestor) {
invariant(typeof ancestor === 'string', 'pass in string');
var commit = engine.getCommitFromRef(ancestor);
var ancestorID = commit.get('id');
var queue = [commit];
var exploredSet = {};
exploredSet[ancestorID] = true;
var addToExplored = function(rent) {
exploredSet[rent.get('id')] = true;
queue.push(rent);
};
while (queue.length) {
var here = queue.pop();
var rents = here.get('parents');
_.each(rents, addToExplored);
}
return exploredSet;
},
getUniqueObjects: function(objects) {
var unique = {};
var result = [];