{"draft":null,"from":33,"to":318,"files":[{"path":"client/src/folder.ts","added":28,"removed":7,"diff":"--- a/client/src/folder.ts\n+++ b/client/src/folder.ts\n@@ -26,8 +26,9 @@\n import { homedir } from \"node:os\";\n import { dirname, join, relative, sep } from \"node:path\";\n import { blobOf, keptWholeAs, readKnownBlobs } from \"./blobs.ts\";\n+import type { CleanFiles } from \"./clean-files.ts\";\n import { type GitHome, gitIgnoreSetup, type Ignore, isLocalOnly, makeIgnore, normalize, readAllSync } from \"./core.ts\";\n-import { type Mode, modeChange, onDisk, PLAIN, readKnownModes } from \"./modes.ts\";\n+import { FILE_MODE, type Mode, modeChange, onDisk, PLAIN, readKnownModes } from \"./modes.ts\";\n import { stateDir } from \"./state-dir.ts\";\n \n export { type Ignore, isLocalOnly, normalize, withEndingsOf } from \"./core.ts\";\n@@ -279,12 +280,13 @@\n \n // --- the known copy ---\n \n-function knownPath(root: string, rel: string): string {\n-\treturn join(stateDir(root), KNOWN, ...insideParts(rel));\n+/** `state` is the folder's stateDir, for a caller that looks up many files: finding it checks the disk each time. */\n+export function knownPath(root: string, rel: string, state: string = stateDir(root)): string {\n+\treturn join(state, KNOWN, ...insideParts(rel));\n }\n \n-export function readKnown(root: string, rel: string): string | undefined {\n-\treturn readText(knownPath(root, rel));\n+export function readKnown(root: string, rel: string, state?: string): string | undefined {\n+\treturn readText(knownPath(root, rel, state));\n }\n \n export function writeKnown(root: string, rel: string, text: string): void {\n@@ -321,11 +323,15 @@\n  * server's form), known files that are gone (null), and the modes that differ\n  * from the known modes. An empty file is a file like any other (\"\"); a link's\n  * text is \"\".\n+ *\n+ * `clean` lets status skip reading the files it found unchanged last time\n+ * (clean-files.ts). record never passes it, so it always reads every file.\n  */\n export function unrecorded(\n \troot: string,\n \tall = false,\n \tmeantBinary: ReadonlySet<string> = new Set(),\n+\tclean?: CleanFiles,\n ): {\n \tfiles: Map<string, string | null>;\n \tblobs: Map<string, BlobToSend>;\n@@ -342,10 +348,23 @@\n \tconst turnedBinary: TurnedBinary[] = [];\n \t// Exact names: on a case-insensitive disk, known/a.ts would also answer for A.ts, hiding a rename that changes only case.\n \tconst knownPaths = new Set(listKnown(root));\n+\tconst state = stateDir(root);\n \tconst knownBlobs = readKnownBlobs(root);\n \tconst knownModes = readKnownModes(root);\n+\tconst trusted = all ? undefined : clean;\n \tfor (const rel of walk(root, ignore)) {\n \t\tconst was = knownModes.get(rel) ?? PLAIN;\n+\t\t// Taken before the file is read, so an edit during the read changes the key.\n+\t\tconst key =\n+\t\t\ttrusted && knownPaths.has(rel) && was.link === null\n+\t\t\t\t? trusted.key(absolute(root, rel), knownPath(root, rel, state))\n+\t\t\t\t: undefined;\n+\t\tif (key && trusted!.check(rel, key)) {\n+\t\t\tpresent.add(rel);\n+\t\t\tconst change = modeChange(was, { exec: FILE_MODE ? (key.mode & 0o111) !== 0 : was.exec, link: null });\n+\t\t\tif (change) modes[rel] = change;\n+\t\t\tcontinue;\n+\t\t}\n \t\tconst d = onDisk(absolute(root, rel), was);\n \t\tif (d === undefined) continue;\n \t\tif (d.text === undefined) {\n@@ -367,11 +386,13 @@\n \t\t\tif (all || knownBlobs.get(rel) !== b.sha) blobs.set(rel, { sha: b.sha, bytes: b.bytes });\n \t\t} else {\n \t\t\tconst text = normalize(d.text);\n-\t\t\tconst known = knownPaths.has(rel) ? readKnown(root, rel) : undefined;\n+\t\t\tconst known = knownPaths.has(rel) ? readKnown(root, rel, state) : undefined;\n \t\t\tpresent.add(rel);\n \t\t\t// A file the server keeps whole has no known copy, only its hash (#46).\n \t\t\tif (all || (known !== text && !(known === undefined && keptWholeAs(text, knownBlobs.get(rel)))))\n \t\t\t\tout.set(rel, text);\n+\t\t\tif (key && d.link === null && known === text) trusted!.mark(rel, key, d.text.includes(\"\\r\"));\n+\t\t\telse trusted?.drop(rel);\n \t\t}\n \t\t// --all sends every file's whole mode, as it sends every file's text.\n \t\tconst change = all ? { exec: d.exec, link: d.link } : modeChange(was, d);\n@@ -434,7 +455,7 @@\n \t}\n \tconst autocrlf = config.get(\"core.autocrlf\");\n \tconst coreEol = config.get(\"core.eol\") ?? \"native\";\n-\tconst attrs = git([\"check-attr\", \"--stdin\", \"-z\", \"text\", \"eol\"], rels.join(\"\\0\") + \"\\0\");\n+\tconst attrs = git([\"check-attr\", \"--stdin\", \"-z\", \"text\", \"eol\"], `${rels.join(\"\\0\")}\\0`);\n \tif (attrs === undefined) return out;\n \tconst f = attrs.split(\"\\0\");\n \tconst seen = new Map<string, { text?: string; eol?: string }>();"}],"unmatched":[]}