2026-02-22 14:13:59 +09:00
|
|
|
import { computeLineHash } from "./hash-computation"
|
|
|
|
|
|
|
|
|
|
export function generateHashlineDiff(oldContent: string, newContent: string, filePath: string): string {
|
|
|
|
|
const oldLines = oldContent.split("\n")
|
|
|
|
|
const newLines = newContent.split("\n")
|
|
|
|
|
|
|
|
|
|
let diff = `--- ${filePath}\n+++ ${filePath}\n`
|
|
|
|
|
const maxLines = Math.max(oldLines.length, newLines.length)
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < maxLines; i += 1) {
|
|
|
|
|
const oldLine = oldLines[i] ?? ""
|
|
|
|
|
const newLine = newLines[i] ?? ""
|
|
|
|
|
const lineNum = i + 1
|
|
|
|
|
const hash = computeLineHash(lineNum, newLine)
|
|
|
|
|
|
|
|
|
|
if (i >= oldLines.length) {
|
2026-02-24 06:01:24 +09:00
|
|
|
diff += `+ ${lineNum}#${hash}|${newLine}\n`
|
2026-02-22 14:13:59 +09:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if (i >= newLines.length) {
|
2026-02-24 06:01:24 +09:00
|
|
|
diff += `- ${lineNum}# |${oldLine}\n`
|
2026-02-22 14:13:59 +09:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if (oldLine !== newLine) {
|
2026-02-24 06:01:24 +09:00
|
|
|
diff += `- ${lineNum}# |${oldLine}\n`
|
|
|
|
|
diff += `+ ${lineNum}#${hash}|${newLine}\n`
|
2026-02-22 14:13:59 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return diff
|
|
|
|
|
}
|