MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / getPatchFromContents

Function getPatchFromContents

src/utils/diff.ts:81–114  ·  view source on GitHub ↗
({
  filePath,
  oldContent,
  newContent,
  ignoreWhitespace = false,
  singleHunk = false,
}: {
  filePath: string
  oldContent: string
  newContent: string
  ignoreWhitespace?: boolean
  singleHunk?: boolean
})

Source from the content-addressed store, hash-verified

79}
80
81export 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

Callers 3

diff.test.tsFile · 0.90
getPatchForEditsFunction · 0.85
computeEditsFromContentsFunction · 0.85

Calls 1

escapeForDiffFunction · 0.85

Tested by

no test coverage detected