1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Better handling of multiple flow merges

Fixes #2039

Keeps better track of what was merged so a subsequent merge
properly identifies new-vs-old and doesn't remove thinks by mistake
This commit is contained in:
Nick O'Leary 2019-01-30 15:12:01 +00:00
parent 85de227003
commit efe8fbbd11
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -687,7 +687,7 @@ RED.diff = (function() {
diff: remoteDiff
}
}
var selectState = "";
if (conflicted) {
@ -1158,19 +1158,19 @@ RED.diff = (function() {
}
});
return {
var diff = {
currentConfig: currentConfig,
newConfig: newConfig,
added: added,
deleted: deleted,
changed: changed,
moved: moved
}
};
return diff;
}
function resolveDiffs(localDiff,remoteDiff) {
var conflicted = {};
var resolutions = {};
var diff = {
localDiff: localDiff,
remoteDiff: remoteDiff,
@ -1348,7 +1348,7 @@ RED.diff = (function() {
if (node) {
nodeChangedStates[id] = node.changed;
}
localChangedStates[id] = true;
localChangedStates[id] = 1;
newConfig.push(remoteDiff.newConfig.all[id]);
}
} else {
@ -1363,7 +1363,7 @@ RED.diff = (function() {
nodeChangedStates[id] = node.changed;
}
if (!localDiff.added.hasOwnProperty(id)) {
localChangedStates[id] = true;
localChangedStates[id] = 2;
newConfig.push(remoteDiff.newConfig.all[id]);
}
}
@ -1376,24 +1376,42 @@ RED.diff = (function() {
}
function mergeDiff(diff) {
//console.log(diff);
var appliedDiff = applyDiff(diff);
var newConfig = appliedDiff.config;
var nodeChangedStates = appliedDiff.nodeChangedStates;
var localChangedStates = appliedDiff.localChangedStates;
var isDirty = RED.nodes.dirty();
var historyEvent = {
t:"replace",
config: RED.nodes.createCompleteNodeSet(),
changed: nodeChangedStates,
dirty: RED.nodes.dirty(),
dirty: isDirty,
rev: RED.nodes.version()
}
RED.history.push(historyEvent);
var originalFlow = RED.nodes.originalFlow();
// originalFlow is what the editor things it loaded
// - add any newly added nodes from remote diff as they are now part of the record
for (var id in diff.remoteDiff.added) {
if (diff.remoteDiff.added.hasOwnProperty(id)) {
if (diff.remoteDiff.newConfig.all.hasOwnProperty(id)) {
originalFlow.push(JSON.parse(JSON.stringify(diff.remoteDiff.newConfig.all[id])));
}
}
}
RED.nodes.clear();
var imported = RED.nodes.import(newConfig);
// Restore the original flow so subsequent merge resolutions can properly
// identify new-vs-old
RED.nodes.originalFlow(originalFlow);
imported[0].forEach(function(n) {
if (nodeChangedStates[n.id] || localChangedStates[n.id]) {
n.changed = true;
@ -1402,11 +1420,16 @@ RED.diff = (function() {
RED.nodes.version(diff.remoteDiff.rev);
if (isDirty) {
RED.nodes.dirty(true);
}
RED.view.redraw(true);
RED.palette.refresh();
RED.workspaces.refresh();
RED.sidebar.config.refresh();
}
function showTestFlowDiff(index) {
if (index === 1) {
var localFlow = RED.nodes.createCompleteNodeSet();