/** * @file Cross-leaf diff machinery for `git/*`. Owns the LRU+TTL git-diff cache, * the spawn-args builder, the porcelain-output parser, and the async/sync * `innerDiff` runners. Public-surface leaves (`changed.ts`, `staged.ts`, * `unstaged.ts`) call into these helpers; nothing else should. */ import type { GitDiffOptions } from './types.js'; export type SpawnArgs = [string, string[], Record]; export interface GitDiffSpawnArgs { all: SpawnArgs; unstaged: SpawnArgs; staged: SpawnArgs; } export type GitDiffCacheEntry = { readonly expiresAt: number; readonly result: string[]; }; export declare const gitDiffCache: Map; export declare const GIT_CACHE_MAX_SIZE = 100; export declare const GIT_CACHE_TTL_MS = 2000; export declare function getCachedGitDiff(key: string): string[] | undefined; /** * Get spawn arguments for different git diff operations. * * Prepares argument arrays for `spawn()`/`spawnSync()` calls that retrieve: - * `all`: All staged, unstaged, and untracked changed files via `git status * --porcelain` - `unstaged`: Unstaged modifications via `git diff --name-only` * * - `staged`: Staged changes via `git diff --cached --name-only` * * Automatically resolves symlinks in the provided `cwd` and enables shell mode * on Windows for proper command execution. * * @param cwd - Working directory for git operations, defaults to * `process.cwd()`. * * @returns Object containing spawn arguments for all, unstaged, and staged * operations. */ export declare function getGitDiffSpawnArgs(cwd?: string | undefined): GitDiffSpawnArgs; /** * Get the git executable path. * * Resolves the git binary path via PATH on first call and caches it. Falls back * to 'git' if not found in PATH. * * @example * ;```typescript * const git = getGitPath() * // => '/usr/bin/git' or 'git' if not found * ``` * * @returns The git executable path (resolved from PATH on first call). */ export declare function getGitPath(): string; /** * Execute git diff command asynchronously and parse results. * * Internal helper for async git operations. Handles caching, command execution, * and result parsing. Returns empty array on git command failure. * * @param args - Spawn arguments tuple `[command, args, options]`. * @param options - Git diff options for caching and parsing. * * @returns Promise resolving to array of file paths. */ export declare function innerDiff(args: SpawnArgs, options?: GitDiffOptions | undefined): Promise; /** * Execute git diff command synchronously and parse results. * * Internal helper for sync git operations. Handles caching, command execution, * and result parsing. Returns empty array on git command failure. * * @param args - Spawn arguments tuple `[command, args, options]`. * @param options - Git diff options for caching and parsing. * * @returns Array of file paths. */ export declare function innerDiffSync(args: SpawnArgs, options?: GitDiffOptions | undefined): string[]; /** * Parse git diff stdout output into file path array. * * Internal helper that processes raw git command output by: 1. Finding git * repository root from spawn cwd 2. Stripping ANSI codes and splitting into * lines 3. Parsing porcelain format status codes if requested 4. Normalizing * and optionally making paths absolute 5. Filtering paths based on cwd and glob * options. * * Git always returns paths relative to the repository root, regardless of where * the command was executed. This function handles the path resolution correctly * by finding the repo root and adjusting paths accordingly. * * @param stdout - Raw stdout from git command. * @param options - Git diff options for path processing. * @param spawnCwd - Working directory where git command was executed. * * @returns Array of processed file paths. */ export declare function parseGitDiffStdout(stdout: string, options?: GitDiffOptions | undefined, spawnCwd?: string | undefined): string[]; export declare function setCachedGitDiff(key: string, result: string[]): void; /** * Build a stable cache key that is insensitive to object-property insertion * order, so callers passing the same options with different shapes hit the same * cache slot. */ export declare function stableKey(value: unknown): string;