Skip to content

Commit

Permalink
better tree comparsion from Issue #28
Browse files Browse the repository at this point in the history
  • Loading branch information
pcottle committed Feb 18, 2013
1 parent 2a96052 commit bf6432b
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 36 deletions.
76 changes: 54 additions & 22 deletions build/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6949,13 +6949,18 @@ var Level = Sandbox.extend({
return;
}

// TODO refactor this ugly ass switch statement...
// ok so lets see if they solved it...
var current = this.mainVis.gitEngine.exportTree();
var solved;
if (this.level.compareOnlyMaster) {
solved = this.treeCompare.compareBranchWithinTrees(current, this.level.goalTreeString, 'master');
} else if (this.level.compareOnlyBranches) {
solved = this.treeCompare.compareAllBranchesWithinTrees(current, this.level.goalTreeString);
} else if (this.level.compareAllBranchesHashAgnostic) {
solved = this.treeCompare.compareAllBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString);
} else if (this.level.compareOnlyMasterHashAgnostic) {
solved = this.treeCompare.compareBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString, ['master']);
} else {
solved = this.treeCompare.compareAllBranchesWithinTreesAndHEAD(current, this.level.goalTreeString);
}
Expand Down Expand Up @@ -9640,6 +9645,23 @@ TreeCompare.prototype.compareBranchWithinTrees = function(treeA, treeB, branchNa
};

TreeCompare.prototype.compareAllBranchesWithinTreesHashAgnostic = function(treeA, treeB) {
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
this.reduceTreeFields([treeA, treeB]);

var allBranches = _.extend(
{},
treeA.branches,
treeB.branches
);
var branchNames = [];
_.each(allBranches, function(obj, name) { branchNames.push(name); });
console.log(branchNames);

return this.compareBranchesWithinTreesHashAgnostic(treeA, treeB, branchNames);
};

TreeCompare.prototype.compareBranchesWithinTreesHashAgnostic = function(treeA, treeB, branches) {
// we can't DRY unfortunately here because we need a special _.isEqual function
// for both the recursive compare and the branch compare
treeA = this.convertTreeSafe(treeA);
Expand All @@ -9659,16 +9681,10 @@ TreeCompare.prototype.compareAllBranchesWithinTreesHashAgnostic = function(treeA
// and a function to compare recursively without worrying about hashes
var recurseCompare = this.getRecurseCompareHashAgnostic(treeA, treeB);

var allBranches = _.extend(
{},
treeA.branches,
treeB.branches
);

var result = true;
_.each(allBranches, function(branchObj, branchName) {
branchA = treeA.branches[branchName];
branchB = treeB.branches[branchName];
_.each(branches, function(branchName) {
var branchA = treeA.branches[branchName];
var branchB = treeB.branches[branchName];

result = result && compareBranchObjs(branchA, branchB) &&
recurseCompare(treeA.commits[branchA.target], treeB.commits[branchB.target]);
Expand Down Expand Up @@ -17450,7 +17466,7 @@ require.define("/src/levels/intro/5.js",function(require,module,exports,__dirnam
});

require.define("/src/levels/rebase/1.js",function(require,module,exports,__dirname,__filename,process,global){exports.level = {
"compareOnlyMaster": true,
"compareOnlyMasterHashAgnostic": true,
"disabledMap" : {
"git revert": true
},
Expand Down Expand Up @@ -17482,7 +17498,7 @@ require.define("/src/levels/rebase/1.js",function(require,module,exports,__dirna
});

require.define("/src/levels/rebase/2.js",function(require,module,exports,__dirname,__filename,process,global){exports.level = {
"compareOnlyBranches": true,
"compareAllBranchesHashAgnostic": true,
"disabledMap" : {
"git revert": true
},
Expand Down Expand Up @@ -20994,6 +21010,23 @@ TreeCompare.prototype.compareBranchWithinTrees = function(treeA, treeB, branchNa
};

TreeCompare.prototype.compareAllBranchesWithinTreesHashAgnostic = function(treeA, treeB) {
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
this.reduceTreeFields([treeA, treeB]);

var allBranches = _.extend(
{},
treeA.branches,
treeB.branches
);
var branchNames = [];
_.each(allBranches, function(obj, name) { branchNames.push(name); });
console.log(branchNames);

return this.compareBranchesWithinTreesHashAgnostic(treeA, treeB, branchNames);
};

TreeCompare.prototype.compareBranchesWithinTreesHashAgnostic = function(treeA, treeB, branches) {
// we can't DRY unfortunately here because we need a special _.isEqual function
// for both the recursive compare and the branch compare
treeA = this.convertTreeSafe(treeA);
Expand All @@ -21013,16 +21046,10 @@ TreeCompare.prototype.compareAllBranchesWithinTreesHashAgnostic = function(treeA
// and a function to compare recursively without worrying about hashes
var recurseCompare = this.getRecurseCompareHashAgnostic(treeA, treeB);

var allBranches = _.extend(
{},
treeA.branches,
treeB.branches
);

var result = true;
_.each(allBranches, function(branchObj, branchName) {
branchA = treeA.branches[branchName];
branchB = treeB.branches[branchName];
_.each(branches, function(branchName) {
var branchA = treeA.branches[branchName];
var branchB = treeB.branches[branchName];

result = result && compareBranchObjs(branchA, branchB) &&
recurseCompare(treeA.commits[branchA.target], treeB.commits[branchB.target]);
Expand Down Expand Up @@ -22034,13 +22061,18 @@ var Level = Sandbox.extend({
return;
}

// TODO refactor this ugly ass switch statement...
// ok so lets see if they solved it...
var current = this.mainVis.gitEngine.exportTree();
var solved;
if (this.level.compareOnlyMaster) {
solved = this.treeCompare.compareBranchWithinTrees(current, this.level.goalTreeString, 'master');
} else if (this.level.compareOnlyBranches) {
solved = this.treeCompare.compareAllBranchesWithinTrees(current, this.level.goalTreeString);
} else if (this.level.compareAllBranchesHashAgnostic) {
solved = this.treeCompare.compareAllBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString);
} else if (this.level.compareOnlyMasterHashAgnostic) {
solved = this.treeCompare.compareBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString, ['master']);
} else {
solved = this.treeCompare.compareAllBranchesWithinTreesAndHEAD(current, this.level.goalTreeString);
}
Expand Down Expand Up @@ -29087,7 +29119,7 @@ require.define("/src/levels/mixed/3.js",function(require,module,exports,__dirnam
require("/src/levels/mixed/3.js");

require.define("/src/levels/rebase/1.js",function(require,module,exports,__dirname,__filename,process,global){exports.level = {
"compareOnlyMaster": true,
"compareOnlyMasterHashAgnostic": true,
"disabledMap" : {
"git revert": true
},
Expand Down Expand Up @@ -29120,7 +29152,7 @@ require.define("/src/levels/rebase/1.js",function(require,module,exports,__dirna
require("/src/levels/rebase/1.js");

require.define("/src/levels/rebase/2.js",function(require,module,exports,__dirname,__filename,process,global){exports.level = {
"compareOnlyBranches": true,
"compareAllBranchesHashAgnostic": true,
"disabledMap" : {
"git revert": true
},
Expand Down
1 change: 1 addition & 0 deletions build/bundle.min.09842c9c.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion build/bundle.min.7e188d82.js

This file was deleted.

2 changes: 1 addition & 1 deletion build/bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ <h2>
For a much easier time perusing the source, see the individual files at:
https://github.com/pcottle/learnGitBranching
-->
<script src="build/bundle.min.7e188d82.js"></script>
<script src="build/bundle.min.09842c9c.js"></script>

<!-- The advantage of github pages: super-easy, simple, slick static hostic.
The downside? No raw logs to parse for analytics, so I have to include
Expand Down
29 changes: 20 additions & 9 deletions src/js/git/treeCompare.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ TreeCompare.prototype.compareBranchWithinTrees = function(treeA, treeB, branchNa
};

TreeCompare.prototype.compareAllBranchesWithinTreesHashAgnostic = function(treeA, treeB) {
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
this.reduceTreeFields([treeA, treeB]);

var allBranches = _.extend(
{},
treeA.branches,
treeB.branches
);
var branchNames = [];
_.each(allBranches, function(obj, name) { branchNames.push(name); });
console.log(branchNames);

return this.compareBranchesWithinTreesHashAgnostic(treeA, treeB, branchNames);
};

TreeCompare.prototype.compareBranchesWithinTreesHashAgnostic = function(treeA, treeB, branches) {
// we can't DRY unfortunately here because we need a special _.isEqual function
// for both the recursive compare and the branch compare
treeA = this.convertTreeSafe(treeA);
Expand All @@ -71,16 +88,10 @@ TreeCompare.prototype.compareAllBranchesWithinTreesHashAgnostic = function(treeA
// and a function to compare recursively without worrying about hashes
var recurseCompare = this.getRecurseCompareHashAgnostic(treeA, treeB);

var allBranches = _.extend(
{},
treeA.branches,
treeB.branches
);

var result = true;
_.each(allBranches, function(branchObj, branchName) {
branchA = treeA.branches[branchName];
branchB = treeB.branches[branchName];
_.each(branches, function(branchName) {
var branchA = treeA.branches[branchName];
var branchB = treeB.branches[branchName];

result = result && compareBranchObjs(branchA, branchB) &&
recurseCompare(treeA.commits[branchA.target], treeB.commits[branchB.target]);
Expand Down
5 changes: 5 additions & 0 deletions src/js/level/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,18 @@ var Level = Sandbox.extend({
return;
}

// TODO refactor this ugly ass switch statement...
// ok so lets see if they solved it...
var current = this.mainVis.gitEngine.exportTree();
var solved;
if (this.level.compareOnlyMaster) {
solved = this.treeCompare.compareBranchWithinTrees(current, this.level.goalTreeString, 'master');
} else if (this.level.compareOnlyBranches) {
solved = this.treeCompare.compareAllBranchesWithinTrees(current, this.level.goalTreeString);
} else if (this.level.compareAllBranchesHashAgnostic) {
solved = this.treeCompare.compareAllBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString);
} else if (this.level.compareOnlyMasterHashAgnostic) {
solved = this.treeCompare.compareBranchesWithinTreesHashAgnostic(current, this.level.goalTreeString, ['master']);
} else {
solved = this.treeCompare.compareAllBranchesWithinTreesAndHEAD(current, this.level.goalTreeString);
}
Expand Down
2 changes: 1 addition & 1 deletion src/levels/rebase/1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
exports.level = {
"compareOnlyMaster": true,
"compareOnlyMasterHashAgnostic": true,
"disabledMap" : {
"git revert": true
},
Expand Down
2 changes: 1 addition & 1 deletion src/levels/rebase/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
exports.level = {
"compareOnlyBranches": true,
"compareAllBranchesHashAgnostic": true,
"disabledMap" : {
"git revert": true
},
Expand Down

0 comments on commit bf6432b

Please sign in to comment.