| 175 | } |
| 176 | |
| 177 | function getDiffStats( |
| 178 | text: string, |
| 179 | lines: FileEditDiffLine[], |
| 180 | ): Pick<FileEditDiffSummary, "additions" | "deletions"> | null { |
| 181 | const additions = lines.filter((line) => line.kind === "add").length; |
| 182 | const deletions = lines.filter((line) => line.kind === "remove").length; |
| 183 | |
| 184 | if (additions > 0 || deletions > 0) { |
| 185 | return { additions, deletions }; |
| 186 | } |
| 187 | |
| 188 | const statAdditions = text.match(/(\d+)\s+insertions?\(\+\)/); |
| 189 | const statDeletions = text.match(/(\d+)\s+deletions?\(-\)/); |
| 190 | if (statAdditions || statDeletions) { |
| 191 | return { |
| 192 | additions: statAdditions ? Number(statAdditions[1]) : 0, |
| 193 | deletions: statDeletions ? Number(statDeletions[1]) : 0, |
| 194 | }; |
| 195 | } |
| 196 | |
| 197 | return null; |
| 198 | } |
| 199 | |
| 200 | function basename(path: string) { |
| 201 | const parts = path.replace(/\\/g, "/").split("/"); |