* Count added / removed content lines in a unified patch. Only * count lines inside hunks (after an `@@` header) so file headers * are ignored while real content that begins with `+++` / `---` * is still counted. Good enough for `--stat`'s numeric column, * which is all the CLI needs.
(patch: string)
| 236 | * which is all the CLI needs. |
| 237 | */ |
| 238 | function countChanges(patch: string): { insertions: number; deletions: number } { |
| 239 | let insertions = 0; |
| 240 | let deletions = 0; |
| 241 | let inHunk = false; |
| 242 | for (const line of patch.split("\n")) { |
| 243 | if (line.startsWith("@@")) { |
| 244 | inHunk = true; |
| 245 | continue; |
| 246 | } |
| 247 | if (!inHunk) continue; |
| 248 | if (line.startsWith("+")) insertions++; |
| 249 | else if (line.startsWith("-")) deletions++; |
| 250 | } |
| 251 | return { insertions, deletions }; |
| 252 | } |
| 253 | |
| 254 | async function listFilesAt( |
| 255 | git: IsomorphicGitDiffClient, |