* Counts the number of unique file paths touched by a git patch. * * `git format-patch` emits one `diff --git` header per (commit, file), so the * same file modified across multiple commits will appear multiple times. The * file-count safety limit counts unique files (i.e. how many distinct file
(patchContent)
| 449 | * @returns {number} Number of unique file paths referenced in the patch |
| 450 | */ |
| 451 | function countUniquePatchFiles(patchContent) { |
| 452 | if (!patchContent || !patchContent.trim()) { |
| 453 | return 0; |
| 454 | } |
| 455 | const files = new Set(); |
| 456 | const entries = extractDiffGitHeaderEntries(patchContent); |
| 457 | let unparseableIdx = 0; |
| 458 | for (const entry of entries) { |
| 459 | const path = entry.newPath || entry.oldPath; |
| 460 | if (path) { |
| 461 | files.add(path); |
| 462 | } else { |
| 463 | files.add(`__unparseable_header_${entry.headerIndex}_${unparseableIdx++}`); |
| 464 | } |
| 465 | } |
| 466 | return files.size; |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * Enforces maximum limits on pull request parameters to prevent resource exhaustion attacks. |
no test coverage detected