(output: string)
| 265 | } |
| 266 | |
| 267 | function parseNumstat(output: string): Map<string, { additions: number; deletions: number }> { |
| 268 | const counts = new Map<string, { additions: number; deletions: number }>(); |
| 269 | const records = output.split("\0"); |
| 270 | for (let i = 0; i < records.length; i++) { |
| 271 | const record = records[i]; |
| 272 | if (!record) continue; |
| 273 | const parts = record.split("\t"); |
| 274 | if (parts.length < 3) continue; |
| 275 | const additions = parts[0] === "-" ? 0 : Number.parseInt(parts[0] ?? "0", 10); |
| 276 | const deletions = parts[1] === "-" ? 0 : Number.parseInt(parts[1] ?? "0", 10); |
| 277 | let path = parts.slice(2).join("\t"); |
| 278 | if (!path) { |
| 279 | path = records[i + 2] ?? ""; |
| 280 | i += 2; |
| 281 | } |
| 282 | if (!path) continue; |
| 283 | counts.set(path, { |
| 284 | additions: Number.isFinite(additions) ? additions : 0, |
| 285 | deletions: Number.isFinite(deletions) ? deletions : 0, |
| 286 | }); |
| 287 | } |
| 288 | return counts; |
| 289 | } |
| 290 | |
| 291 | async function countTextFileLines(path: string): Promise<number> { |
| 292 | try { |
no test coverage detected