MCPcopy Index your code
hub / github.com/anomalyco/opencode / generateUnifiedDiff

Function generateUnifiedDiff

packages/opencode/src/patch/index.ts:486–511  ·  view source on GitHub ↗
(oldContent: string, newContent: string)

Source from the content-addressed store, hash-verified

484}
485
486function generateUnifiedDiff(oldContent: string, newContent: string): string {
487 const oldLines = oldContent.split("\n")
488 const newLines = newContent.split("\n")
489
490 // Simple diff generation - in a real implementation you'd use a proper diff algorithm
491 let diff = "@@ -1 +1 @@\n"
492
493 // Find changes (simplified approach)
494 const maxLen = Math.max(oldLines.length, newLines.length)
495 let hasChanges = false
496
497 for (let i = 0; i < maxLen; i++) {
498 const oldLine = oldLines[i] || ""
499 const newLine = newLines[i] || ""
500
501 if (oldLine !== newLine) {
502 if (oldLine) diff += `-${oldLine}\n`
503 if (newLine) diff += `+${newLine}\n`
504 hasChanges = true
505 } else if (oldLine) {
506 diff += ` ${oldLine}\n`
507 }
508 }
509
510 return hasChanges ? diff : ""
511}
512
513// Apply hunks to filesystem
514export const applyHunksToFiles = Effect.fn("Patch.applyHunksToFiles")(function* (hunks: Hunk[]) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected