({
filePath,
oldContent,
newContent,
ignoreWhitespace = false,
singleHunk = false,
}: {
filePath: string
oldContent: string
newContent: string
ignoreWhitespace?: boolean
singleHunk?: boolean
})
| 81 | } |
| 82 | |
| 83 | export function getPatchFromContents({ |
| 84 | filePath, |
| 85 | oldContent, |
| 86 | newContent, |
| 87 | ignoreWhitespace = false, |
| 88 | singleHunk = false, |
| 89 | }: { |
| 90 | filePath: string |
| 91 | oldContent: string |
| 92 | newContent: string |
| 93 | ignoreWhitespace?: boolean |
| 94 | singleHunk?: boolean |
| 95 | }): StructuredPatchHunk[] { |
| 96 | const result = structuredPatch( |
| 97 | filePath, |
| 98 | filePath, |
| 99 | escapeForDiff(oldContent), |
| 100 | escapeForDiff(newContent), |
| 101 | undefined, |
| 102 | undefined, |
| 103 | { |
| 104 | ignoreWhitespace, |
| 105 | context: singleHunk ? 100_000 : CONTEXT_LINES, |
| 106 | timeout: DIFF_TIMEOUT_MS, |
| 107 | }, |
| 108 | ) |
| 109 | if (!result) { |
| 110 | return [] |
| 111 | } |
| 112 | return result.hunks.map(_ => ({ |
| 113 | ..._, |
| 114 | lines: _.lines.map(unescapeFromDiff), |
| 115 | })) |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Get a patch for display with edits applied |
no test coverage detected