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

@ -27,12 +27,6 @@ function catchShortCircuit(err) {
}
}
function invariant(truthy, reason) {
if (!truthy) {
throw new Error(reason);
}
}
function GitEngine(options) {
this.rootCommit = null;
this.refs = {};
@ -174,7 +168,7 @@ GitEngine.prototype.exportTreeForBranch = function(branchName) {
// is not connected to branchname
var tree = this.exportTree();
// get the upstream set
var set = this.getUpstreamSet(branchName);
var set = Graph.getUpstreamSet(this, branchName);
// now loop through and delete commits
var commitsToLoop = tree.commits;
tree.commits = {};
@ -934,7 +928,7 @@ GitEngine.prototype.checkUpstreamOfSource = function(
// target. Hence target should be strictly upstream of source
// lets first get the upstream set from source's dest branch
var upstream = source.getUpstreamSet(sourceBranch);
var upstream = Graph.getUpstreamSet(source, sourceBranch);
var targetLocationID = target.getCommitFromRef(targetBranch).get('id');
if (!upstream[targetLocationID]) {
@ -954,7 +948,7 @@ GitEngine.prototype.getTargetGraphDifference = function(
options = options || {};
sourceBranch = source.resolveID(sourceBranch);
var targetSet = target.getUpstreamSet(targetBranch);
var targetSet = Graph.getUpstreamSet(target, targetBranch);
var sourceStartCommit = source.getCommitFromRef(sourceBranch);
var sourceTree = source.exportTree();
@ -1707,7 +1701,7 @@ GitEngine.prototype.pruneTreeAndPlay = function() {
GitEngine.prototype.pruneTree = function() {
var set = this.getUpstreamBranchSet();
// dont prune commits that HEAD depends on
var headSet = this.getUpstreamSet('HEAD');
var headSet = Graph.getUpstreamSet(this, 'HEAD');
_.each(headSet, function(val, commitID) {
set[commitID] = true;
});
@ -1802,7 +1796,7 @@ GitEngine.prototype.getUpstreamCollectionSet = function(collection) {
};
GitEngine.prototype.getUpstreamHeadSet = function() {
var set = this.getUpstreamSet('HEAD');
var set = Graph.getUpstreamSet(this, 'HEAD');
var including = this.getCommitFromRef('HEAD').get('id');
set[including] = true;
@ -1950,7 +1944,7 @@ GitEngine.prototype.hgRebase = function(destination, base) {
// we need everything BELOW ourselves...
var downstream = this.getDownstreamSet(base);
// and we need to go upwards to the stop set
var stopSet = this.getUpstreamSet(destination);
var stopSet = Graph.getUpstreamSet(this, destination);
var upstream = this.getUpstreamDiffSetFromSet(stopSet, base);
// and NOWWWwwww get all the descendants of this set
@ -2032,7 +2026,7 @@ GitEngine.prototype.rebase = function(targetSource, currentLocation, options) {
// then we BFS from currentLocation, using the downstream set as our stopping point.
// we need to BFS because we need to include all commits below
// pop these commits on top of targetSource and modify their ids with quotes
var stopSet = this.getUpstreamSet(targetSource);
var stopSet = Graph.getUpstreamSet(this, targetSource);
var toRebaseRough = this.getUpstreamDiffFromSet(stopSet, currentLocation);
return this.rebaseFinish(toRebaseRough, stopSet, targetSource, currentLocation, options);
};
@ -2064,7 +2058,7 @@ GitEngine.prototype.rebaseInteractive = function(targetSource, currentLocation,
}
// now get the stop set
var stopSet = this.getUpstreamSet(targetSource);
var stopSet = Graph.getUpstreamSet(this, targetSource);
var toRebaseRough = [];
// standard BFS
@ -2567,7 +2561,7 @@ GitEngine.prototype.status = function() {
GitEngine.prototype.logWithout = function(ref, omitBranch) {
// slice off the ^branch
omitBranch = omitBranch.slice(1);
this.log(ref, this.getUpstreamSet(omitBranch));
this.log(ref, Graph.getUpstreamSet(this, omitBranch));
};
GitEngine.prototype.log = function(ref, omitSet) {
@ -2612,7 +2606,7 @@ GitEngine.prototype.getCommonAncestor = function(ancestor, cousin) {
throw new Error('Dont use common ancestor if we are upstream!');
}
var upstreamSet = this.getUpstreamSet(ancestor);
var upstreamSet = Graph.getUpstreamSet(this, ancestor);
// now BFS off of cousin until you find something
var queue = [this.getCommitFromRef(cousin)];
@ -2631,7 +2625,7 @@ GitEngine.prototype.isUpstreamOf = function(child, ancestor) {
// basically just do a completely BFS search on ancestor to the root, then
// check for membership of child in that set of explored nodes
var upstream = this.getUpstreamSet(ancestor);
var upstream = Graph.getUpstreamSet(this, ancestor);
return upstream[child.get('id')] !== undefined;
};
@ -2658,29 +2652,6 @@ GitEngine.prototype.getDownstreamSet = function(ancestor) {
return exploredSet;
};
GitEngine.prototype.getUpstreamSet = function(ancestor) {
var commit = this.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;
};
var Ref = Backbone.Model.extend({
initialize: function() {
if (!this.get('target')) {
@ -2741,7 +2712,6 @@ var Branch = Ref.extend({
*
* With that in mind, we change our branch model to support the following
*/
setRemoteTrackingBranchID: function(id) {
this.set('remoteTrackingBranchID', id);
},