MCPcopy Create free account
hub / github.com/agent-tower/core / parseNumstat

Function parseNumstat

packages/server/src/routes/git.ts:111–129  ·  view source on GitHub ↗

Parse `git diff --numstat` output into a path → {additions, deletions} map.

(output: string)

Source from the content-addressed store, hash-verified

109/** Parse `git diff --numstat` output into a path → {additions, deletions} map. */
110function parseNumstat(output: string): Map<string, { additions: number; deletions: number }> {
111 const map = new Map<string, { additions: number; deletions: number }>();
112 if (!output.trim()) return map;
113 for (const line of output.trim().split('\n')) {
114 // Format: "12\t4\tpath"; binary files: "-\t-\tpath"; renames: "1\t2\told => new" or "1\t2\ta/{b => c}/d"
115 const parts = line.split('\t');
116 if (parts.length < 3) continue;
117 const additions = parts[0] === '-' ? 0 : Number(parts[0]) || 0;
118 const deletions = parts[1] === '-' ? 0 : Number(parts[1]) || 0;
119 let filePath = parts.slice(2).join('\t');
120 if (filePath.includes(' => ')) {
121 filePath = filePath.includes('{')
122 ? filePath.replace(/\{[^}]*? => ([^}]*?)\}/g, '$1').replace(/\/{2,}/g, '/')
123 : filePath.split(' => ').pop()!;
124 }
125 map.set(filePath, { additions, deletions });
126 }
127 return map;
128}
129
130/** Merge numstat counts into name-status entries by path. */
131function attachNumstat(
132 entries: ChangeEntry[],

Callers 1

gitRoutesFunction · 0.85

Calls 3

trimMethod · 0.80
setMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected