MCPcopy Create free account
hub / github.com/bigcode-project/jupytercoder / formatPatch

Function formatPatch

src/diff.js:1055–1084  ·  view source on GitHub ↗
(diff)

Source from the content-addressed store, hash-verified

1053 };
1054 }
1055 function formatPatch(diff) {
1056 var ret = [];
1057
1058 if (diff.oldFileName == diff.newFileName) {
1059 ret.push('Index: ' + diff.oldFileName);
1060 }
1061
1062 ret.push('===================================================================');
1063 ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
1064 ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
1065
1066 for (var i = 0; i < diff.hunks.length; i++) {
1067 var hunk = diff.hunks[i]; // Unified Diff Format quirk: If the chunk size is 0,
1068 // the first number is one lower than one would expect.
1069 // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
1070
1071 if (hunk.oldLines === 0) {
1072 hunk.oldStart -= 1;
1073 }
1074
1075 if (hunk.newLines === 0) {
1076 hunk.newStart -= 1;
1077 }
1078
1079 ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
1080 ret.push.apply(ret, hunk.lines);
1081 }
1082
1083 return ret.join('\n') + '\n';
1084 }
1085 function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
1086 return formatPatch(structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options));
1087 }

Callers 1

createTwoFilesPatchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected