MCPcopy Create free account
hub / github.com/anthropics/claude-code / parseNumstat

Function parseNumstat

mods/diff/hooks/git/parse/parse-numstat.ts:16–66  ·  view source on GitHub ↗
(
  stdout: string,
  maxFiles: number,
)

Source from the content-addressed store, hash-verified

14 * @returns the totals and the kept rows
15 */
16export function parseNumstat(
17 stdout: string,
18 maxFiles: number,
19): Types.NumstatResult {
20 const files: Types.FileStat[] = []
21 const stats = { filesCount: 0, linesAdded: 0, linesRemoved: 0 }
22 const records = stdout.split('\0')
23
24 let at = 0
25
26 while (at < records.length) {
27 const [addedField, removedField, ...pathFields] = (records[at] ?? '').split(
28 '\t',
29 )
30
31 const inline = pathFields.join('\t')
32 const isRename = pathFields.length === 1 && inline === ''
33 const renamedFrom = isRename ? (records[at + 1] ?? null) : null
34 const path = isRename ? (records[at + 2] ?? '') : inline
35 at += isRename ? RENAME_RECORDS : 1
36
37 const isRow =
38 addedField !== undefined && removedField !== undefined && path !== ''
39
40 if (!isRow) {
41 continue
42 }
43
44 const isBinary = addedField === '-' || removedField === '-'
45 const added = isBinary ? 0 : Number(addedField) || 0
46 const removed = isBinary ? 0 : Number(removedField) || 0
47
48 stats.filesCount += 1
49 stats.linesAdded += added
50 stats.linesRemoved += removed
51
52 if (files.length < maxFiles) {
53 files.push({
54 path,
55 renamedFrom,
56 added,
57 removed,
58 isBinary,
59 isUntracked: false,
60 isPreSession: false,
61 })
62 }
63 }
64
65 return { stats, files }
66}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected