MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / readDiffStats

Function readDiffStats

apps/kimi-code/src/utils/git/git-status.ts:216–237  ·  view source on GitHub ↗
(workDir: string)

Source from the content-addressed store, hash-verified

214}
215
216function readDiffStats(workDir: string): { added: number; deleted: number } {
217 try {
218 const result = spawnSync('git', ['-C', workDir, 'diff', '--numstat', 'HEAD', '--'], {
219 encoding: 'utf8',
220 timeout: SPAWN_TIMEOUT_MS,
221 maxBuffer: 4 * 1024 * 1024,
222 });
223 if (result.status !== 0) return { added: 0, deleted: 0 };
224
225 let added = 0;
226 let deleted = 0;
227 for (const line of result.stdout.split('\n')) {
228 if (!line) continue;
229 const [addedText, deletedText] = line.split('\t');
230 added += parseDiffNumstatCount(addedText);
231 deleted += parseDiffNumstatCount(deletedText);
232 }
233 return { added, deleted };
234 } catch {
235 return { added: 0, deleted: 0 };
236 }
237}
238
239function parseDiffNumstatCount(value: string | undefined): number {
240 if (value === undefined || value === '-') return 0;

Callers 1

readStatusFunction · 0.85

Calls 1

parseDiffNumstatCountFunction · 0.85

Tested by

no test coverage detected