(
lines: string[],
{ supportLegacyDiffs }: { supportLegacyDiffs: boolean },
)
| 148 | } |
| 149 | |
| 150 | function parsePatchLines( |
| 151 | lines: string[], |
| 152 | { supportLegacyDiffs }: { supportLegacyDiffs: boolean }, |
| 153 | ): FileDeets[] { |
| 154 | const result: FileDeets[] = [] |
| 155 | let currentFilePatch: FileDeets = emptyFilePatch() |
| 156 | let state: State = "parsing header" |
| 157 | let currentHunk: Hunk | null = null |
| 158 | let currentHunkMutationPart: PatchMutationPart | null = null |
| 159 | let hunkStartLineIndex = 0 |
| 160 | |
| 161 | function commitHunk(i: number) { |
| 162 | if (currentHunk) { |
| 163 | if (currentHunkMutationPart) { |
| 164 | currentHunk.parts.push(currentHunkMutationPart) |
| 165 | currentHunkMutationPart = null |
| 166 | } |
| 167 | currentHunk.source = lines.slice(hunkStartLineIndex, i).join("\n") |
| 168 | currentFilePatch.hunks!.push(currentHunk) |
| 169 | currentHunk = null |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | function commitFilePatch(i: number) { |
| 174 | commitHunk(i) |
| 175 | result.push(currentFilePatch) |
| 176 | currentFilePatch = emptyFilePatch() |
| 177 | } |
| 178 | |
| 179 | for (let i = 0; i < lines.length; i++) { |
| 180 | const line = lines[i] |
| 181 | |
| 182 | if (state === "parsing header") { |
| 183 | if (line.startsWith("@@")) { |
| 184 | hunkStartLineIndex = i |
| 185 | state = "parsing hunks" |
| 186 | currentFilePatch.hunks = [] |
| 187 | i-- |
| 188 | } else if (line.startsWith("diff --git ")) { |
| 189 | if (currentFilePatch && currentFilePatch.diffLineFromPath) { |
| 190 | commitFilePatch(i) |
| 191 | } |
| 192 | const match = line.match(/^diff --git a\/(.*?) b\/(.*?)\s*$/) |
| 193 | if (!match) { |
| 194 | throw new Error("Bad diff line: " + line) |
| 195 | } |
| 196 | currentFilePatch.diffLineFromPath = match[1] |
| 197 | currentFilePatch.diffLineToPath = match[2] |
| 198 | } else if (line.startsWith("old mode ")) { |
| 199 | currentFilePatch.oldMode = line.slice("old mode ".length).trim() |
| 200 | } else if (line.startsWith("new mode ")) { |
| 201 | currentFilePatch.newMode = line.slice("new mode ".length).trim() |
| 202 | } else if (line.startsWith("deleted file mode ")) { |
| 203 | currentFilePatch.deletedFileMode = line |
| 204 | .slice("deleted file mode ".length) |
| 205 | .trim() |
| 206 | } else if (line.startsWith("new file mode ")) { |
| 207 | currentFilePatch.newFileMode = line |
no test coverage detected
searching dependent graphs…