think moving method worked

This commit is contained in:
Peter Cottle 2013-10-29 20:53:19 -07:00
parent 5702b08d44
commit f9f9d98628
2 changed files with 97 additions and 8 deletions

View file

@ -210,7 +210,7 @@ GitEngine.prototype.exportTree = function() {
_.each(this.branchCollection.toJSON(), function(branch) { _.each(this.branchCollection.toJSON(), function(branch) {
branch.target = branch.target.get('id'); branch.target = branch.target.get('id');
branch.visBranch = undefined; delete branch.visBranch;
totalExport.branches[branch.id] = branch; totalExport.branches[branch.id] = branch;
}); });
@ -218,7 +218,7 @@ GitEngine.prototype.exportTree = function() {
_.each(this.commitCollection.toJSON(), function(commit) { _.each(this.commitCollection.toJSON(), function(commit) {
// clear out the fields that reference objects and create circular structure // clear out the fields that reference objects and create circular structure
_.each(Commit.prototype.constants.circularFields, function(field) { _.each(Commit.prototype.constants.circularFields, function(field) {
commit[field] = undefined; delete commit[field];
}, this); }, this);
// convert parents // convert parents
@ -239,7 +239,7 @@ GitEngine.prototype.exportTree = function() {
}, this); }, this);
var HEAD = this.HEAD.toJSON(); var HEAD = this.HEAD.toJSON();
HEAD.lastTarget = HEAD.lastLastTarget = HEAD.visBranch = HEAD.visTag =undefined; HEAD.lastTarget = HEAD.lastLastTarget = HEAD.visBranch = HEAD.visTag = undefined;
HEAD.target = HEAD.target.get('id'); HEAD.target = HEAD.target.get('id');
totalExport.HEAD = HEAD; totalExport.HEAD = HEAD;
@ -291,23 +291,23 @@ GitEngine.prototype.instantiateFromTree = function(tree) {
var createdSoFar = {}; var createdSoFar = {};
_.each(tree.commits, function(commitJSON) { _.each(tree.commits, function(commitJSON) {
var commit = this.getOrMakeRecursive(tree, createdSoFar, commitJSON.id); var commit = this.getOrMakeRecursive(tree, createdSoFar, commitJSON.id, this.gitVisuals);
this.commitCollection.add(commit); this.commitCollection.add(commit);
}, this); }, this);
_.each(tree.branches, function(branchJSON) { _.each(tree.branches, function(branchJSON) {
var branch = this.getOrMakeRecursive(tree, createdSoFar, branchJSON.id); var branch = this.getOrMakeRecursive(tree, createdSoFar, branchJSON.id, this.gitVisuals);
this.branchCollection.add(branch, {silent: true}); this.branchCollection.add(branch, {silent: true});
}, this); }, this);
_.each(tree.tags, function(tagJSON) { _.each(tree.tags, function(tagJSON) {
var tag = this.getOrMakeRecursive(tree, createdSoFar, tagJSON.id); var tag = this.getOrMakeRecursive(tree, createdSoFar, tagJSON.id, this.gitVisuals);
this.tagCollection.add(tag, {silent: true}); this.tagCollection.add(tag, {silent: true});
}, this); }, this);
var HEAD = this.getOrMakeRecursive(tree, createdSoFar, tree.HEAD.id); var HEAD = this.getOrMakeRecursive(tree, createdSoFar, tree.HEAD.id, this.gitVisuals);
this.HEAD = HEAD; this.HEAD = HEAD;
this.rootCommit = createdSoFar['C0']; this.rootCommit = createdSoFar['C0'];
@ -482,7 +482,8 @@ GitEngine.prototype.setLocalToTrackRemote = function(localBranch, remoteBranch)
GitEngine.prototype.getOrMakeRecursive = function( GitEngine.prototype.getOrMakeRecursive = function(
tree, tree,
createdSoFar, createdSoFar,
objID objID,
gitVisuals
) { ) {
if (createdSoFar[objID]) { if (createdSoFar[objID]) {
// base case // base case

View file

@ -1,6 +1,94 @@
var _ = require('underscore'); var _ = require('underscore');
var Graph = { var Graph = {
getOrMakeRecursive: function(
tree,
createdSoFar,
objID,
gitVisuals
) {
if (createdSoFar[objID]) {
// base case
return createdSoFar[objID];
}
var getType = function(tree, id) {
if (tree.commits[id]) {
return 'commit';
} else if (tree.branches[id]) {
return 'branch';
} else if (id == 'HEAD') {
return 'HEAD';
} else if (tree.tags[id]) {
return 'tag';
}
throw new Error("bad type for " + id);
};
// figure out what type
var type = getType(tree, objID);
if (type == 'HEAD') {
var headJSON = tree.HEAD;
var HEAD = new Ref(_.extend(
tree.HEAD,
{
target: this.getOrMakeRecursive(tree, createdSoFar, headJSON.target)
}
));
createdSoFar[objID] = HEAD;
return HEAD;
}
if (type == 'branch') {
var branchJSON = tree.branches[objID];
var branch = new Branch(_.extend(
tree.branches[objID],
{
target: this.getOrMakeRecursive(tree, createdSoFar, branchJSON.target)
}
));
createdSoFar[objID] = branch;
return branch;
}
if (type == 'tag') {
var tagJSON = tree.tags[objID];
var tag = new Tag(_.extend(
tree.tags[objID],
{
target: this.getOrMakeRecursive(tree, createdSoFar, tagJSON.target)
}
));
createdSoFar[objID] = tag;
return tag;
}
if (type == 'commit') {
// for commits, we need to grab all the parents
var commitJSON = tree.commits[objID];
var parentObjs = [];
_.each(commitJSON.parents, function(parentID) {
parentObjs.push(this.getOrMakeRecursive(tree, createdSoFar, parentID));
}, this);
var commit = new Commit(_.extend(
commitJSON,
{
parents: parentObjs,
gitVisuals: this.gitVisuals
}
));
createdSoFar[objID] = commit;
return commit;
}
throw new Error('ruh rho!! unsupported type for ' + objID);
},
descendSortDepth: function(objects) { descendSortDepth: function(objects) {
return objects.sort(function(oA, oB) { return objects.sort(function(oA, oB) {
return oB.depth - oA.depth; return oB.depth - oA.depth;