mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-25 15:38:33 +02:00
think moving method worked
This commit is contained in:
parent
5702b08d44
commit
f9f9d98628
2 changed files with 97 additions and 8 deletions
|
@ -210,7 +210,7 @@ GitEngine.prototype.exportTree = function() {
|
|||
|
||||
_.each(this.branchCollection.toJSON(), function(branch) {
|
||||
branch.target = branch.target.get('id');
|
||||
branch.visBranch = undefined;
|
||||
delete branch.visBranch;
|
||||
|
||||
totalExport.branches[branch.id] = branch;
|
||||
});
|
||||
|
@ -218,7 +218,7 @@ GitEngine.prototype.exportTree = function() {
|
|||
_.each(this.commitCollection.toJSON(), function(commit) {
|
||||
// clear out the fields that reference objects and create circular structure
|
||||
_.each(Commit.prototype.constants.circularFields, function(field) {
|
||||
commit[field] = undefined;
|
||||
delete commit[field];
|
||||
}, this);
|
||||
|
||||
// convert parents
|
||||
|
@ -291,23 +291,23 @@ GitEngine.prototype.instantiateFromTree = function(tree) {
|
|||
var createdSoFar = {};
|
||||
|
||||
_.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);
|
||||
|
||||
_.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);
|
||||
|
||||
_.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);
|
||||
|
||||
var HEAD = this.getOrMakeRecursive(tree, createdSoFar, tree.HEAD.id);
|
||||
var HEAD = this.getOrMakeRecursive(tree, createdSoFar, tree.HEAD.id, this.gitVisuals);
|
||||
this.HEAD = HEAD;
|
||||
|
||||
this.rootCommit = createdSoFar['C0'];
|
||||
|
@ -482,7 +482,8 @@ GitEngine.prototype.setLocalToTrackRemote = function(localBranch, remoteBranch)
|
|||
GitEngine.prototype.getOrMakeRecursive = function(
|
||||
tree,
|
||||
createdSoFar,
|
||||
objID
|
||||
objID,
|
||||
gitVisuals
|
||||
) {
|
||||
if (createdSoFar[objID]) {
|
||||
// base case
|
||||
|
|
|
@ -1,6 +1,94 @@
|
|||
var _ = require('underscore');
|
||||
|
||||
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) {
|
||||
return objects.sort(function(oA, oB) {
|
||||
return oB.depth - oA.depth;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue