@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 46 lines 1.34 KB
Raw
1 export interface TurnDiffFileSummary {
2 readonly path: string;
3 readonly previousPath?: string;
4 readonly additions: number;
5 readonly deletions: number;
6 }
7
8 export function parseTurnDiffFilesFromNumstat(numstat: string): ReadonlyArray<TurnDiffFileSummary> {
9 const records = numstat.split("\0");
10 const files: TurnDiffFileSummary[] = [];
11
12 for (let index = 0; index < records.length; index += 1) {
13 const record = records[index]!;
14 const counts = /^(\d+|-)\t(\d+|-)\t/.exec(record);
15 if (!counts) continue;
16
17 let path = record.slice(counts[0].length);
18 let previousPath: string | undefined;
19 if (path.length === 0) {
20 previousPath = records[index + 1];
21 path = records[index + 2] ?? "";
22 index += 2;
23 }
24 if (path.length === 0) continue;
25
26 files.push({
27 path,
28 ...(previousPath === undefined ? {} : { previousPath }),
29 additions: counts[1] === "-" ? 0 : Number(counts[1]),
30 deletions: counts[2] === "-" ? 0 : Number(counts[2]),
31 });
32 }
33
34 return files.toSorted((left, right) => left.path.localeCompare(right.path));
35 }
36
37 export function isGitImport(
38 file: TurnDiffFileSummary,
39 authoredPaths: ReadonlySet<string> | null,
40 ): boolean {
41 return (
42 authoredPaths !== null &&
43 !authoredPaths.has(file.path) &&
44 (file.previousPath === undefined || !authoredPaths.has(file.previousPath))
45 );
46 }