mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 00:18:56 +02:00
finally got one unit test for git down. pretty cool actually
This commit is contained in:
parent
822ed2e7fa
commit
620b438c5b
2 changed files with 91 additions and 27 deletions
|
@ -7372,20 +7372,38 @@ TreeCompare.prototype.convertTreeSafe = function(tree) {
|
||||||
};
|
};
|
||||||
|
|
||||||
TreeCompare.prototype.stripTreeFields = function(trees) {
|
TreeCompare.prototype.stripTreeFields = function(trees) {
|
||||||
var stripFields = ['createTime', 'author', 'commitMessage'];
|
var commitStripFields = [
|
||||||
var sortFields = ['children', 'parents'];
|
'createTime',
|
||||||
|
'author',
|
||||||
|
'commitMessage',
|
||||||
|
'gitVisuals',
|
||||||
|
'children',
|
||||||
|
'visNode',
|
||||||
|
'type'
|
||||||
|
];
|
||||||
|
var branchStripFields = [
|
||||||
|
'type',
|
||||||
|
'visBranch'
|
||||||
|
];
|
||||||
|
var commitSortFields = ['children', 'parents'];
|
||||||
|
|
||||||
_.each(trees, function(tree) {
|
var strip = function(objects, stripFields, sortFields) {
|
||||||
_.each(tree.commits, function(commit) {
|
_.each(objects, function(obj) {
|
||||||
_.each(stripFields, function(field) {
|
_.each(stripFields, function(field) {
|
||||||
commit[field] = undefined;
|
delete obj[field];
|
||||||
});
|
});
|
||||||
_.each(sortFields, function(field) {
|
_.each(sortFields, function(field) {
|
||||||
if (commit[field]) {
|
if (obj[field]) {
|
||||||
commit[field] = commit[field].sort();
|
obj[field].sort();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
_.each(trees, function(tree) {
|
||||||
|
strip(tree.commits, commitStripFields, commitSortFields);
|
||||||
|
strip(tree.branches, branchStripFields);
|
||||||
|
strip([tree.HEAD], branchStripFields);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11367,20 +11385,38 @@ TreeCompare.prototype.convertTreeSafe = function(tree) {
|
||||||
};
|
};
|
||||||
|
|
||||||
TreeCompare.prototype.stripTreeFields = function(trees) {
|
TreeCompare.prototype.stripTreeFields = function(trees) {
|
||||||
var stripFields = ['createTime', 'author', 'commitMessage'];
|
var commitStripFields = [
|
||||||
var sortFields = ['children', 'parents'];
|
'createTime',
|
||||||
|
'author',
|
||||||
|
'commitMessage',
|
||||||
|
'gitVisuals',
|
||||||
|
'children',
|
||||||
|
'visNode',
|
||||||
|
'type'
|
||||||
|
];
|
||||||
|
var branchStripFields = [
|
||||||
|
'type',
|
||||||
|
'visBranch'
|
||||||
|
];
|
||||||
|
var commitSortFields = ['children', 'parents'];
|
||||||
|
|
||||||
_.each(trees, function(tree) {
|
var strip = function(objects, stripFields, sortFields) {
|
||||||
_.each(tree.commits, function(commit) {
|
_.each(objects, function(obj) {
|
||||||
_.each(stripFields, function(field) {
|
_.each(stripFields, function(field) {
|
||||||
commit[field] = undefined;
|
delete obj[field];
|
||||||
});
|
});
|
||||||
_.each(sortFields, function(field) {
|
_.each(sortFields, function(field) {
|
||||||
if (commit[field]) {
|
if (obj[field]) {
|
||||||
commit[field] = commit[field].sort();
|
obj[field].sort();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
_.each(trees, function(tree) {
|
||||||
|
strip(tree.commits, commitStripFields, commitSortFields);
|
||||||
|
strip(tree.branches, branchStripFields);
|
||||||
|
strip([tree.HEAD], branchStripFields);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ TreeCompare.prototype.compareBranchWithinTrees = function(treeA, treeB, branchNa
|
||||||
treeA = this.convertTreeSafe(treeA);
|
treeA = this.convertTreeSafe(treeA);
|
||||||
treeB = this.convertTreeSafe(treeB);
|
treeB = this.convertTreeSafe(treeB);
|
||||||
|
|
||||||
this.stripTreeFields([treeA, treeB]);
|
this.reduceTreeFields([treeA, treeB]);
|
||||||
|
|
||||||
// we need a recursive comparison function to bubble up the branch
|
// we need a recursive comparison function to bubble up the branch
|
||||||
var recurseCompare = function(commitA, commitB) {
|
var recurseCompare = function(commitA, commitB) {
|
||||||
|
@ -56,21 +56,49 @@ TreeCompare.prototype.convertTreeSafe = function(tree) {
|
||||||
return tree;
|
return tree;
|
||||||
};
|
};
|
||||||
|
|
||||||
TreeCompare.prototype.stripTreeFields = function(trees) {
|
TreeCompare.prototype.reduceTreeFields = function(trees) {
|
||||||
var stripFields = ['createTime', 'author', 'commitMessage'];
|
var commitSaveFields = [
|
||||||
var sortFields = ['children', 'parents'];
|
'parents',
|
||||||
|
'id',
|
||||||
|
'rootCommit'
|
||||||
|
];
|
||||||
|
var commitSortFields = ['children', 'parents'];
|
||||||
|
var branchSaveFields = [
|
||||||
|
'target',
|
||||||
|
'id'
|
||||||
|
];
|
||||||
|
|
||||||
_.each(trees, function(tree) {
|
// this function saves only the specified fields of a tree
|
||||||
_.each(tree.commits, function(commit) {
|
var saveOnly = function(tree, treeKey, saveFields, sortFields) {
|
||||||
_.each(stripFields, function(field) {
|
var objects = tree[treeKey];
|
||||||
commit[field] = undefined;
|
_.each(objects, function(obj, objKey) {
|
||||||
});
|
// our blank slate to copy over
|
||||||
_.each(sortFields, function(field) {
|
var blank = {};
|
||||||
if (commit[field]) {
|
_.each(saveFields, function(field) {
|
||||||
commit[field] = commit[field].sort();
|
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) {
|
||||||
|
saveOnly(tree, 'commits', commitSaveFields, commitSortFields);
|
||||||
|
saveOnly(tree, 'branches', branchSaveFields);
|
||||||
|
|
||||||
|
tree.HEAD = {
|
||||||
|
target: tree.HEAD.target,
|
||||||
|
id: tree.HEAD.id
|
||||||
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -80,7 +108,7 @@ TreeCompare.prototype.compareTrees = function(treeA, treeB) {
|
||||||
|
|
||||||
// now we need to strip out the fields we don't care about, aka things
|
// now we need to strip out the fields we don't care about, aka things
|
||||||
// like createTime, message, author
|
// like createTime, message, author
|
||||||
this.stripTreeFields([treeA, treeB]);
|
this.reduceTreeFields([treeA, treeB]);
|
||||||
|
|
||||||
console.log('comparing tree A', treeA, 'to', treeB);
|
console.log('comparing tree A', treeA, 'to', treeB);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue