surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| 1 | import Limits from '../../limits' |
| 2 | import Argv from '../argv' |
| 3 | import Parse from '../parse' |
| 4 | import type Types from '../types' |
| 5 | |
| 6 | /** |
| 7 | * The rows and totals of `git diff <base>`, or null when git could not |
| 8 | * say (as the built-in panel's stats fetch) or its listing arrived cut. |
| 9 | * |
| 10 | * A `--shortstat` probe runs first, so a diff past MAX_FILES_FOR_DETAILS |
| 11 | * answers its totals with no rows and no `--numstat` buffering. |
| 12 | * |
| 13 | * @param context runs git |
| 14 | * @param base the ref (or `--cached`) the working tree is compared with |
| 15 | * @returns the parsed result, or null on a failed numstat |
| 16 | */ |
| 17 | export async function statsOf( |
| 18 | context: Types.FetchContext, |
| 19 | base: string, |
| 20 | ): Promise<Types.NumstatResult | null> { |
| 21 | const run = context.run |
| 22 | |
| 23 | const shortstat = await run([...Argv.DIFF_LEADING_ARGS, base, '--shortstat']) |
| 24 | |
| 25 | const totals = |
| 26 | shortstat.exitCode === 0 ? Parse.parseShortstat(shortstat.stdout) : null |
| 27 | |
| 28 | const isPastDetails = |
| 29 | totals !== null && totals.filesCount > Limits.MAX_FILES_FOR_DETAILS |
| 30 | |
| 31 | if (isPastDetails) { |
| 32 | return { stats: totals, files: [] } |
| 33 | } |
| 34 | |
| 35 | const numstat = await run([ |
| 36 | ...Argv.DIFF_LEADING_ARGS, |
| 37 | base, |
| 38 | '--numstat', |
| 39 | '-z', |
| 40 | ]) |
| 41 | |
| 42 | const isRead = Parse.isWholeAnswer(numstat) |
| 43 | |
| 44 | return isRead ? Parse.parseNumstat(numstat.stdout, Limits.MAX_FILES) : null |
| 45 | } |