Lines 1–10 at 318 (were 1–9 at 32)
1−import type { View } from "../../src/engine/index.ts";
1+import { createHash } from "node:crypto"; 2+import type { ReadView } from "../../src/engine/index.ts"; 23import { ProjectError } from "./project-error.ts"; 34import type { FileChange, Mode, Modes } from "./project-types.ts"; 56/** The listed files whose text differs between two views, before and after. */ 6−export function changesBetween(before: View, after: View, files: Iterable<string>): FileChange[] {
7+export function changesBetween(before: ReadView, after: ReadView, files: Iterable<string>): FileChange[] { 78 const out: FileChange[] = []; 89 for (const path of [...new Set(files)].toSorted()) { 910 const b = before.hasFile(path) ? before.text(path) : null; Lines 19–69 at 318 (were 18–25 at 32)
22+/** A changed file's text or blob, summed up: its size in UTF-8 bytes and its SHA-256, or a blob's hash. */ 23+export type FileSummary = { size: number; sha256: string } | { blob: string }; 26+ * changesBetween without the texts (abso issue 680, compare's summary): each changed file before and after as its size 27+ * and SHA-256, or its blob's hash for a binary file. Each text is read, summed up and let go, so a compare of thousands 28+ * of files never holds them all. 30+export function summariesBetween( 33+ files: Iterable<string>, 36+ before: FileSummary | null; 37+ after: FileSummary | null; 38+ mode?: { before: Mode; after: Mode }; 39+ blob?: { before: string | null; after: string | null }; 41+ const sum = (view: ReadView, path: string): FileSummary | null => { 42+ if (!view.hasFile(path)) return null; 43+ const blob = view.attrs(path).blob; 44+ if (blob !== null) return { blob }; 45+ const text = view.text(path); 46+ return { size: Buffer.byteLength(text, "utf8"), sha256: createHash("sha256").update(text, "utf8").digest("hex") }; 48+ const out: ReturnType<typeof summariesBetween> = []; 49+ for (const path of [...new Set(files)].toSorted()) { 50+ if (!differs(before, after, path)) continue; 51+ const mode = modeChange(before, after, path); 52+ const bb = before.attrs(path).blob; 53+ const ab = after.attrs(path).blob; 56+ before: sum(before, path), 57+ after: sum(after, path), 58+ ...(mode ? { mode } : {}), 59+ ...(bb !== ab ? { blob: { before: bb, after: ab } } : {}), 2165/** Whether a file differs between two views: its text, its mode, or its blob (what changesBetween lists). */ 22−export function differs(before: View, after: View, path: string): boolean {
66+export function differs(before: ReadView, after: ReadView, path: string): boolean { 2367 const had = before.hasFile(path); 2468 if (had !== after.hasFile(path)) return true; 2569 if (had && !before.sameText(path, after)) return true; Lines 73–79 at 318 (were 29–35 at 32)
3175/** A file's executable bit and link target, before and after, when either changed. */ 32−export function modeChange(before: View, after: View, path: string): { before: Mode; after: Mode } | undefined {
76+export function modeChange(before: ReadView, after: ReadView, path: string): { before: Mode; after: Mode } | undefined { 3377 const b = before.attrs(path); 3478 const a = after.attrs(path); 3579 if (b.exec === a.exec && b.link === a.link) return undefined; Lines 81–87 at 318 (were 37–43 at 32)
3983/** Every executable file and link in a view. */ 40−export function modesOf(view: View): Modes {
84+export function modesOf(view: ReadView): Modes { 4185 const out: Modes = {}; 4286 for (const path of view.paths()) { 4387 const a = view.attrs(path);