mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 16:38:50 +02:00
moved another function to graph
This commit is contained in:
parent
c3c3a50bdd
commit
e7d9b76b98
3 changed files with 44 additions and 42 deletions
|
@ -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 = [];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue