# apps/server/src/checkpointing/Diffs.ts · gitcafe/t3code

[View on GitCafe](https://git.cafe/gitcafe/t3code/blob/44701efd6790c39dc82cb08104f7295e1780210f/apps/server/src/checkpointing/Diffs.ts)

Repository: [gitcafe/t3code](https://git.cafe/gitcafe/t3code)

Visibility: public

Requested revision: 44701efd6790c39dc82cb08104f7295e1780210f

Requested commit: 44701efd6790c39dc82cb08104f7295e1780210f

Commit: 44701efd6790c39dc82cb08104f7295e1780210f

Blob: 0eeee1b6f3f45f1de55ae1292f4aaced0ab2aac4

Size: 838 bytes

[Immutable source](https://git.cafe/gitcafe/t3code/blob/44701efd6790c39dc82cb08104f7295e1780210f/apps/server/src/checkpointing/Diffs.ts?format=markdown)

```
import { parsePatchFiles } from "@pierre/diffs/utils/parsePatchFiles";

export interface TurnDiffFileSummary {
  readonly path: string;
  readonly additions: number;
  readonly deletions: number;
}

export function parseTurnDiffFilesFromUnifiedDiff(
  diff: string,
): ReadonlyArray<TurnDiffFileSummary> {
  const normalized = diff.replace(/\r\n/g, "\n").trim();
  if (normalized.length === 0) {
    return [];
  }

  const parsedPatches = parsePatchFiles(normalized);
  const files = parsedPatches.flatMap((patch) =>
    patch.files.map((file) => ({
      path: file.name,
      additions: file.hunks.reduce((total, hunk) => total + hunk.additionLines, 0),
      deletions: file.hunks.reduce((total, hunk) => total + hunk.deletionLines, 0),
    })),
  );

  return files.toSorted((left, right) => left.path.localeCompare(right.path));
}

```
