fix(server): checkpoint capture no longer rehashes unchanged untracked files #37482
Mergedjuliusmarmingemerged 0 commits into
main fromrefs/pull/37482/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/vcs/checkpointUntrackedBlobs.ts line 424Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +397,21 @@397+ "settled" in blob && blob.settled && before?.attributes.get(blob.path) !== undefined398+ ? [blob]399+ : [],400+ );401+ const candidatePaths = candidates.map((blob) => blob.path);402+ const [config, attributes, changing] = yield* Effect.all(403+ [404+ readConfig(input.cwd),405+ readAttributes(input.topLevel, input.env, candidatePaths),406+ changingAttributeDirectories(input.topLevel, candidatePaths, settledNs),407+ ],408+ { concurrency: "unbounded" },409+ );410+ const sameConfig = before !== undefined && config === before.config;411+ const admitted = candidates.flatMap((blob, index): UntrackedBlob[] => {412+ const value = attributes[index];413+ // A clean filter is a program whose output can depend on more than the file.414+ return sameConfig &&415+ value !== undefined &&416+ value === before.attributes.get(blob.path) &&417+ /\0(?:unspecified|unset)$/.test(value) &&
- @@ -0,0 +76,21 @@76+ changedNs: stat.mtimeNs > stat.ctimeNs ? stat.mtimeNs : stat.ctimeNs,77+ regular: stat.isFile(),78+ }),79+ () => undefined,80+ ),81+ ),82+ );83+ stats.push(...batch);84+ }85+ return stats;86+ });87+88+/**89+ * Lets a capture skip rehashing untracked files that have not changed since the last capture of90+ * the same workspace. A blob is reused only when a fresh `git add` would produce the same one:91+ * same file stat, same conversion attributes and config, still not ignored, still not tracked.92+ */93+export const make = (94+ execute: VcsDriver.VcsDriver["Service"]["execute"],95+ fileSystem: FileSystem.FileSystem,96+) => {@@ -0,0 +124,21 @@124+ values.push(fields[field + 2]!);125+ }126+ return values.join("\0");127+ });128+ });129+130+ // Config that changes the blob or mode `git add` records for an unchanged file.131+ const readConfig = (cwd: string) =>132+ execute({133+ operation,134+ cwd,135+ args: ["config", "--null", "--get-regexp", "^core\\.(autocrlf|eol|filemode)$"],136+ allowNonZeroExit: true,137+ }).pipe(Effect.map((result) => `${result.exitCode}\0${result.stdout}`));138+139+ /**140+ * Finds directories whose .gitattributes may have changed while Git hashed: a present file141+ * touched since just before the capture, or a missing one in a directory touched since then.142+ * Reading attributes before and after staging cannot see a change that was undone in between.143+ */144+ const changingAttributeDirectories = Effect.fnUntraced(function* (@@ -0,0 +301,21 @@301+ yield* execute({302+ operation,303+ cwd: input.cwd,304+ // core.ignorestat marks the new entries assume-unchanged, so git add trusts them as they are.305+ args: [306+ ...input.indexConfig,307+ "-c",308+ "core.ignorestat=true",309+ "update-index",310+ "-z",311+ "--index-info",312+ ],313+ stdin: blobs.map((blob) => `${blob.mode} ${blob.oid}\t${blob.path}\0`).join(""),314+ env: input.env,315+ });316+ // Tracked entries are racy against the index's old timestamp, not this rewrite's.317+ const indexTime = Math.floor(mtime.value.getTime() / 1000);318+ yield* fileSystem.utimes(indexFile, indexTime, indexTime);319+ return { reused: blobs, before };320+ },321+ Effect.orElseSucceed(() => NOTHING),@@ -531,0 +619,21 @@619+ if (input.args.includes("core.ignorestat=true")) reused++;620+ // Only a capture whose staging took real time looks for files to remember.621+ if (input.args.includes("add"))622+ return liveProcess.run(input).pipe(Effect.tap(() => TestClock.adjust("1 second")));623+ // The files are hashed and published by now, but not yet remembered.624+ return input.args.includes("update-ref")625+ ? liveProcess.run(input).pipe(Effect.tap(() => afterPublish))626+ : liveProcess.run(input);627+ },628+ }),629+ );630+ // A driver that has never captured this workspace hashes every file, as a first capture does.631+ const fresh = yield* GitVcsDriver.makeVcsDriverShape();632+ const cwd = yield* fs.makeTempDirectoryScoped({ prefix: "t3-untracked-blobs-" });633+ const { git, checkpointRef } = yield* makeCheckpointFixture(driver, cwd);634+ const write = (relativePath: string, contents: string) =>635+ fs.writeFileString(path.join(cwd, relativePath), contents);636+ yield* fs.makeDirectory(path.join(cwd, "nested"));637+ yield* write("nested/large.txt", "line\r\n".repeat(3 * 1024 * 1024));638+ // Only files left alone for a few seconds before a capture are remembered.639+ yield* TestClock.adjust("36500 days");
juliusmarminge merged this39e269a
juliusmarminge closed this
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed