much better test coverage now

This commit is contained in:
Peter Cottle 2012-12-17 22:17:25 -08:00
parent df7e636aa7
commit ee6a81b35c
4 changed files with 168 additions and 70 deletions

View file

@ -5387,7 +5387,7 @@ GitEngine.prototype.exportTree = function() {
GitEngine.prototype.printTree = function(tree) {
tree = tree || this.exportTree();
TreeCompare.prototype.stripTreeFields([tree]);
TreeCompare.prototype.reduceTreeFields([tree]);
var str = JSON.stringify(tree);
if (/'/.test(str)) {
@ -7333,7 +7333,7 @@ TreeCompare.prototype.compareBranchWithinTrees = function(treeA, treeB, branchNa
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
this.stripTreeFields([treeA, treeB]);
this.reduceTreeFields([treeA, treeB]);
// we need a recursive comparison function to bubble up the branch
var recurseCompare = function(commitA, commitB) {
@ -7371,39 +7371,49 @@ TreeCompare.prototype.convertTreeSafe = function(tree) {
return tree;
};
TreeCompare.prototype.stripTreeFields = function(trees) {
var commitStripFields = [
'createTime',
'author',
'commitMessage',
'gitVisuals',
'children',
'visNode',
'type'
];
var branchStripFields = [
'type',
'visBranch'
TreeCompare.prototype.reduceTreeFields = function(trees) {
var commitSaveFields = [
'parents',
'id',
'rootCommit'
];
var commitSortFields = ['children', 'parents'];
var branchSaveFields = [
'target',
'id'
];
var strip = function(objects, stripFields, sortFields) {
_.each(objects, function(obj) {
_.each(stripFields, function(field) {
delete obj[field];
});
_.each(sortFields, function(field) {
if (obj[field]) {
obj[field].sort();
// this function saves only the specified fields of a tree
var saveOnly = function(tree, treeKey, saveFields, sortFields) {
var objects = tree[treeKey];
_.each(objects, function(obj, objKey) {
// our blank slate to copy over
var blank = {};
_.each(saveFields, function(field) {
if (obj[field] !== undefined) {
blank[field] = obj[field];
}
});
_.each(sortFields, function(field) {
// also sort some fields
if (obj[field]) {
obj[field].sort();
blank[field] = obj[field];
}
});
tree[treeKey][objKey] = blank;
});
};
_.each(trees, function(tree) {
strip(tree.commits, commitStripFields, commitSortFields);
strip(tree.branches, branchStripFields);
strip([tree.HEAD], branchStripFields);
saveOnly(tree, 'commits', commitSaveFields, commitSortFields);
saveOnly(tree, 'branches', branchSaveFields);
tree.HEAD = {
target: tree.HEAD.target,
id: tree.HEAD.id
};
});
};
@ -7413,7 +7423,7 @@ TreeCompare.prototype.compareTrees = function(treeA, treeB) {
// now we need to strip out the fields we don't care about, aka things
// like createTime, message, author
this.stripTreeFields([treeA, treeB]);
this.reduceTreeFields([treeA, treeB]);
console.log('comparing tree A', treeA, 'to', treeB);
@ -9767,7 +9777,7 @@ GitEngine.prototype.exportTree = function() {
GitEngine.prototype.printTree = function(tree) {
tree = tree || this.exportTree();
TreeCompare.prototype.stripTreeFields([tree]);
TreeCompare.prototype.reduceTreeFields([tree]);
var str = JSON.stringify(tree);
if (/'/.test(str)) {
@ -11346,7 +11356,7 @@ TreeCompare.prototype.compareBranchWithinTrees = function(treeA, treeB, branchNa
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
this.stripTreeFields([treeA, treeB]);
this.reduceTreeFields([treeA, treeB]);
// we need a recursive comparison function to bubble up the branch
var recurseCompare = function(commitA, commitB) {
@ -11384,39 +11394,49 @@ TreeCompare.prototype.convertTreeSafe = function(tree) {
return tree;
};
TreeCompare.prototype.stripTreeFields = function(trees) {
var commitStripFields = [
'createTime',
'author',
'commitMessage',
'gitVisuals',
'children',
'visNode',
'type'
];
var branchStripFields = [
'type',
'visBranch'
TreeCompare.prototype.reduceTreeFields = function(trees) {
var commitSaveFields = [
'parents',
'id',
'rootCommit'
];
var commitSortFields = ['children', 'parents'];
var branchSaveFields = [
'target',
'id'
];
var strip = function(objects, stripFields, sortFields) {
_.each(objects, function(obj) {
_.each(stripFields, function(field) {
delete obj[field];
});
_.each(sortFields, function(field) {
if (obj[field]) {
obj[field].sort();
// this function saves only the specified fields of a tree
var saveOnly = function(tree, treeKey, saveFields, sortFields) {
var objects = tree[treeKey];
_.each(objects, function(obj, objKey) {
// our blank slate to copy over
var blank = {};
_.each(saveFields, function(field) {
if (obj[field] !== undefined) {
blank[field] = obj[field];
}
});
_.each(sortFields, function(field) {
// also sort some fields
if (obj[field]) {
obj[field].sort();
blank[field] = obj[field];
}
});
tree[treeKey][objKey] = blank;
});
};
_.each(trees, function(tree) {
strip(tree.commits, commitStripFields, commitSortFields);
strip(tree.branches, branchStripFields);
strip([tree.HEAD], branchStripFields);
saveOnly(tree, 'commits', commitSaveFields, commitSortFields);
saveOnly(tree, 'branches', branchSaveFields);
tree.HEAD = {
target: tree.HEAD.target,
id: tree.HEAD.id
};
});
};
@ -11426,7 +11446,7 @@ TreeCompare.prototype.compareTrees = function(treeA, treeB) {
// now we need to strip out the fields we don't care about, aka things
// like createTime, message, author
this.stripTreeFields([treeA, treeB]);
this.reduceTreeFields([treeA, treeB]);
console.log('comparing tree A', treeA, 'to', treeB);