MCPcopy Index your code
hub / github.com/continuedev/continue / parseUnifiedDiff

Function parseUnifiedDiff

core/edit/lazy/unifiedDiffApply.ts:104–127  ·  view source on GitHub ↗

* Parses a unified diff string into an array of hunks. * It skips the file header lines (starting with "---" or "+++") and hunk header lines (starting with "@@"), * then collects the remaining lines (which may start with '+' or '-' or have no prefix).

(diffText: string)

Source from the content-addressed store, hash-verified

102 * then collects the remaining lines (which may start with '+' or '-' or have no prefix).
103 */
104function parseUnifiedDiff(diffText: string): Hunk[] {
105 const lines = diffText.split(/\r?\n/);
106 const hunks: Hunk[] = [];
107 let currentHunk: Hunk | null = null;
108
109 for (const line of lines) {
110 if (line.startsWith("---") || line.startsWith("+++")) {
111 // Skip file header lines.
112 continue;
113 }
114 if (line.startsWith("@@")) {
115 if (currentHunk) {
116 hunks.push(currentHunk);
117 }
118 currentHunk = { lines: [] };
119 continue;
120 }
121 currentHunk?.lines.push(line);
122 }
123 if (currentHunk) {
124 hunks.push(currentHunk);
125 }
126 return hunks;
127}
128
129/**
130 * Searches for an occurrence of the block of lines (the “before” block) in sourceLines,

Callers 1

applyUnifiedDiffFunction · 0.85

Calls 1

pushMethod · 0.65

Tested by

no test coverage detected