157 lines
17 KiB
JavaScript
157 lines
17 KiB
JavaScript
/*istanbul ignore start*/'use strict';
|
|
|
|
exports.__esModule = true;
|
|
exports. /*istanbul ignore end*/structuredPatch = structuredPatch;
|
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/createTwoFilesPatch = createTwoFilesPatch;
|
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/createPatch = createPatch;
|
|
|
|
var /*istanbul ignore start*/_line = require('../diff/line') /*istanbul ignore end*/;
|
|
|
|
/*istanbul ignore start*/
|
|
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
|
|
|
/*istanbul ignore end*/function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
if (!options) {
|
|
options = {};
|
|
}
|
|
if (typeof options.context === 'undefined') {
|
|
options.context = 4;
|
|
}
|
|
|
|
var diff = /*istanbul ignore start*/(0, _line.diffLines) /*istanbul ignore end*/(oldStr, newStr, options);
|
|
diff.push({ value: '', lines: [] }); // Append an empty value to make cleanup easier
|
|
|
|
function contextLines(lines) {
|
|
return lines.map(function (entry) {
|
|
return ' ' + entry;
|
|
});
|
|
}
|
|
|
|
var hunks = [];
|
|
var oldRangeStart = 0,
|
|
newRangeStart = 0,
|
|
curRange = [],
|
|
oldLine = 1,
|
|
newLine = 1;
|
|
/*istanbul ignore start*/
|
|
var _loop = function _loop( /*istanbul ignore end*/i) {
|
|
var current = diff[i],
|
|
lines = current.lines || current.value.replace(/\n$/, '').split('\n');
|
|
current.lines = lines;
|
|
|
|
if (current.added || current.removed) {
|
|
/*istanbul ignore start*/
|
|
var _curRange;
|
|
|
|
/*istanbul ignore end*/
|
|
// If we have previous context, start with that
|
|
if (!oldRangeStart) {
|
|
var prev = diff[i - 1];
|
|
oldRangeStart = oldLine;
|
|
newRangeStart = newLine;
|
|
|
|
if (prev) {
|
|
curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
|
|
oldRangeStart -= curRange.length;
|
|
newRangeStart -= curRange.length;
|
|
}
|
|
}
|
|
|
|
// Output our changes
|
|
/*istanbul ignore start*/(_curRange = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/lines.map(function (entry) {
|
|
return (current.added ? '+' : '-') + entry;
|
|
})));
|
|
|
|
// Track the updated file position
|
|
if (current.added) {
|
|
newLine += lines.length;
|
|
} else {
|
|
oldLine += lines.length;
|
|
}
|
|
} else {
|
|
// Identical context lines. Track line changes
|
|
if (oldRangeStart) {
|
|
// Close out any changes that have been output (or join overlapping)
|
|
if (lines.length <= options.context * 2 && i < diff.length - 2) {
|
|
/*istanbul ignore start*/
|
|
var _curRange2;
|
|
|
|
/*istanbul ignore end*/
|
|
// Overlapping
|
|
/*istanbul ignore start*/(_curRange2 = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange2 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/contextLines(lines)));
|
|
} else {
|
|
/*istanbul ignore start*/
|
|
var _curRange3;
|
|
|
|
/*istanbul ignore end*/
|
|
// end the range and output
|
|
var contextSize = Math.min(lines.length, options.context);
|
|
/*istanbul ignore start*/(_curRange3 = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange3 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/contextLines(lines.slice(0, contextSize))));
|
|
|
|
var hunk = {
|
|
oldStart: oldRangeStart,
|
|
oldLines: oldLine - oldRangeStart + contextSize,
|
|
newStart: newRangeStart,
|
|
newLines: newLine - newRangeStart + contextSize,
|
|
lines: curRange
|
|
};
|
|
if (i >= diff.length - 2 && lines.length <= options.context) {
|
|
// EOF is inside this hunk
|
|
var oldEOFNewline = /\n$/.test(oldStr);
|
|
var newEOFNewline = /\n$/.test(newStr);
|
|
if (lines.length == 0 && !oldEOFNewline) {
|
|
// special case: old has no eol and no trailing context; no-nl can end up before adds
|
|
curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
|
|
} else if (!oldEOFNewline || !newEOFNewline) {
|
|
curRange.push('\\ No newline at end of file');
|
|
}
|
|
}
|
|
hunks.push(hunk);
|
|
|
|
oldRangeStart = 0;
|
|
newRangeStart = 0;
|
|
curRange = [];
|
|
}
|
|
}
|
|
oldLine += lines.length;
|
|
newLine += lines.length;
|
|
}
|
|
};
|
|
|
|
for (var i = 0; i < diff.length; i++) {
|
|
/*istanbul ignore start*/
|
|
_loop( /*istanbul ignore end*/i);
|
|
}
|
|
|
|
return {
|
|
oldFileName: oldFileName, newFileName: newFileName,
|
|
oldHeader: oldHeader, newHeader: newHeader,
|
|
hunks: hunks
|
|
};
|
|
}
|
|
|
|
function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
|
|
|
|
var ret = [];
|
|
if (oldFileName == newFileName) {
|
|
ret.push('Index: ' + oldFileName);
|
|
}
|
|
ret.push('===================================================================');
|
|
ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
|
|
ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
|
|
|
|
for (var i = 0; i < diff.hunks.length; i++) {
|
|
var hunk = diff.hunks[i];
|
|
ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
|
|
ret.push.apply(ret, hunk.lines);
|
|
}
|
|
|
|
return ret.join('\n') + '\n';
|
|
}
|
|
|
|
function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
|
|
}
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wYXRjaC9jcmVhdGUuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O2dDQUVnQixlLEdBQUEsZTt5REFpR0EsbUIsR0FBQSxtQjt5REF3QkEsVyxHQUFBLFc7O0FBM0hoQixJLHlCQUFBLCtCLHdCQUFBOzs7Ozt1QkFFTyxTQUFTLGVBQVQsQ0FBeUIsV0FBekIsRUFBc0MsV0FBdEMsRUFBbUQsTUFBbkQsRUFBMkQsTUFBM0QsRUFBbUUsU0FBbkUsRUFBOEUsU0FBOUUsRUFBeUYsT0FBekYsRUFBa0c7QUFDdkcsTUFBSSxDQUFDLE9BQUwsRUFBYztBQUNaLGNBQVUsRUFBVjtBQUNEO0FBQ0QsTUFBSSxPQUFPLFFBQVEsT0FBZixLQUEyQixXQUEvQixFQUE0QztBQUMxQyxZQUFRLE9BQVIsR0FBa0IsQ0FBbEI7QUFDRDs7QUFFRCxNQUFNLE8seUJBQU8sb0Isd0JBQUEsQ0FBVSxNQUFWLEVBQWtCLE1BQWxCLEVBQTBCLE9BQTFCLENBQWI7QUFDQSxPQUFLLElBQUwsQ0FBVSxFQUFDLE9BQU8sRUFBUixFQUFZLE9BQU8sRUFBbkIsRUFBVixFOztBQUVBLFdBQVMsWUFBVCxDQUFzQixLQUF0QixFQUE2QjtBQUMzQixXQUFPLE1BQU0sR0FBTixDQUFVLFVBQVMsS0FBVCxFQUFnQjtBQUFFLGFBQU8sTUFBTSxLQUFiO0FBQXFCLEtBQWpELENBQVA7QUFDRDs7QUFFRCxNQUFJLFFBQVEsRUFBWjtBQUNBLE1BQUksZ0JBQWdCLENBQXBCO0FBQUEsTUFBdUIsZ0JBQWdCLENBQXZDO0FBQUEsTUFBMEMsV0FBVyx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