mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-25 07:28:35 +02:00
[TargetSetDifference] Sort commits by dependencies Resolves #223
This commit is contained in:
parent
37a792db5e
commit
7b687ab6da
1 changed files with 37 additions and 1 deletions
|
@ -997,7 +997,43 @@ GitEngine.prototype.getTargetGraphDifference = function(
|
|||
|
||||
// filter because we werent doing graph search
|
||||
var differenceUnique = Graph.getUniqueObjects(difference);
|
||||
return Graph.descendSortDepth(differenceUnique);
|
||||
/**
|
||||
* Ok now we have to determine the order in which to make these commits.
|
||||
* We used to just sort by depth because we were lazy but that is incorrect
|
||||
* since it doesnt represent the actual dependency tree of the commits.
|
||||
*
|
||||
* So here is what we are going to do -- loop through the differenceUnique
|
||||
* set and find a commit that has _all_ its parents in the targetSet. Then
|
||||
* decide to make that commit first, expand targetSet, and then rinse & repeat
|
||||
*/
|
||||
var inOrder = [];
|
||||
var allParentsMade = function(node) {
|
||||
var allParents = true;
|
||||
node.parents.forEach(function(parent) {
|
||||
allParents = allParents && targetSet[parent];
|
||||
});
|
||||
return allParents;
|
||||
};
|
||||
|
||||
while (differenceUnique.length) {
|
||||
for (var i = 0; i < differenceUnique.length; i++) {
|
||||
if (!allParentsMade(differenceUnique[i])) {
|
||||
// This commit cannot be made since not all of its dependencies are
|
||||
// satisfied.
|
||||
continue;
|
||||
}
|
||||
|
||||
var makeThis = differenceUnique[i];
|
||||
inOrder.push(makeThis);
|
||||
// remove the commit
|
||||
differenceUnique.splice(i, 1);
|
||||
// expand target set
|
||||
targetSet[makeThis.id] = true;
|
||||
// start over
|
||||
break;
|
||||
}
|
||||
}
|
||||
return inOrder;
|
||||
};
|
||||
|
||||
GitEngine.prototype.push = function(options) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue