in client/src/components/versioned-storages/vs-actions/components/conflicts/utilities/analyze-conflicts.js [107:209]
function processDiffs (contents, head, remote, mergeInProgress) {
const list = parse(contents, mergeInProgress);
const headRest = (head || []).slice();
const remoteRest = (remote || []).slice();
const modificationsAreTheSame = (a, b) => {
return !!a && !!b && a.origin === b.origin && a.content === b.content;
};
const performInsertion = (line, ...branches) => {
list.markLineAsInserted(line, ...branches);
};
const performDeletion = (line, content, ...branches) => {
const inserted = list.insertLineBefore(line, content, {}, ...branches);
if (inserted) {
list.markLineAsRemoved(inserted, ...branches);
}
};
const performModification = (line, modification, ...branches) => {
if (modification.origin === '+') {
performInsertion(line, ...branches);
} else {
performDeletion(line, modification.content, ...branches);
}
};
while (headRest.length > 0 || remoteRest.length > 0) {
const headModification = headRest[0];
const remoteModification = remoteRest[0];
let headLine, remoteLine;
if (headModification) {
if (headModification.origin === '+') {
headLine = list.getLineAtIndex(HeadBranch, headModification.new_lineno);
} else if (headModification.origin === '-') {
headLine = list.getLineAtOriginalIndex(
HeadBranch,
headModification.old_lineno
);
}
}
if (remoteModification) {
if (remoteModification.origin === '+') {
remoteLine = list.getLineAtIndex(RemoteBranch, remoteModification.new_lineno);
} else if (remoteModification.origin === '-') {
remoteLine = list.getLineAtOriginalIndex(
RemoteBranch,
remoteModification.old_lineno
);
}
}
let sameModifications = false;
let performHead = false;
let performRemote = false;
if (remoteLine && headLine) {
sameModifications = remoteLine === headLine &&
modificationsAreTheSame(headModification, remoteModification);
const headIsParent = headLine.isParentFor(remoteLine);
const remoteIsParent = headIsParent ? false : remoteLine.isParentFor(headLine);
if (!headIsParent && !remoteIsParent) {
// we're at conflicting branches; both modifications can be performed
// (as they will be skipped)
performHead = true;
performRemote = true;
} else {
performHead = headIsParent;
performRemote = remoteIsParent;
}
} else {
performHead = !!headLine;
performRemote = !!remoteLine;
}
if (sameModifications) {
performModification(
remoteLine,
remoteModification,
HeadBranch,
RemoteBranch
);
headRest.splice(0, 1);
remoteRest.splice(0, 1);
} else {
if (performHead) {
performModification(
headLine,
headModification,
HeadBranch
);
headRest.splice(0, 1);
}
if (performRemote) {
performModification(remoteLine, remoteModification, RemoteBranch);
remoteRest.splice(0, 1);
}
if (!performHead && !performRemote) {
headRest.splice(0, 1);
remoteRest.splice(0, 1);
}
}
}
prepareConflicts(list);
list.preProcessLines(HeadBranch);
list.preProcessLines(RemoteBranch);
list.preProcessLines(Merged);
prepareChanges(list);
return list;
}