MCPcopy Create free account
hub / github.com/arctic-cli/interface / parseUpdateFileChunks

Function parseUpdateFileChunks

packages/arctic/src/patch/index.ts:107–159  ·  view source on GitHub ↗
(lines: string[], startIdx: number)

Source from the content-addressed store, hash-verified

105 }
106
107 function parseUpdateFileChunks(lines: string[], startIdx: number): { chunks: UpdateFileChunk[]; nextIdx: number } {
108 const chunks: UpdateFileChunk[] = []
109 let i = startIdx
110
111 while (i < lines.length && !lines[i].startsWith("***")) {
112 if (lines[i].startsWith("@@")) {
113 // Parse context line
114 const contextLine = lines[i].substring(2).trim()
115 i++
116
117 const oldLines: string[] = []
118 const newLines: string[] = []
119 let isEndOfFile = false
120
121 // Parse change lines
122 while (i < lines.length && !lines[i].startsWith("@@") && !lines[i].startsWith("***")) {
123 const changeLine = lines[i]
124
125 if (changeLine === "*** End of File") {
126 isEndOfFile = true
127 i++
128 break
129 }
130
131 if (changeLine.startsWith(" ")) {
132 // Keep line - appears in both old and new
133 const content = changeLine.substring(1)
134 oldLines.push(content)
135 newLines.push(content)
136 } else if (changeLine.startsWith("-")) {
137 // Remove line - only in old
138 oldLines.push(changeLine.substring(1))
139 } else if (changeLine.startsWith("+")) {
140 // Add line - only in new
141 newLines.push(changeLine.substring(1))
142 }
143
144 i++
145 }
146
147 chunks.push({
148 old_lines: oldLines,
149 new_lines: newLines,
150 change_context: contextLine || undefined,
151 is_end_of_file: isEndOfFile || undefined,
152 })
153 } else {
154 i++
155 }
156 }
157
158 return { chunks, nextIdx: i }
159 }
160
161 function parseAddFileContent(lines: string[], startIdx: number): { content: string; nextIdx: number } {
162 let content = ""

Callers 1

parsePatchFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected