MCPcopy Create free account
hub / github.com/bearlyai/OpenADE / parsePatchStats

Function parsePatchStats

projects/electron/src/modules/code/git.ts:865–883  ·  view source on GitHub ↗

* Parse stats from a unified diff patch

(patch: string)

Source from the content-addressed store, hash-verified

863 * Parse stats from a unified diff patch
864 */
865function parsePatchStats(patch: string): { filesChanged: number; insertions: number; deletions: number } {
866 const lines = patch.split("\n")
867 const files = new Set<string>()
868 let insertions = 0
869 let deletions = 0
870
871 for (const line of lines) {
872 if (line.startsWith("diff --git")) {
873 const match = line.match(/diff --git a\/(.+) b\//)
874 if (match) files.add(match[1])
875 } else if (line.startsWith("+") && !line.startsWith("+++")) {
876 insertions++
877 } else if (line.startsWith("-") && !line.startsWith("---")) {
878 deletions++
879 }
880 }
881
882 return { filesChanged: files.size, insertions, deletions }
883}
884
885// Max patch size to return (1MB) - larger patches are truncated
886const MAX_PATCH_SIZE = 1024 * 1024

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected