correctness on fetch

This commit is contained in:
Peter Cottle 2013-09-01 12:16:46 -07:00
parent 7cec1bcaab
commit 9840a5e6b4
5 changed files with 96 additions and 53 deletions

View file

@ -8007,19 +8007,26 @@ GitEngine.prototype.getTargetGraphDifference = function(
} }
// filter because we werent doing graph search // filter because we werent doing graph search
var differenceUnique = this.getUniqueObjects(difference);
return this.descendSortDepth(differenceUnique);
};
GitEngine.prototype.getUniqueObjects = function(objects) {
var unique = {}; var unique = {};
var differenceUnique = []; var result = [];
_.forEach(difference, function(commit) { _.forEach(objects, function(object) {
if (unique[commit.id]) { if (unique[object.id]) {
return; return;
} }
unique[commit.id] = true; unique[object.id] = true;
differenceUnique.push(commit); result.push(object);
}); });
return result;
};
return differenceUnique.sort(function(cA, cB) { GitEngine.prototype.descendSortDepth = function(objects) {
// reverse sort by depth return objects.sort(function(oA, oB) {
return cB.depth - cA.depth; return oB.depth - oA.depth;
}); });
}; };
@ -8133,8 +8140,7 @@ GitEngine.prototype.fetch = function(options) {
); );
}, this); }, this);
// then we get the difference in commits between these two graphs, ordered by // then we get the difference in commits between these two graphs
// depth. TODO -- make work for all branches
var commitsToMake = []; var commitsToMake = [];
_.each(allRemotes, function(localRemoteBranch) { _.each(allRemotes, function(localRemoteBranch) {
commitsToMake = commitsToMake.concat(this.getTargetGraphDifference( commitsToMake = commitsToMake.concat(this.getTargetGraphDifference(
@ -8145,6 +8151,12 @@ GitEngine.prototype.fetch = function(options) {
options options
)); ));
}, this); }, this);
// we did this for each remote branch, but we still need to reduce to unique
// and sort. in this particular app we can never have unfected remote
// commits that are upstream of multiple branches (since the fakeTeamwork
// command simply commits), but we are doing it anyways for correctness
commitsToMake = this.getUniqueObjects(commitsToMake);
commitsToMake = this.descendSortDepth(commitsToMake);
if (commitsToMake.length === 0) { if (commitsToMake.length === 0) {
this.command.addWarning(intl.str( this.command.addWarning(intl.str(
@ -26440,19 +26452,26 @@ GitEngine.prototype.getTargetGraphDifference = function(
} }
// filter because we werent doing graph search // filter because we werent doing graph search
var differenceUnique = this.getUniqueObjects(difference);
return this.descendSortDepth(differenceUnique);
};
GitEngine.prototype.getUniqueObjects = function(objects) {
var unique = {}; var unique = {};
var differenceUnique = []; var result = [];
_.forEach(difference, function(commit) { _.forEach(objects, function(object) {
if (unique[commit.id]) { if (unique[object.id]) {
return; return;
} }
unique[commit.id] = true; unique[object.id] = true;
differenceUnique.push(commit); result.push(object);
}); });
return result;
};
return differenceUnique.sort(function(cA, cB) { GitEngine.prototype.descendSortDepth = function(objects) {
// reverse sort by depth return objects.sort(function(oA, oB) {
return cB.depth - cA.depth; return oB.depth - oA.depth;
}); });
}; };
@ -26566,8 +26585,7 @@ GitEngine.prototype.fetch = function(options) {
); );
}, this); }, this);
// then we get the difference in commits between these two graphs, ordered by // then we get the difference in commits between these two graphs
// depth. TODO -- make work for all branches
var commitsToMake = []; var commitsToMake = [];
_.each(allRemotes, function(localRemoteBranch) { _.each(allRemotes, function(localRemoteBranch) {
commitsToMake = commitsToMake.concat(this.getTargetGraphDifference( commitsToMake = commitsToMake.concat(this.getTargetGraphDifference(
@ -26578,6 +26596,12 @@ GitEngine.prototype.fetch = function(options) {
options options
)); ));
}, this); }, this);
// we did this for each remote branch, but we still need to reduce to unique
// and sort. in this particular app we can never have unfected remote
// commits that are upstream of multiple branches (since the fakeTeamwork
// command simply commits), but we are doing it anyways for correctness
commitsToMake = this.getUniqueObjects(commitsToMake);
commitsToMake = this.descendSortDepth(commitsToMake);
if (commitsToMake.length === 0) { if (commitsToMake.length === 0) {
this.command.addWarning(intl.str( this.command.addWarning(intl.str(
@ -31919,13 +31943,13 @@ _.each(toGlobalize, function(module) {
}); });
$(document).ready(function() { $(document).ready(function() {
window.events = toGlobalize.Main.getEvents(); window.debug_events = toGlobalize.Main.getEvents();
window.eventBaton = toGlobalize.Main.getEventBaton(); window.debug_eventBaton = toGlobalize.Main.getEventBaton();
window.sandbox = toGlobalize.Main.getSandbox(); window.debug_sandbox = toGlobalize.Main.getSandbox();
window.modules = toGlobalize; window.debug_modules = toGlobalize;
window.levelDropdown = toGlobalize.Main.getLevelDropdown(); window.debug_levelDropdown = toGlobalize.Main.getLevelDropdown();
window.under = _; window.debug_under = _;
window.copyTree = function() { window.debug_copyTree = function() {
return toGlobalize.Main.getSandbox().mainVis.gitEngine.printAndCopyTree(); return toGlobalize.Main.getSandbox().mainVis.gitEngine.printAndCopyTree();
}; };
}); });

13
spec/remote.spec.js Normal file
View file

@ -0,0 +1,13 @@
var base = require('./base');
var expectTreeAsync = base.expectTreeAsync;
describe('Git Remotes', function() {
it('clones', function() {
expectTreeAsync(
'git clone',
'{"branches":{"master":{"target":"C1","id":"master"},"o/master":{"target":"C1","id":"o/master"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"HEAD":{"target":"master","id":"HEAD"},"originTree":{"branches":{"master":{"remoteTrackingBranchID":null,"localBranchesThatTrackThis":null,"remote":false,"target":"C1","id":"master","type":"branch"}},"commits":{"C0":{"type":"commit","parents":[],"author":"Peter Cottle","createTime":"Sun Sep 01 2013 11:59:29 GMT-0700 (PDT)","commitMessage":"Quick commit. Go Bears!","id":"C0","rootCommit":true},"C1":{"type":"commit","parents":["C0"],"author":"Peter Cottle","createTime":"Sun Sep 01 2013 11:59:29 GMT-0700 (PDT)","commitMessage":"Quick commit. Go Bears!","id":"C1"}},"HEAD":{"target":"master","id":"HEAD","type":"general ref"}}}'
);
});
});

View file

@ -787,19 +787,26 @@ GitEngine.prototype.getTargetGraphDifference = function(
} }
// filter because we werent doing graph search // filter because we werent doing graph search
var differenceUnique = this.getUniqueObjects(difference);
return this.descendSortDepth(differenceUnique);
};
GitEngine.prototype.getUniqueObjects = function(objects) {
var unique = {}; var unique = {};
var differenceUnique = []; var result = [];
_.forEach(difference, function(commit) { _.forEach(objects, function(object) {
if (unique[commit.id]) { if (unique[object.id]) {
return; return;
} }
unique[commit.id] = true; unique[object.id] = true;
differenceUnique.push(commit); result.push(object);
}); });
return result;
};
return differenceUnique.sort(function(cA, cB) { GitEngine.prototype.descendSortDepth = function(objects) {
// reverse sort by depth return objects.sort(function(oA, oB) {
return cB.depth - cA.depth; return oB.depth - oA.depth;
}); });
}; };
@ -913,8 +920,7 @@ GitEngine.prototype.fetch = function(options) {
); );
}, this); }, this);
// then we get the difference in commits between these two graphs, ordered by // then we get the difference in commits between these two graphs
// depth. TODO -- make work for all branches
var commitsToMake = []; var commitsToMake = [];
_.each(allRemotes, function(localRemoteBranch) { _.each(allRemotes, function(localRemoteBranch) {
commitsToMake = commitsToMake.concat(this.getTargetGraphDifference( commitsToMake = commitsToMake.concat(this.getTargetGraphDifference(
@ -925,6 +931,12 @@ GitEngine.prototype.fetch = function(options) {
options options
)); ));
}, this); }, this);
// we did this for each remote branch, but we still need to reduce to unique
// and sort. in this particular app we can never have unfected remote
// commits that are upstream of multiple branches (since the fakeTeamwork
// command simply commits), but we are doing it anyways for correctness
commitsToMake = this.getUniqueObjects(commitsToMake);
commitsToMake = this.descendSortDepth(commitsToMake);
if (commitsToMake.length === 0) { if (commitsToMake.length === 0) {
this.command.addWarning(intl.str( this.command.addWarning(intl.str(

View file

@ -36,13 +36,13 @@ _.each(toGlobalize, function(module) {
}); });
$(document).ready(function() { $(document).ready(function() {
window.events = toGlobalize.Main.getEvents(); window.debug_events = toGlobalize.Main.getEvents();
window.eventBaton = toGlobalize.Main.getEventBaton(); window.debug_eventBaton = toGlobalize.Main.getEventBaton();
window.sandbox = toGlobalize.Main.getSandbox(); window.debug_sandbox = toGlobalize.Main.getSandbox();
window.modules = toGlobalize; window.debug_modules = toGlobalize;
window.levelDropdown = toGlobalize.Main.getLevelDropdown(); window.debug_levelDropdown = toGlobalize.Main.getLevelDropdown();
window.under = _; window.debug_under = _;
window.copyTree = function() { window.debug_copyTree = function() {
return toGlobalize.Main.getSandbox().mainVis.gitEngine.printAndCopyTree(); return toGlobalize.Main.getSandbox().mainVis.gitEngine.printAndCopyTree();
}; };
}); });

View file

@ -2,17 +2,10 @@ Big Things
~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
[ ] compare settings for a level!!! integrated into builder... [ ] compare settings for a level!!! integrated into builder...
Easier origin things:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ ] then maybe work on remote branches tracking correctly? wut? that means:
- getRemoteBranch has a default (the same name of the branch) but could be different
- git push takes in an argument, and has to check if the remote branch exists, and makes
it otherwise (after pushing)
Origin things: Origin things:
~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
[-] set checkout -b branch __remoteBranch to track the remote branch [ ] polish visual layout
[ ] prototype visual layout (background change + header? maybe...) [ ] importTreeNow fails if origin isnt updated
Medium things: Medium things:
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -37,6 +30,7 @@ Ideas for cleaning
Done things: Done things:
(I only started this on Dec 17th 2012 to get a better sense of what was done) (I only started this on Dec 17th 2012 to get a better sense of what was done)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[x] set checkout -b branch __remoteBranch to track the remote branch
[x] test coverage for hg!!! (in progress) [x] test coverage for hg!!! (in progress)
[x] tree pruning [x] tree pruning
[x] TONS of hg stuff [x] TONS of hg stuff