You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
536 lines
51 KiB
536 lines
51 KiB
|
2 months ago
|
/*istanbul ignore start*/
|
||
|
|
"use strict";
|
||
|
|
|
||
|
|
Object.defineProperty(exports, "__esModule", {
|
||
|
|
value: true
|
||
|
|
});
|
||
|
|
exports.calcLineCount = calcLineCount;
|
||
|
|
exports.merge = merge;
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
var
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_create = require("./create")
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
;
|
||
|
|
var
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_parse = require("./parse")
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
;
|
||
|
|
var
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_array = require("../util/array")
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
;
|
||
|
|
/*istanbul ignore start*/ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
||
|
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
||
|
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
||
|
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
||
|
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
||
|
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
function calcLineCount(hunk) {
|
||
|
|
var
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_calcOldNewLineCount =
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
calcOldNewLineCount(hunk.lines),
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
oldLines = _calcOldNewLineCount.oldLines,
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
newLines = _calcOldNewLineCount.newLines;
|
||
|
|
if (oldLines !== undefined) {
|
||
|
|
hunk.oldLines = oldLines;
|
||
|
|
} else {
|
||
|
|
delete hunk.oldLines;
|
||
|
|
}
|
||
|
|
if (newLines !== undefined) {
|
||
|
|
hunk.newLines = newLines;
|
||
|
|
} else {
|
||
|
|
delete hunk.newLines;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
function merge(mine, theirs, base) {
|
||
|
|
mine = loadPatch(mine, base);
|
||
|
|
theirs = loadPatch(theirs, base);
|
||
|
|
var ret = {};
|
||
|
|
|
||
|
|
// For index we just let it pass through as it doesn't have any necessary meaning.
|
||
|
|
// Leaving sanity checks on this to the API consumer that may know more about the
|
||
|
|
// meaning in their own context.
|
||
|
|
if (mine.index || theirs.index) {
|
||
|
|
ret.index = mine.index || theirs.index;
|
||
|
|
}
|
||
|
|
if (mine.newFileName || theirs.newFileName) {
|
||
|
|
if (!fileNameChanged(mine)) {
|
||
|
|
// No header or no change in ours, use theirs (and ours if theirs does not exist)
|
||
|
|
ret.oldFileName = theirs.oldFileName || mine.oldFileName;
|
||
|
|
ret.newFileName = theirs.newFileName || mine.newFileName;
|
||
|
|
ret.oldHeader = theirs.oldHeader || mine.oldHeader;
|
||
|
|
ret.newHeader = theirs.newHeader || mine.newHeader;
|
||
|
|
} else if (!fileNameChanged(theirs)) {
|
||
|
|
// No header or no change in theirs, use ours
|
||
|
|
ret.oldFileName = mine.oldFileName;
|
||
|
|
ret.newFileName = mine.newFileName;
|
||
|
|
ret.oldHeader = mine.oldHeader;
|
||
|
|
ret.newHeader = mine.newHeader;
|
||
|
|
} else {
|
||
|
|
// Both changed... figure it out
|
||
|
|
ret.oldFileName = selectField(ret, mine.oldFileName, theirs.oldFileName);
|
||
|
|
ret.newFileName = selectField(ret, mine.newFileName, theirs.newFileName);
|
||
|
|
ret.oldHeader = selectField(ret, mine.oldHeader, theirs.oldHeader);
|
||
|
|
ret.newHeader = selectField(ret, mine.newHeader, theirs.newHeader);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
ret.hunks = [];
|
||
|
|
var mineIndex = 0,
|
||
|
|
theirsIndex = 0,
|
||
|
|
mineOffset = 0,
|
||
|
|
theirsOffset = 0;
|
||
|
|
while (mineIndex < mine.hunks.length || theirsIndex < theirs.hunks.length) {
|
||
|
|
var mineCurrent = mine.hunks[mineIndex] || {
|
||
|
|
oldStart: Infinity
|
||
|
|
},
|
||
|
|
theirsCurrent = theirs.hunks[theirsIndex] || {
|
||
|
|
oldStart: Infinity
|
||
|
|
};
|
||
|
|
if (hunkBefore(mineCurrent, theirsCurrent)) {
|
||
|
|
// This patch does not overlap with any of the others, yay.
|
||
|
|
ret.hunks.push(cloneHunk(mineCurrent, mineOffset));
|
||
|
|
mineIndex++;
|
||
|
|
theirsOffset += mineCurrent.newLines - mineCurrent.oldLines;
|
||
|
|
} else if (hunkBefore(theirsCurrent, mineCurrent)) {
|
||
|
|
// This patch does not overlap with any of the others, yay.
|
||
|
|
ret.hunks.push(cloneHunk(theirsCurrent, theirsOffset));
|
||
|
|
theirsIndex++;
|
||
|
|
mineOffset += theirsCurrent.newLines - theirsCurrent.oldLines;
|
||
|
|
} else {
|
||
|
|
// Overlap, merge as best we can
|
||
|
|
var mergedHunk = {
|
||
|
|
oldStart: Math.min(mineCurrent.oldStart, theirsCurrent.oldStart),
|
||
|
|
oldLines: 0,
|
||
|
|
newStart: Math.min(mineCurrent.newStart + mineOffset, theirsCurrent.oldStart + theirsOffset),
|
||
|
|
newLines: 0,
|
||
|
|
lines: []
|
||
|
|
};
|
||
|
|
mergeLines(mergedHunk, mineCurrent.oldStart, mineCurrent.lines, theirsCurrent.oldStart, theirsCurrent.lines);
|
||
|
|
theirsIndex++;
|
||
|
|
mineIndex++;
|
||
|
|
ret.hunks.push(mergedHunk);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return ret;
|
||
|
|
}
|
||
|
|
function loadPatch(param, base) {
|
||
|
|
if (typeof param === 'string') {
|
||
|
|
if (/^@@/m.test(param) || /^Index:/m.test(param)) {
|
||
|
|
return (
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
(0,
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_parse
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
.
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
parsePatch)
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
(param)[0]
|
||
|
|
);
|
||
|
|
}
|
||
|
|
if (!base) {
|
||
|
|
throw new Error('Must provide a base reference or pass in a patch');
|
||
|
|
}
|
||
|
|
return (
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
(0,
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_create
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
.
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
structuredPatch)
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
(undefined, undefined, base, param)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
return param;
|
||
|
|
}
|
||
|
|
function fileNameChanged(patch) {
|
||
|
|
return patch.newFileName && patch.newFileName !== patch.oldFileName;
|
||
|
|
}
|
||
|
|
function selectField(index, mine, theirs) {
|
||
|
|
if (mine === theirs) {
|
||
|
|
return mine;
|
||
|
|
} else {
|
||
|
|
index.conflict = true;
|
||
|
|
return {
|
||
|
|
mine: mine,
|
||
|
|
theirs: theirs
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|
||
|
|
function hunkBefore(test, check) {
|
||
|
|
return test.oldStart < check.oldStart && test.oldStart + test.oldLines < check.oldStart;
|
||
|
|
}
|
||
|
|
function cloneHunk(hunk, offset) {
|
||
|
|
return {
|
||
|
|
oldStart: hunk.oldStart,
|
||
|
|
oldLines: hunk.oldLines,
|
||
|
|
newStart: hunk.newStart + offset,
|
||
|
|
newLines: hunk.newLines,
|
||
|
|
lines: hunk.lines
|
||
|
|
};
|
||
|
|
}
|
||
|
|
function mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) {
|
||
|
|
// This will generally result in a conflicted hunk, but there are cases where the context
|
||
|
|
// is the only overlap where we can successfully merge the content here.
|
||
|
|
var mine = {
|
||
|
|
offset: mineOffset,
|
||
|
|
lines: mineLines,
|
||
|
|
index: 0
|
||
|
|
},
|
||
|
|
their = {
|
||
|
|
offset: theirOffset,
|
||
|
|
lines: theirLines,
|
||
|
|
index: 0
|
||
|
|
};
|
||
|
|
|
||
|
|
// Handle any leading content
|
||
|
|
insertLeading(hunk, mine, their);
|
||
|
|
insertLeading(hunk, their, mine);
|
||
|
|
|
||
|
|
// Now in the overlap content. Scan through and select the best changes from each.
|
||
|
|
while (mine.index < mine.lines.length && their.index < their.lines.length) {
|
||
|
|
var mineCurrent = mine.lines[mine.index],
|
||
|
|
theirCurrent = their.lines[their.index];
|
||
|
|
if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) {
|
||
|
|
// Both modified ...
|
||
|
|
mutualChange(hunk, mine, their);
|
||
|
|
} else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') {
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
var _hunk$lines;
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
// Mine inserted
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
(_hunk$lines =
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
hunk.lines).push.apply(
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_hunk$lines
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
,
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_toConsumableArray(
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
collectChange(mine)));
|
||
|
|
} else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') {
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
var _hunk$lines2;
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
// Theirs inserted
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
(_hunk$lines2 =
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
hunk.lines).push.apply(
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_hunk$lines2
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
,
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_toConsumableArray(
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
collectChange(their)));
|
||
|
|
} else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') {
|
||
|
|
// Mine removed or edited
|
||
|
|
removal(hunk, mine, their);
|
||
|
|
} else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') {
|
||
|
|
// Their removed or edited
|
||
|
|
removal(hunk, their, mine, true);
|
||
|
|
} else if (mineCurrent === theirCurrent) {
|
||
|
|
// Context identity
|
||
|
|
hunk.lines.push(mineCurrent);
|
||
|
|
mine.index++;
|
||
|
|
their.index++;
|
||
|
|
} else {
|
||
|
|
// Context mismatch
|
||
|
|
conflict(hunk, collectChange(mine), collectChange(their));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Now push anything that may be remaining
|
||
|
|
insertTrailing(hunk, mine);
|
||
|
|
insertTrailing(hunk, their);
|
||
|
|
calcLineCount(hunk);
|
||
|
|
}
|
||
|
|
function mutualChange(hunk, mine, their) {
|
||
|
|
var myChanges = collectChange(mine),
|
||
|
|
theirChanges = collectChange(their);
|
||
|
|
if (allRemoves(myChanges) && allRemoves(theirChanges)) {
|
||
|
|
// Special case for remove changes that are supersets of one another
|
||
|
|
if (
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
(0,
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_array
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
.
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
arrayStartsWith)
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
(myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) {
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
var _hunk$lines3;
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
(_hunk$lines3 =
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
hunk.lines).push.apply(
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_hunk$lines3
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
,
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_toConsumableArray(
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
myChanges));
|
||
|
|
return;
|
||
|
|
} else if (
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
(0,
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_array
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
.
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
arrayStartsWith)
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
(theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) {
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
var _hunk$lines4;
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
(_hunk$lines4 =
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
hunk.lines).push.apply(
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_hunk$lines4
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
,
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_toConsumableArray(
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
theirChanges));
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
} else if (
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
(0,
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_array
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
.
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
arrayEqual)
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
(myChanges, theirChanges)) {
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
var _hunk$lines5;
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
(_hunk$lines5 =
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
hunk.lines).push.apply(
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_hunk$lines5
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
,
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_toConsumableArray(
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
myChanges));
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
conflict(hunk, myChanges, theirChanges);
|
||
|
|
}
|
||
|
|
function removal(hunk, mine, their, swap) {
|
||
|
|
var myChanges = collectChange(mine),
|
||
|
|
theirChanges = collectContext(their, myChanges);
|
||
|
|
if (theirChanges.merged) {
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
var _hunk$lines6;
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
(_hunk$lines6 =
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
hunk.lines).push.apply(
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_hunk$lines6
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
,
|
||
|
|
/*istanbul ignore start*/
|
||
|
|
_toConsumableArray(
|
||
|
|
/*istanbul ignore end*/
|
||
|
|
theirChanges.merged));
|
||
|
|
} else {
|
||
|
|
conflict(hunk, swap ? theirChanges : myChanges, swap ? myChanges : theirChanges);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
function conflict(hunk, mine, their) {
|
||
|
|
hunk.conflict = true;
|
||
|
|
hunk.lines.push({
|
||
|
|
conflict: true,
|
||
|
|
mine: mine,
|
||
|
|
theirs: their
|
||
|
|
});
|
||
|
|
}
|
||
|
|
function insertLeading(hunk, insert, their) {
|
||
|
|
while (insert.offset < their.offset && insert.index < insert.lines.length) {
|
||
|
|
var line = insert.lines[insert.index++];
|
||
|
|
hunk.lines.push(line);
|
||
|
|
insert.offset++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
function insertTrailing(hunk, insert) {
|
||
|
|
while (insert.index < insert.lines.length) {
|
||
|
|
var line = insert.lines[insert.index++];
|
||
|
|
hunk.lines.push(line);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
function collectChange(state) {
|
||
|
|
var ret = [],
|
||
|
|
operation = state.lines[state.index][0];
|
||
|
|
while (state.index < state.lines.length) {
|
||
|
|
var line = state.lines[state.index];
|
||
|
|
|
||
|
|
// Group additions that are immediately after subtractions and treat them as one "atomic" modify change.
|
||
|
|
if (operation === '-' && line[0] === '+') {
|
||
|
|
operation = '+';
|
||
|
|
}
|
||
|
|
if (operation === line[0]) {
|
||
|
|
ret.push(line);
|
||
|
|
state.index++;
|
||
|
|
} else {
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return ret;
|
||
|
|
}
|
||
|
|
function collectContext(state, matchChanges) {
|
||
|
|
var changes = [],
|
||
|
|
merged = [],
|
||
|
|
matchIndex = 0,
|
||
|
|
contextChanges = false,
|
||
|
|
conflicted = false;
|
||
|
|
while (matchIndex < matchChanges.length && state.index < state.lines.length) {
|
||
|
|
var change = state.lines[state.index],
|
||
|
|
match = matchChanges[matchIndex];
|
||
|
|
|
||
|
|
// Once we've hit our add, then we are done
|
||
|
|
if (match[0] === '+') {
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
contextChanges = contextChanges || change[0] !== ' ';
|
||
|
|
merged.push(match);
|
||
|
|
matchIndex++;
|
||
|
|
|
||
|
|
// Consume any additions in the other block as a conflict to attempt
|
||
|
|
// to pull in the remaining context after this
|
||
|
|
if (change[0] === '+') {
|
||
|
|
conflicted = true;
|
||
|
|
while (change[0] === '+') {
|
||
|
|
changes.push(change);
|
||
|
|
change = state.lines[++state.index];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (match.substr(1) === change.substr(1)) {
|
||
|
|
changes.push(change);
|
||
|
|
state.index++;
|
||
|
|
} else {
|
||
|
|
conflicted = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if ((matchChanges[matchIndex] || '')[0] === '+' && contextChanges) {
|
||
|
|
conflicted = true;
|
||
|
|
}
|
||
|
|
if (conflicted) {
|
||
|
|
return changes;
|
||
|
|
}
|
||
|
|
while (matchIndex < matchChanges.length) {
|
||
|
|
merged.push(matchChanges[matchIndex++]);
|
||
|
|
}
|
||
|
|
return {
|
||
|
|
merged: merged,
|
||
|
|
changes: changes
|
||
|
|
};
|
||
|
|
}
|
||
|
|
function allRemoves(changes) {
|
||
|
|
return changes.reduce(function (prev, change) {
|
||
|
|
return prev && change[0] === '-';
|
||
|
|
}, true);
|
||
|
|
}
|
||
|
|
function skipRemoveSuperset(state, removeChanges, delta) {
|
||
|
|
for (var i = 0; i < delta; i++) {
|
||
|
|
var changeContent = removeChanges[removeChanges.length - delta + i].substr(1);
|
||
|
|
if (state.lines[state.index + i] !== ' ' + changeContent) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
state.index += delta;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
function calcOldNewLineCount(lines) {
|
||
|
|
var oldLines = 0;
|
||
|
|
var newLines = 0;
|
||
|
|
lines.forEach(function (line) {
|
||
|
|
if (typeof line !== 'string') {
|
||
|
|
var myCount = calcOldNewLineCount(line.mine);
|
||
|
|
var theirCount = calcOldNewLineCount(line.theirs);
|
||
|
|
if (oldLines !== undefined) {
|
||
|
|
if (myCount.oldLines === theirCount.oldLines) {
|
||
|
|
oldLines += myCount.oldLines;
|
||
|
|
} else {
|
||
|
|
oldLines = undefined;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (newLines !== undefined) {
|
||
|
|
if (myCount.newLines === theirCount.newLines) {
|
||
|
|
newLines += myCount.newLines;
|
||
|
|
} else {
|
||
|
|
newLines = undefined;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
if (newLines !== undefined && (line[0] === '+' || line[0] === ' ')) {
|
||
|
|
newLines++;
|
||
|
|
}
|
||
|
|
if (oldLines !== undefined && (line[0] === '-' || line[0] === ' ')) {
|
||
|
|
oldLines++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
return {
|
||
|
|
oldLines: oldLines,
|
||
|
|
newLines: newLines
|
||
|
|
};
|
||
|
|
}
|
||
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfY3JlYXRlIiwicmVxdWlyZSIsIl9wYXJzZSIsIl9hcnJheSIsIl90b0NvbnN1bWFibGVBcnJheSIsImFyciIsIl9hcnJheVdpdGhvdXRIb2xlcyIsIl9pdGVyYWJsZVR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