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