MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / loadDiffData

Function loadDiffData

source code/components/FileEditToolDiff.tsx:108–162  ·  view source on GitHub ↗
(file_path: string, edits: FileEdit[])

Source from the content-addressed store, hash-verified

106 return t2;
107}
108async function loadDiffData(file_path: string, edits: FileEdit[]): Promise<DiffData> {
109 const valid = edits.filter(e => e.old_string != null && e.new_string != null);
110 const single = valid.length === 1 ? valid[0]! : undefined;
111
112 // SedEditPermissionRequest passes the entire file as old_string. Scanning for
113 // a needle ≥ CHUNK_SIZE allocates O(needle) for the overlap buffer — skip the
114 // file read entirely and diff the inputs we already have.
115 if (single && single.old_string.length >= CHUNK_SIZE) {
116 return diffToolInputsOnly(file_path, [single]);
117 }
118 try {
119 const handle = await openForScan(file_path);
120 if (handle === null) return diffToolInputsOnly(file_path, valid);
121 try {
122 // Multi-edit and empty old_string genuinely need full-file for sequential
123 // replacements — structuredPatch needs before/after strings. replace_all
124 // routes through the chunked path below (shows first-occurrence window;
125 // matches within the slice still replace via edit.replace_all).
126 if (!single || single.old_string === '') {
127 const file = await readCapped(handle);
128 if (file === null) return diffToolInputsOnly(file_path, valid);
129 const normalized = valid.map(e => normalizeEdit(file, e));
130 return {
131 patch: getPatchForDisplay({
132 filePath: file_path,
133 fileContents: file,
134 edits: normalized
135 }),
136 firstLine: firstLineOf(file),
137 fileContent: file
138 };
139 }
140 const ctx = await scanForContext(handle, single.old_string, CONTEXT_LINES);
141 if (ctx.truncated || ctx.content === '') {
142 return diffToolInputsOnly(file_path, [single]);
143 }
144 const normalized = normalizeEdit(ctx.content, single);
145 const hunks = getPatchForDisplay({
146 filePath: file_path,
147 fileContents: ctx.content,
148 edits: [normalized]
149 });
150 return {
151 patch: adjustHunkLineNumbers(hunks, ctx.lineOffset - 1),
152 firstLine: ctx.lineOffset === 1 ? firstLineOf(ctx.content) : null,
153 fileContent: ctx.content
154 };
155 } finally {
156 await handle.close();
157 }
158 } catch (e) {
159 logError(e as Error);
160 return diffToolInputsOnly(file_path, valid);
161 }
162}
163function diffToolInputsOnly(filePath: string, edits: FileEdit[]): DiffData {
164 return {
165 patch: edits.flatMap(e => getPatchForDisplay({

Callers 1

FileEditToolDiffFunction · 0.70

Calls 10

diffToolInputsOnlyFunction · 0.85
openForScanFunction · 0.85
readCappedFunction · 0.85
normalizeEditFunction · 0.85
getPatchForDisplayFunction · 0.85
firstLineOfFunction · 0.85
scanForContextFunction · 0.85
adjustHunkLineNumbersFunction · 0.85
logErrorFunction · 0.50
closeMethod · 0.45

Tested by

no test coverage detected