MCPcopy Create free account
hub / github.com/kpdecker/jsdiff / applyPatches

Function applyPatches

src/patch/apply.ts:340–366  ·  view source on GitHub ↗
(uniDiff: string | StructuredPatch[], options: ApplyPatchesOptions)

Source from the content-addressed store, hash-verified

338 * Once all patches have been applied or an error occurs, the `options.complete(err)` callback is made.
339 */
340export function applyPatches(uniDiff: string | StructuredPatch[], options: ApplyPatchesOptions): void {
341 const spDiff: StructuredPatch[] = typeof uniDiff === 'string' ? parsePatch(uniDiff) : uniDiff;
342
343 let currentIndex = 0;
344 function processIndex(): void {
345 const index = spDiff[currentIndex++];
346 if (!index) {
347 return options.complete();
348 }
349
350 options.loadFile(index, function(err: any, data: string) {
351 if (err) {
352 return options.complete(err);
353 }
354
355 const updatedContent = applyPatch(data, index, options);
356 options.patched(index, updatedContent, function(err: any) {
357 if (err) {
358 return options.complete(err);
359 }
360
361 processIndex();
362 });
363 });
364 }
365 processIndex();
366}

Callers 1

apply.jsFile · 0.85

Calls 2

parsePatchFunction · 0.85
processIndexFunction · 0.85

Tested by

no test coverage detected