@gitkraken/core-gitlens 0.38.1 → 0.38.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/dist/git/parsers/diffParser.d.ts +25 -0
  3. package/dist/git/parsers/diffParser.js +169 -23
  4. package/dist/git/parsers/diffParser.js.map +1 -1
  5. package/dist/git/service.d.ts +4 -1
  6. package/dist/git/service.js +6 -2
  7. package/dist/git/service.js.map +1 -1
  8. package/dist/git/watching/unwatchedCacheValidator.d.ts +26 -4
  9. package/dist/git/watching/unwatchedCacheValidator.js +110 -10
  10. package/dist/git/watching/unwatchedCacheValidator.js.map +1 -1
  11. package/dist/git-cli/exec/statWorkers.d.ts +50 -0
  12. package/dist/git-cli/exec/statWorkers.js +194 -0
  13. package/dist/git-cli/exec/statWorkers.js.map +1 -0
  14. package/dist/git-cli/parsers/blameParser.js +25 -5
  15. package/dist/git-cli/parsers/blameParser.js.map +1 -1
  16. package/dist/git-cli/parsers/logParser.js +28 -18
  17. package/dist/git-cli/parsers/logParser.js.map +1 -1
  18. package/dist/git-cli/parsers/statusParser.d.ts +5 -1
  19. package/dist/git-cli/parsers/statusParser.js +17 -6
  20. package/dist/git-cli/parsers/statusParser.js.map +1 -1
  21. package/dist/git-cli/parsers/treeParser.js +5 -3
  22. package/dist/git-cli/parsers/treeParser.js.map +1 -1
  23. package/dist/git-cli/parsers/worktreeParser.js +1 -41
  24. package/dist/git-cli/parsers/worktreeParser.js.map +1 -1
  25. package/dist/git-cli/providers/revision.js +3 -3
  26. package/dist/git-cli/providers/revision.js.map +1 -1
  27. package/dist/git-cli/providers/status.js +1 -0
  28. package/dist/git-cli/providers/status.js.map +1 -1
  29. package/dist/git-cli/service.d.ts +7 -4
  30. package/dist/git-cli/service.js +14 -17
  31. package/dist/git-cli/service.js.map +1 -1
  32. package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +2 -0
  33. package/dist/plus/integrations/authentication/configuredIntegrationService.js +23 -1
  34. package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
  35. package/dist/plus/integrations/authentication/models.d.ts +1 -0
  36. package/dist/plus/integrations/authentication/models.js.map +1 -1
  37. package/dist/plus/integrations/authentication/observedAuthenticationProvider.js +4 -1
  38. package/dist/plus/integrations/authentication/observedAuthenticationProvider.js.map +1 -1
  39. package/dist/plus/integrations/integrationService.js +7 -1
  40. package/dist/plus/integrations/integrationService.js.map +1 -1
  41. package/dist/plus/integrations/models/integration.d.ts +1 -0
  42. package/dist/plus/integrations/models/integration.js +8 -0
  43. package/dist/plus/integrations/models/integration.js.map +1 -1
  44. package/dist/plus/integrations/models/issuesIntegration.d.ts +5 -0
  45. package/dist/plus/integrations/models/issuesIntegration.js +33 -1
  46. package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
  47. package/dist/plus/integrations/providers/jira.d.ts +3 -2
  48. package/dist/plus/integrations/providers/jira.js +36 -17
  49. package/dist/plus/integrations/providers/jira.js.map +1 -1
  50. package/dist/plus/integrations/providers/linear.d.ts +1 -0
  51. package/dist/plus/integrations/providers/linear.js +40 -17
  52. package/dist/plus/integrations/providers/linear.js.map +1 -1
  53. package/dist/plus/integrations/providers/utils/discoveryCache.d.ts +6 -3
  54. package/dist/plus/integrations/providers/utils/discoveryCache.js +12 -6
  55. package/dist/plus/integrations/providers/utils/discoveryCache.js.map +1 -1
  56. package/dist/utils/env/node/exec.js +24 -22
  57. package/dist/utils/env/node/exec.js.map +1 -1
  58. package/dist/utils/string.d.ts +15 -0
  59. package/dist/utils/string.js +61 -1
  60. package/dist/utils/string.js.map +1 -1
  61. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"unwatchedCacheValidator.js","names":[],"sources":["../../../../git/src/watching/unwatchedCacheValidator.ts"],"sourcesContent":["import { raceWithTimeout } from '@gitlens/utils/cancellation.js';\nimport { joinPaths } from '@gitlens/utils/path.js';\nimport type { ResourceUsage } from '@gitlens/utils/resourceUsage.js';\nimport type { Cache } from '../cache.js';\nimport { FileType } from '../context.js';\nimport type { RepositoryChange } from '../models/repository.js';\nimport { isIgnoredWorktreeEntry, parseWorktreeAdminPath } from '../utils/repository.utils.js';\nimport { allWatchedRepositoryChanges, classifyGitDirChange } from './classifyChange.js';\nimport type { GitDirProbe } from './gitDirPoller.js';\nimport { GitDirProbeTarget } from './gitDirPoller.js';\nimport { gitDirCommonProbes, gitDirRootProbes } from './watcherPatterns.js';\nimport { isNotFound } from './watchGroup.js';\nimport { defaultRepoDelay } from './watchSession.js';\n\ntype ProbeStat = { readonly mtime: number; readonly size: number };\n/** The stats of one validation, by absolute path, shared by every git dir it reads */\ntype StatMemo = Map<string, Promise<ProbeStat | undefined>>;\n/** The reading of a path whose stat failed; never a whole second, so never racy */\nconst unreadable: ProbeStat = { mtime: -1, size: -1 };\n\nexport interface UnwatchedCacheValidatorOptions {\n\treadonly cache: Cache;\n\t/** A path's modification time (ms since the epoch) and size; `undefined` when it doesn't exist */\n\treadonly stat: (path: string) => Promise<ProbeStat | undefined>;\n\t/** A directory's entries with their `FileType`s; a rejection whose `code` is `ENOENT` or `FileNotFound` means it isn't there */\n\treadonly readDirectory: (path: string) => Promise<readonly (readonly [string, number])[]>;\n\t/** A file's bytes; `undefined` when it doesn't exist. Without it, no worktree is ignored */\n\treadonly readFile?: (path: string) => Promise<Uint8Array | undefined>;\n\t/**\n\t * The absolute, normalized folders whose worktrees core ignores (see `GitProvider.getIgnoredWorktreeRoots`), asked\n\t * with a `repoPath` whose git dir the cache holds; a worktree in one is left out of the worktree list, so what moves\n\t * in its admin entry changes nothing cached. A rejection means none is ignored\n\t */\n\treadonly getIgnoredWorktreeRoots?: (repoPath: string) => Promise<readonly string[]>;\n\t/**\n\t * Caches `repoPath`'s git dir without running git, for a repository nothing resolved one for yet (as when only its\n\t * branches, remotes or tags were read); whether one is cached. Without it, or when it answers `false`, such a\n\t * repository isn't validated: a layout git's files alone can't answer for (a bare repository, a submodule, a\n\t * `--separate-git-dir` checkout, a `core.worktree`) stays unvalidated until a read resolves its git dir. A rejection\n\t * is a failure to look, retried soon; `false` is a repository its files can't answer for, tried again rarely\n\t */\n\treadonly resolveGitDir?: (repoPath: string) => Promise<boolean>;\n\t/**\n\t * Whether a `.git` watcher covers `repoPath` and is live (see `RepositoryWatchService.isRepoWatched`): one that is\n\t * suspended holds what it hears until it resumes, so a repository is unwatched meanwhile, without being announced\n\t */\n\treadonly isWatched: (repoPath: string) => boolean;\n\t/** Milliseconds since the epoch, the clock `stat`'s `mtime` is on. Default: `Date.now` */\n\treadonly now?: () => number;\n\t/**\n\t * How long a read waits for a validation before it's served from the cache as is, and how long a hung file-system\n\t * call holds back other repositories' validations. Default: 1000\n\t */\n\treadonly timeoutMs?: number;\n\t/**\n\t * How many of Node's file-system threads (libuv's pool) the validator's calls may hold at once, counting those hung\n\t * past {@link timeoutMs}; at most two run at once. Default: 2, which leaves a host two of the pool's default four\n\t */\n\treadonly maxFsThreads?: number;\n}\n\n/**\n * A target read within this long of its last validation is served as is: a watched repository's read is as stale, as\n * its watch session debounces what its watcher reports by as much\n */\nconst validationWindowMs = defaultRepoDelay;\n/**\n * How long a repository whose files can't show its git dir (a bare repository, a submodule) is left before they are\n * looked at again. Any read that resolves its git dir with git makes the lookup unneeded\n */\nconst unresolvableRetryMs = 30_000;\n/** Targets kept per kind; one dropped just takes a new baseline */\nconst maxTargets = 512;\n/**\n * Other worktrees' first baselines one validation takes with its own. Their stats run one at a time per repository\n * inside the read that triggered them, so the batch is kept small enough that a slow file system doesn't push that read\n * past its timeout; the worktrees left out batch the rest at their own first validation. Never more than fit under\n * {@link maxTargets}, as a target dropped for them would clear the shared entries again\n */\nconst maxSiblingBaselines = 64;\n/**\n * Linked worktrees' first baselines one validation clears only their own entries for, when the common git dir vouches\n * for each one's HEAD; past it, they clear the shared entries too, once. Clearing the shared entries costs a ref listing,\n * a default branch read and the reader's current branch, and that listing seeds every worktree's current branch again;\n * clearing a worktree's own entries costs it a read of its own current branch. So past a few worktrees, one clear of the\n * shared entries is the cheaper\n */\nconst maxOwnBaselines = 3;\n/** Polls one validation runs to take the baselines of the directories it finds; the next validation resumes from there */\nconst maxDiscoveryPolls = 16;\n/**\n * How long a reading stays racy on a file system whose timestamps tick by whole seconds (or two, as FAT's): a write in\n * the same second as the stat leaves the same mtime. Counted both from the mtime and from when the validator first saw\n * the reading, as a server whose clock runs ahead of ours stamps writes with a second that ends, on our clock, no later\n * than this long after we first saw it\n */\nconst racyMtimeWindowMs = 2000;\n/** Racy candidates whose first sighting is remembered; the oldest is dropped past it, which only extends its raciness */\nconst maxRacyReadings = maxTargets * 8;\n/** How long a read waits for a validation before it's served from the cache as is */\nconst defaultValidationTimeoutMs = 1000;\n/** The longest delay `setTimeout` keeps; a longer one (`Infinity` included) fires at once */\nconst maxValidationTimeoutMs = 2 ** 31 - 1;\n/**\n * A stat or listing holds one of Node's file-system threads (libuv's pool, 4 by default) until it returns, which on a\n * hung mount is never, as it can't be cancelled. A repository makes one at a time and the validator two, holding no more\n * threads than it's allowed counting those outstanding past the timeout\n */\nconst maxFsCallsPerRepo = 1;\nconst maxFsCalls = 2;\nconst defaultMaxFsThreads = 2;\n\nconst refNamespaces: readonly string[] = ['refs/heads', 'refs/remotes', 'refs/tags'];\nconst reftableProbePath = 'reftable/tables.list';\nconst worktreeHeadRegex = /^worktrees\\/([^/]+)\\/(?:HEAD|reftable\\/tables\\.list)$/;\n\n/**\n * The git dir itself, as the gate of the files in it that git writes by lockfile and rename, or creates and deletes:\n * either moves the directory's mtime, so its reading stands in for theirs, which are read only once it moved. Each\n * gate's files have a probe target of their own, whose readings outlast the validations that skip it; were they left\n * out of a shared target instead, their next reading would be a new baseline, losing what changed meanwhile. What git\n * writes in place (`FETCH_HEAD`, an admin entry's `gitdir`, the rebase and sequencer state `--edit-todo` rewrites) is\n * read every time. This saves stats only while the gate holds still: an index write moves the git dir too, so an\n * active checkout reads as much as ever, and an idle one, as unwatched repositories mostly are, reads just the gate.\n */\nconst gitDirGatePath = '';\nconst rootGatedPaths: ReadonlySet<string> = new Set([\n\t'HEAD',\n\t'ORIG_HEAD',\n\t'MERGE_HEAD',\n\t'CHERRY_PICK_HEAD',\n\t'REVERT_HEAD',\n\t'REBASE_HEAD',\n]);\nconst commonGatedPaths: ReadonlySet<string> = new Set(['packed-refs', 'config', 'shallow']);\n\n// The index is what working-tree status reads, which these caches aren't; `info/exclude` clears only the gitignore filter\nconst rootProbes: readonly GitDirProbe[] = gitDirRootProbes.filter(p => p.path !== 'index');\nconst rootAlwaysProbes: readonly GitDirProbe[] = [\n\t{ path: gitDirGatePath },\n\t...rootProbes.filter(p => !rootGatedPaths.has(p.path)),\n\t{ path: reftableProbePath },\n];\nconst rootGatedProbes: readonly GitDirProbe[] = rootProbes.filter(p => rootGatedPaths.has(p.path));\n/**\n * What a worktree's own git dir can report, which is all its validation without a baseline reports: the shared kinds\n * are the common git dir's to report, from a baseline of its own, or by another worktree's watcher that covers it\n */\nconst rootReportableChanges: readonly RepositoryChange[] = [\n\t...new Set(\n\t\t[...rootAlwaysProbes, ...rootGatedProbes].flatMap((p): RepositoryChange[] => {\n\t\t\tif (p.path === gitDirGatePath) return [];\n\t\t\t// As `classify` reports a worktree's own reftable, which moves with its HEAD\n\t\t\tif (p.path === reftableProbePath) return ['head', 'heads'];\n\n\t\t\treturn (p.emitAs ?? [p.path]).flatMap(path => classifyGitDirChange(path) ?? []);\n\t\t}),\n\t),\n];\nconst commonProbes: readonly GitDirProbe[] = [\n\t...gitDirCommonProbes.filter(p => p.path !== 'info/exclude'),\n\t{ path: reftableProbePath },\n\t// Dropping a stash entry other than the newest rewrites only the stash's reflog, leaving `refs/stash` as it was\n\t{ path: 'logs/refs/stash', emitAs: ['refs/stash'] },\n\t// A replacement (`git replace`) changes ancestry, and the cached ref list holds the replace refs\n\t{ path: 'refs/replace' },\n];\nconst commonAlwaysProbes: readonly GitDirProbe[] = [\n\t{ path: gitDirGatePath },\n\t...commonProbes.filter(p => !commonGatedPaths.has(p.path)),\n];\nconst commonGatedProbes: readonly GitDirProbe[] = commonProbes.filter(p => commonGatedPaths.has(p.path));\n\ninterface ValidationResult {\n\treadonly changes: ReadonlySet<RepositoryChange>;\n\t/** With a `'worktreeHead'` among `changes`, the admin ids of the linked worktrees whose HEAD moved; `undefined` when any may have */\n\treadonly movedWorktrees: ReadonlySet<string> | undefined;\n\t/**\n\t * Read without a baseline (a first validation, or one after a failure or a reset dropped it), so `changes` is all its\n\t * git dir can report rather than what moved\n\t */\n\treadonly noBaseline: boolean;\n}\n\n/** Something reads wait for, at most until their timeout */\ninterface Waitable {\n\t/** In flight; settles once what it found was applied */\n\trunning?: Promise<void>;\n\t/** What outlasted a read's wait; while it's still {@link running}, reads don't wait for it */\n\tslow?: Promise<void>;\n\t/** What it started that reads wait for through it, which a wait that outlasts it marks slow too */\n\treadonly started?: (readonly [Waitable, Promise<void>])[];\n\tsettledAt?: number;\n}\n\ninterface TargetState extends Waitable {\n\treadonly dir: ProbedGitDir;\n\truns: number;\n}\n\n/** A resolution of a git dir nothing resolved, then the validation that follows it */\ninterface ResolutionState extends Waitable {\n\treadonly started: (readonly [Waitable, Promise<void>])[];\n\t/** How long after it settled the resolution is tried again: briefly for a failure, longer for a definite \"no\" */\n\tretryAfterMs: number;\n}\n\n/**\n * Keeps the caches that never expire fresh for repositories no `.git` watcher covers: before such a read, stats the\n * files a watcher would have reported (see {@link UnwatchedCacheValidatorOptions.stat}) and applies what moved to the\n * cache as a watcher event would have. Both a worktree's own git dir and the common one are validated while that\n * worktree is unwatched; while another worktree's watcher covers the common one, what moved there clears only the\n * unwatched worktrees' own entries, but for a linked worktree's HEAD moving, which is applied as that worktree's own\n * report would be (see {@link apply}). A repository whose git dir nothing resolved yet is validated once\n * {@link UnwatchedCacheValidatorOptions.resolveGitDir} resolves one; a repository whose files can't show it is looked at\n * again rarely, and one whose resolution failed within the validation window. A read waits at most\n * {@link UnwatchedCacheValidatorOptions.timeoutMs} for a validation (and a resolution before it); one that outlasts it\n * is left to finish on its own, and the reads meanwhile are served as is.\n */\nexport class UnwatchedCacheValidator {\n\tprivate readonly cache: Cache;\n\tprivate readonly isWatched: (repoPath: string) => boolean;\n\tprivate readonly now: () => number;\n\tprivate readonly timeoutMs: number;\n\tprivate readonly resolveGitDir: ((repoPath: string) => Promise<boolean>) | undefined;\n\tprivate readonly gate: FileSystemGate;\n\t/** Since it was created; what {@link getResourceUsage} reports */\n\tprivate readonly counts = { validations: 0, validationsApplied: 0, waitsTimedOut: 0, gitDirLookups: 0 };\n\tprivate readonly dirOptions: ProbedGitDirOptions;\n\t/** Keyed by repo path */\n\tprivate readonly roots = new Map<string, TargetState>();\n\t/** Keyed by common path */\n\tprivate readonly commons = new Map<string, TargetState>();\n\t/** Keyed by absolute path; the readings that may be racy, with when each was first read */\n\tprivate readonly racyReadings = new Map<string, { mtime: number; size: number; firstSeen: number }>();\n\t/**\n\t * Keyed by repo path; one that found nothing is kept, so the reads meanwhile don't retry it: for the window after a\n\t * failure, for {@link unresolvableRetryMs} after a git dir the files can't show\n\t */\n\tprivate readonly resolutions = new Map<string, ResolutionState>();\n\t/** The validation {@link onWatched} ran as a watcher attached, by repo path, which reads wait for while it runs */\n\tprivate readonly handoffs = new Map<string, Promise<void>>();\n\t/**\n\t * By the repo path of a watched worktree, what moved in its common git dir that its watcher was left to clear, and\n\t * whether its own HEAD's move, which the common git dir saw, was left to it to report (see {@link applyMovedHeads})\n\t */\n\tprivate readonly deferred = new Map<\n\t\tstring,\n\t\t{ readonly commonPath: string; readonly changes: Set<RepositoryChange>; headMoved: boolean }\n\t>();\n\n\tconstructor(options: UnwatchedCacheValidatorOptions) {\n\t\tthis.cache = options.cache;\n\t\tthis.isWatched = options.isWatched;\n\t\tthis.now = options.now ?? ((): number => Date.now());\n\t\tthis.timeoutMs = Math.min(options.timeoutMs ?? defaultValidationTimeoutMs, maxValidationTimeoutMs);\n\t\tthis.resolveGitDir = options.resolveGitDir;\n\t\t// A `NaN` would fail every slot check, so nothing would ever be validated\n\t\tconst maxFsThreads = Math.floor(options.maxFsThreads ?? defaultMaxFsThreads);\n\t\tthis.gate = new FileSystemGate(\n\t\t\tthis.timeoutMs,\n\t\t\tNumber.isNaN(maxFsThreads) ? defaultMaxFsThreads : Math.max(1, maxFsThreads),\n\t\t);\n\t\tthis.dirOptions = {\n\t\t\tgate: this.gate,\n\t\t\tstat: options.stat,\n\t\t\treadDirectory: options.readDirectory,\n\t\t\treadFile: options.readFile,\n\t\t\tgetIgnoredWorktreeRoots: options.getIgnoredWorktreeRoots,\n\t\t\tisRacy: (stat, path) => this.isRacy(stat, path),\n\t\t};\n\t}\n\n\t/**\n\t * Whether `stat` of `path` may still show the same file a write in its own second would leave. Only a whole-second\n\t * mtime can, and only until its second ended: by the mtime's own clock, and by ours since the reading was first\n\t * seen, whichever comes first\n\t */\n\tprivate isRacy(stat: ProbeStat, path: string): boolean {\n\t\tconst now = this.now();\n\t\tif (stat.mtime % 1000 !== 0 || now - stat.mtime >= racyMtimeWindowMs) {\n\t\t\tthis.racyReadings.delete(path);\n\t\t\treturn false;\n\t\t}\n\n\t\tlet reading = this.racyReadings.get(path);\n\t\tif (reading == null || reading.mtime !== stat.mtime || reading.size !== stat.size) {\n\t\t\treading = { mtime: stat.mtime, size: stat.size, firstSeen: now };\n\t\t\tthis.racyReadings.delete(path);\n\t\t\tthis.racyReadings.set(path, reading);\n\t\t\tif (this.racyReadings.size > maxRacyReadings) {\n\t\t\t\tconst oldest = this.racyReadings.keys().next();\n\t\t\t\tif (!oldest.done) {\n\t\t\t\t\tthis.racyReadings.delete(oldest.value);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Kept newest, so the cap drops the reading read longest ago, not one still read\n\t\t\tthis.racyReadings.delete(path);\n\t\t\tthis.racyReadings.set(path, reading);\n\t\t\t// A clock set back since counts from now, or the reading would stay racy until it caught up\n\t\t\tif (now < reading.firstSeen) {\n\t\t\t\treading.firstSeen = now;\n\t\t\t}\n\t\t}\n\n\t\treturn now - reading.firstSeen < racyMtimeWindowMs;\n\t}\n\n\t/**\n\t * Validates what `repoPath`'s reads would be served from, unless a watcher covers it or it was validated within\n\t * the last 250ms. `undefined` when there's nothing to wait for; otherwise settles once what moved was applied to\n\t * the cache, or after {@link UnwatchedCacheValidatorOptions.timeoutMs} with the cache as is, whichever is first.\n\t * Never rejects. A path that can't be read counts as moved as it becomes unreadable and again as it becomes\n\t * readable; a directory that can't be listed is listed again at the next validation, and what changes deeper inside\n\t * it goes unseen until it can be.\n\t */\n\tvalidate(repoPath: string): Promise<void> | undefined {\n\t\treturn this.handoffs.get(repoPath) ?? this.run(repoPath, false);\n\t}\n\n\t/**\n\t * A watcher attached to `repoPath`, so it reports only what changes from now on: validates now what changed since\n\t * the last validation, whatever the window, and has `repoPath`'s reads wait for it.\n\t */\n\tonWatched(repoPath: string): void {\n\t\tconst validation = this.run(repoPath, true);\n\t\tif (validation == null) return;\n\n\t\tconst handoff: Promise<void> = validation.finally(() => {\n\t\t\tif (this.handoffs.get(repoPath) === handoff) {\n\t\t\t\tthis.handoffs.delete(repoPath);\n\t\t\t}\n\t\t});\n\t\tthis.handoffs.set(repoPath, handoff);\n\t}\n\n\t/**\n\t * A watcher left `repoPath`, dropping what it held back unreported. What moved in its common git dir that an\n\t * unwatched sibling's validation left to it is applied now, since that validation took the shared baseline past it,\n\t * and so is its own HEAD's move that the common git dir saw, as its watcher would have reported it; whatever else it\n\t * dropped is still ahead of its own baselines.\n\t */\n\tonUnwatched(repoPath: string): void {\n\t\tconst deferred = this.deferred.get(repoPath);\n\t\tif (deferred == null) return;\n\n\t\tthis.deferred.delete(repoPath);\n\t\tif (deferred.changes.size) {\n\t\t\t// To the common path, which keys the shared entries, as `repoPath` may already be unregistered\n\t\t\tthis.cache.onRepositoryChanged(deferred.commonPath, deferred.changes);\n\t\t\t// And to a linked worktree's own entries while it is still registered, which its watcher would have cleared too\n\t\t\tif (repoPath !== deferred.commonPath && this.cache.isRegistered(repoPath)) {\n\t\t\t\tthis.cache.applyRepositoryChanges(repoPath, deferred.changes, 'share', { worktreeOnly: true });\n\t\t\t}\n\t\t}\n\t\tif (deferred.headMoved) {\n\t\t\t// Not added to the changes, which would clear the main checkout's own entries along with the shared ones\n\t\t\tconst registered = this.cache.getCommonPath(repoPath) === deferred.commonPath;\n\t\t\tthis.cache.onRepositoryChanged(registered ? repoPath : deferred.commonPath, ['head', 'heads']);\n\t\t}\n\t}\n\n\tprivate run(repoPath: string, force: boolean): Promise<void> | undefined {\n\t\tif (!force && this.isWatched(repoPath)) return undefined;\n\n\t\t// A watcher attaching has no baseline to hand off without a git dir\n\t\tif (this.cache.gitDir.get(repoPath) == null) return force ? undefined : this.resolveThenValidate(repoPath);\n\n\t\tconst waits = this.start(repoPath, force);\n\t\treturn waits?.length ? this.waitAtMost(waits) : undefined;\n\t}\n\n\t/** Starts validating `repoPath`, or joins the validations in flight; what a read waits for */\n\tprivate start(repoPath: string, force: boolean): (readonly [Waitable, Promise<void>])[] | undefined {\n\t\tconst gitDir = this.cache.gitDir.get(repoPath);\n\t\tif (gitDir == null) return undefined;\n\n\t\tconst commonPath = this.cache.getCommonPath(repoPath);\n\t\t// A watcher suspended holds what was left to it until it resumes, and suspending announces nothing\n\t\tfor (const [path, deferred] of this.deferred) {\n\t\t\tif (deferred.commonPath === commonPath && !this.isWatched(path)) {\n\t\t\t\tthis.onUnwatched(path);\n\t\t\t}\n\t\t}\n\n\t\tconst commonGitDir = (gitDir.commonUri ?? gitDir.uri).fsPath;\n\t\tconst root = this.getTarget(this.roots, repoPath, 'root', gitDir.uri.fsPath, commonPath, commonGitDir);\n\t\t// A root never validated reports everything its git dir could have moved, which clears the repository's shared\n\t\t// entries unless the common git dir vouches for its HEAD (see `apply`); the other worktrees never validated take\n\t\t// their first baselines with it, so each clears only its own entries rather than the shared ones again\n\t\tconst siblings = root.runs === 0 ? this.getSiblingTargets(repoPath, commonPath, commonGitDir) : [];\n\t\t// Read even while another worktree's watcher covers it: that watcher clears the shared entries, never this\n\t\t// worktree's own\n\t\tconst common = this.getTarget(this.commons, commonPath, 'common', commonGitDir, commonPath, commonGitDir);\n\n\t\tconst waits: (readonly [Waitable, Promise<void>])[] = [];\n\t\tconst previous: Promise<void>[] = [];\n\t\tconst start = (state: TargetState | undefined): TargetState | undefined => {\n\t\t\tif (state == null) return undefined;\n\n\t\t\tif (state.running != null) {\n\t\t\t\tif (!force) {\n\t\t\t\t\tif (state.slow !== state.running) {\n\t\t\t\t\t\twaits.push([state, state.running]);\n\t\t\t\t\t}\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tprevious.push(state.running);\n\t\t\t} else if (!force && state.settledAt != null) {\n\t\t\t\t// A clock set back since counts as outside the window, or nothing would validate until it caught up\n\t\t\t\tconst elapsed = this.now() - state.settledAt;\n\t\t\t\tif (elapsed >= 0 && elapsed < validationWindowMs) return undefined;\n\t\t\t}\n\t\t\treturn state;\n\t\t};\n\t\tconst startedRoot = start(root);\n\t\tconst startedCommon = start(common);\n\n\t\tif (startedRoot != null || startedCommon != null) {\n\t\t\tconst job = this.runTargets(repoPath, commonPath, startedRoot, startedCommon, common, siblings, previous);\n\t\t\tif (startedRoot != null) {\n\t\t\t\tstartedRoot.running = job;\n\t\t\t}\n\t\t\tif (startedCommon != null) {\n\t\t\t\tstartedCommon.running = job;\n\t\t\t}\n\t\t\t// So a read of one joins this validation rather than starting its own\n\t\t\tfor (const [, state] of siblings) {\n\t\t\t\tstate.running = job;\n\t\t\t}\n\t\t\tfor (const state of [startedRoot, startedCommon, ...siblings.map(([, s]) => s)]) {\n\t\t\t\tif (state != null) {\n\t\t\t\t\twaits.push([state, job]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn waits;\n\t}\n\n\t/**\n\t * Resolves the git dir of `repoPath` (through the gate, as one call, keyed by `repoPath` since its common git dir\n\t * isn't known yet), then validates it as usual within the same wait. That first validation has no baseline.\n\t */\n\tprivate resolveThenValidate(repoPath: string): Promise<void> | undefined {\n\t\tconst resolveGitDir = this.resolveGitDir;\n\t\tif (resolveGitDir == null) return undefined;\n\n\t\tlet state = this.resolutions.get(repoPath);\n\t\tlet running = state?.running;\n\t\tif (state != null && running != null) {\n\t\t\tif (state.slow === running) return undefined;\n\t\t} else {\n\t\t\tif (state?.settledAt != null) {\n\t\t\t\tconst elapsed = this.now() - state.settledAt;\n\t\t\t\tif (elapsed >= 0 && elapsed < state.retryAfterMs) return undefined;\n\t\t\t}\n\n\t\t\tstate = { started: [], retryAfterMs: validationWindowMs };\n\t\t\trunning = this.startResolution(repoPath, resolveGitDir, state);\n\t\t}\n\n\t\treturn this.waitAtMost([[state, running]]);\n\t}\n\n\tprivate startResolution(\n\t\trepoPath: string,\n\t\tresolveGitDir: (repoPath: string) => Promise<boolean>,\n\t\tstate: ResolutionState,\n\t): Promise<void> {\n\t\tlet found = false;\n\t\tthis.counts.gitDirLookups++;\n\t\tconst running: Promise<void> = this.gate\n\t\t\t.run(repoPath, () => resolveGitDir(repoPath))\n\t\t\t.catch((): undefined => undefined)\n\t\t\t.then(async resolved => {\n\t\t\t\tfound = resolved === true;\n\t\t\t\t// Only a definite \"no\" waits long: a failure may pass\n\t\t\t\tif (resolved === false) {\n\t\t\t\t\tstate.retryAfterMs = unresolvableRetryMs;\n\t\t\t\t}\n\t\t\t\tif (!found || this.isWatched(repoPath)) return;\n\n\t\t\t\tconst waits = this.start(repoPath, false);\n\t\t\t\tif (waits == null) return;\n\n\t\t\t\tstate.started.push(...waits);\n\t\t\t\tawait Promise.all(waits.map(([, validation]) => validation));\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tstate.settledAt = this.now();\n\t\t\t\tstate.running = undefined;\n\t\t\t\t// Reads go by the cached git dir from here on\n\t\t\t\tif (found && this.resolutions.get(repoPath) === state) {\n\t\t\t\t\tthis.resolutions.delete(repoPath);\n\t\t\t\t}\n\t\t\t});\n\t\tstate.running = running;\n\n\t\tthis.resolutions.delete(repoPath);\n\t\tthis.resolutions.set(repoPath, state);\n\t\tif (this.resolutions.size > maxTargets) {\n\t\t\tconst oldest = this.resolutions.keys().next();\n\t\t\tif (!oldest.done) {\n\t\t\t\tthis.resolutions.delete(oldest.value);\n\t\t\t}\n\t\t}\n\t\treturn running;\n\t}\n\n\t/**\n\t * Settles once `waits`' validations do, or once the timeout elapses, latching those still running as slow (and what\n\t * they started) so the reads after it don't wait for them again\n\t */\n\tprivate waitAtMost(waits: readonly (readonly [Waitable, Promise<void>])[]): Promise<void> {\n\t\tconst latch = (state: Waitable, running: Promise<void>): void => {\n\t\t\tif (state.running !== running) return;\n\n\t\t\tstate.slow = running;\n\t\t\tfor (const [started, startedRunning] of state.started ?? []) {\n\t\t\t\tlatch(started, startedRunning);\n\t\t\t}\n\t\t};\n\n\t\t// The waits never reject, so only the timeout lands in the rejection handler\n\t\treturn raceWithTimeout(Promise.all(waits.map(([, running]) => running)), this.timeoutMs).then(\n\t\t\t() => undefined,\n\t\t\t() => {\n\t\t\t\tthis.counts.waitsTimedOut++;\n\t\t\t\tfor (const [state, running] of waits) {\n\t\t\t\t\tlatch(state, running);\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * What validating has cost, for a host to weigh against watching: counts since the validator was created of the\n\t * validations run, those that cleared something, the reads served as is after their wait timed out, the git dir\n\t * lookups, and the file-system calls made; and, as of now, the calls stuck on a hung mount and the git dirs kept\n\t */\n\tgetResourceUsage(): ResourceUsage {\n\t\treturn {\n\t\t\t'unwatchedValidation.validations.count': this.counts.validations,\n\t\t\t'unwatchedValidation.validationsApplied.count': this.counts.validationsApplied,\n\t\t\t'unwatchedValidation.waitsTimedOut.count': this.counts.waitsTimedOut,\n\t\t\t'unwatchedValidation.gitDirLookups.count': this.counts.gitDirLookups,\n\t\t\t'unwatchedValidation.fsCalls.count': this.gate.calls,\n\t\t\t'unwatchedValidation.fsCallsStuck.count': this.gate.stuckCalls,\n\t\t\t'unwatchedValidation.gitDirs.count': this.roots.size + this.commons.size,\n\t\t};\n\t}\n\n\t/** The repository's other worktrees whose watchers cover its common git dir */\n\tprivate getCommonWatchers(repoPath: string, commonPath: string): string[] {\n\t\tconst watchers = new Set<string>();\n\t\tif (commonPath !== repoPath && this.isWatched(commonPath)) {\n\t\t\twatchers.add(commonPath);\n\t\t}\n\t\tfor (const path of this.cache.getWorktreePaths(commonPath)) {\n\t\t\tif (path !== repoPath && this.isWatched(path)) {\n\t\t\t\twatchers.add(path);\n\t\t\t}\n\t\t}\n\t\treturn [...watchers];\n\t}\n\n\tprivate getTarget(\n\t\ttargets: Map<string, TargetState>,\n\t\tkey: string,\n\t\tkind: 'root' | 'common',\n\t\tbasePath: string,\n\t\tcommonPath: string,\n\t\tcommonGitDir: string,\n\t): TargetState {\n\t\tlet state = targets.get(key);\n\t\tif (state?.dir.basePath === basePath && state.dir.commonPath === commonPath) {\n\t\t\t// Kept newest, so the cap drops the target read longest ago\n\t\t\ttargets.delete(key);\n\t\t} else {\n\t\t\tstate = { dir: new ProbedGitDir(kind, basePath, commonPath, commonGitDir, this.dirOptions), runs: 0 };\n\t\t}\n\t\ttargets.set(key, state);\n\n\t\tif (targets.size > maxTargets) {\n\t\t\tconst oldest = targets.keys().next();\n\t\t\tif (!oldest.done) {\n\t\t\t\ttargets.delete(oldest.value);\n\t\t\t}\n\t\t}\n\t\treturn state;\n\t}\n\n\t/**\n\t * The root targets, new, of `repoPath`'s registered sibling worktrees that never had one: unwatched (a watcher covers\n\t * its own git dir, and validates it as it attaches), with a git dir the cache resolved in the same common git dir\n\t */\n\tprivate getSiblingTargets(\n\t\trepoPath: string,\n\t\tcommonPath: string,\n\t\tcommonGitDir: string,\n\t): (readonly [string, TargetState])[] {\n\t\tconst siblings: (readonly [string, TargetState])[] = [];\n\t\tconst room = Math.min(maxSiblingBaselines, maxTargets - this.roots.size);\n\t\tfor (const path of this.cache.getWorktreePaths(commonPath)) {\n\t\t\tif (siblings.length >= room) break;\n\t\t\t// One that failed and was reset still has its target, as does one in flight\n\t\t\tif (path === repoPath || this.roots.has(path) || this.isWatched(path)) continue;\n\t\t\tif (this.cache.getCommonPath(path) !== commonPath) continue;\n\n\t\t\tconst gitDir = this.cache.gitDir.get(path);\n\t\t\tif (gitDir == null || (gitDir.commonUri ?? gitDir.uri).fsPath !== commonGitDir) continue;\n\n\t\t\tsiblings.push([\n\t\t\t\tpath,\n\t\t\t\tthis.getTarget(this.roots, path, 'root', gitDir.uri.fsPath, commonPath, commonGitDir),\n\t\t\t]);\n\t\t}\n\t\treturn siblings;\n\t}\n\n\tprivate async runTargets(\n\t\trepoPath: string,\n\t\tcommonPath: string,\n\t\troot: TargetState | undefined,\n\t\tcommon: TargetState | undefined,\n\t\t/** The repository's common target, whether or not this validation started it */\n\t\tcommonTarget: TargetState,\n\t\tsiblings: readonly (readonly [string, TargetState])[],\n\t\tprevious: readonly Promise<void>[],\n\t): Promise<void> {\n\t\tconst rootRun = root != null ? ++root.runs : 0;\n\t\tconst commonRun = common != null ? ++common.runs : 0;\n\t\tconst siblingRuns = siblings.map(([, state]) => ++state.runs);\n\t\t// Before anything is awaited: a watcher that attaches from here on reports only what changes after it attached,\n\t\t// and its own validation reads the common git dir after this one, from the baseline this one advances\n\t\tconst watchedAtStart = new Set(this.getCommonWatchers(repoPath, commonPath));\n\t\ttry {\n\t\t\t// A forced validation reads after the one in flight, never beside it\n\t\t\tif (previous.length) {\n\t\t\t\tawait Promise.all(previous);\n\t\t\t}\n\n\t\t\t// The root and common git dirs of one validation can share paths: a main checkout's are the same, and a\n\t\t\t// linked worktree's root is an admin entry of the common one\n\t\t\tconst memo: StatMemo = new Map();\n\t\t\tconst [rootResult, commonResult, siblingResults] = await Promise.all([\n\t\t\t\troot?.dir.validate(memo, repoPath),\n\t\t\t\tcommon?.dir.validate(memo, repoPath),\n\t\t\t\tPromise.all(siblings.map(([path, state]) => state.dir.validate(memo, path))),\n\t\t\t]);\n\t\t\tthis.counts.validations++;\n\t\t\tif (rootResult?.changes.size || commonResult?.changes.size) {\n\t\t\t\tthis.counts.validationsApplied++;\n\t\t\t}\n\t\t\tthis.apply(\n\t\t\t\trepoPath,\n\t\t\t\tcommonPath,\n\t\t\t\trootResult,\n\t\t\t\tcommonResult,\n\t\t\t\tcommonTarget.dir,\n\t\t\t\tsiblings.map(([path, state], i) => [path, state, siblingResults[i]] as const),\n\t\t\t\twatchedAtStart,\n\t\t\t);\n\t\t} catch {\n\t\t\t// `validate` never rejects, so only applying can have thrown; whatever it did apply stands, but a sibling\n\t\t\t// may have been left baselined with nothing cleared, so each reports everything again at its next validation\n\t\t\tfor (const [, state] of siblings) {\n\t\t\t\tstate.dir.reset();\n\t\t\t}\n\t\t} finally {\n\t\t\t// Before the validation settles, so a read it gated finds the window open and runs no other\n\t\t\tconst settledAt = this.now();\n\t\t\tif (root != null) {\n\t\t\t\troot.settledAt = settledAt;\n\t\t\t\tif (root.runs === rootRun) {\n\t\t\t\t\troot.running = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (common != null) {\n\t\t\t\tcommon.settledAt = settledAt;\n\t\t\t\tif (common.runs === commonRun) {\n\t\t\t\t\tcommon.running = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Never stamped as validated: a sibling's own first read still validates, from the baseline taken here\n\t\t\tfor (const [i, [, state]] of siblings.entries()) {\n\t\t\t\tif (state.runs === siblingRuns[i]) {\n\t\t\t\t\tstate.running = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Applies what moved to `repoPath`, and what moved in the common git dir to its other unwatched registered worktrees\n\t * too, as the common watcher would have told each of them. While another worktree's watcher covers the common git\n\t * dir, it already cleared the shared entries, so only the worktrees' own are. A watcher covers it only if it watched\n\t * since before the stats began (`watchedAtStart`). What each sibling whose first baseline was taken with it reports\n\t * clears that sibling's own entries, as `repoPath`'s report cleared the shared ones.\n\t *\n\t * Once the common git dir (`commonDir`) holds a reading of a linked worktree's HEAD, it reports that HEAD's every\n\t * move, and a commit on its branch as a ref directory moving. Each such move clears the shared entries, as that\n\t * worktree's own report would (see {@link applyMovedHeads}), or is left to its watcher, which reports it or has it\n\t * applied as it leaves. So nothing the shared entries hold of that worktree can go stale unseen: its first report (or\n\t * its first after a reset) clears only its own entries, for up to {@link maxOwnBaselines} of them\n\t */\n\tprivate apply(\n\t\trepoPath: string,\n\t\tcommonPath: string,\n\t\troot: ValidationResult | undefined,\n\t\tcommon: ValidationResult | undefined,\n\t\tcommonDir: ProbedGitDir,\n\t\tsiblings: readonly (readonly [string, TargetState, ValidationResult])[],\n\t\twatchedAtStart: ReadonlySet<string>,\n\t): void {\n\t\tconst watchers = this.getCommonWatchers(repoPath, commonPath).filter(p => watchedAtStart.has(p));\n\t\tconst commonWatched = watchers.length !== 0;\n\n\t\tconst own = this.getVouchedBaselines(repoPath, commonPath, root, commonDir, siblings);\n\t\t// A common git dir without a baseline before this validation saw none of those HEADs move before now\n\t\tif (common?.noBaseline || own.size > maxOwnBaselines) {\n\t\t\town.clear();\n\t\t}\n\n\t\t// What `repoPath`'s report applies in full, which is what clears the shared entries\n\t\tconst changes = new Set<RepositoryChange>(own.has(repoPath) ? undefined : root?.changes);\n\t\tif (!commonWatched) {\n\t\t\tfor (const change of common?.changes ?? []) {\n\t\t\t\tchanges.add(change);\n\t\t\t}\n\t\t}\n\n\t\tif (root != null && own.has(repoPath)) {\n\t\t\tthis.cache.applyLinkedWorktreeChanges(repoPath, root.changes, 'share');\n\t\t}\n\t\tif (changes.size) {\n\t\t\t// Only the common git dir reports a `'worktreeHead'`\n\t\t\tthis.cache.onRepositoryChanged(repoPath, changes, {\n\t\t\t\tmovedWorktrees: changes.has('worktreeHead') ? common?.movedWorktrees : undefined,\n\t\t\t});\n\t\t}\n\t\tthis.applyMovedHeads(repoPath, commonPath, common, watchers, changes.has('head'));\n\n\t\t// `repoPath`'s report cleared the shared entries of the worktrees registered under its common path as of now, so\n\t\t// it covers a sibling's only while `repoPath` is still under that path and reported all the sibling did\n\t\tconst shared = this.cache.getCommonPath(repoPath) === commonPath;\n\t\tfor (const [path, state, result] of siblings) {\n\t\t\tif (!this.cache.isRegistered(path) || this.cache.getCommonPath(path) !== commonPath) {\n\t\t\t\t// Nothing was cleared for it, so its baseline goes too\n\t\t\t\tstate.dir.reset();\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (own.has(path)) {\n\t\t\t\tthis.cache.applyLinkedWorktreeChanges(path, result.changes, 'share');\n\t\t\t} else if (shared && [...result.changes].every(c => changes.has(c))) {\n\t\t\t\tthis.cache.applyRepositoryChanges(path, result.changes, 'share', { worktreeOnly: true });\n\t\t\t} else {\n\t\t\t\t// As its own first validation would have\n\t\t\t\tthis.cache.onRepositoryChanged(path, result.changes);\n\t\t\t}\n\t\t}\n\n\t\tif (!common?.changes.size) return;\n\n\t\tif (commonWatched) {\n\t\t\tthis.cache.applyRepositoryChanges(repoPath, common.changes, 'share', { worktreeOnly: true });\n\n\t\t\t// Kept for each watcher until it leaves (see `onUnwatched`), since one that leaves first drops what it held back\n\t\t\tfor (const path of watchers) {\n\t\t\t\tconst deferred = this.getDeferred(path, commonPath);\n\t\t\t\tfor (const change of common.changes) {\n\t\t\t\t\tdeferred.changes.add(change);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const path of this.cache.getWorktreePaths(commonPath)) {\n\t\t\tif (path === repoPath || watchers.includes(path)) continue;\n\n\t\t\tthis.cache.applyRepositoryChanges(path, common.changes, 'share', { worktreeOnly: true });\n\t\t}\n\t}\n\n\t/** What is left to the watcher of `path` until it leaves (see {@link onUnwatched}) */\n\tprivate getDeferred(\n\t\tpath: string,\n\t\tcommonPath: string,\n\t): { readonly commonPath: string; readonly changes: Set<RepositoryChange>; headMoved: boolean } {\n\t\tlet deferred = this.deferred.get(path);\n\t\tif (deferred?.commonPath !== commonPath) {\n\t\t\tdeferred = { commonPath: commonPath, changes: new Set(), headMoved: false };\n\t\t\tthis.deferred.set(path, deferred);\n\t\t}\n\t\treturn deferred;\n\t}\n\n\t/**\n\t * The worktrees, of `repoPath` and the `siblings`, whose report without a baseline the common git dir vouches for as\n\t * of now: each a linked worktree registered under `commonPath` whose HEAD `commonDir` holds a reading of\n\t */\n\tprivate getVouchedBaselines(\n\t\trepoPath: string,\n\t\tcommonPath: string,\n\t\troot: ValidationResult | undefined,\n\t\tcommonDir: ProbedGitDir,\n\t\tsiblings: readonly (readonly [string, TargetState, ValidationResult])[],\n\t): Set<string> {\n\t\tconst vouched = (path: string): boolean => {\n\t\t\tif (this.cache.getCommonPath(path) !== commonPath) return false;\n\n\t\t\tconst id = this.cache.getLinkedWorktreeId(path);\n\t\t\treturn id != null && commonDir.holdsWorktreeHead(id);\n\t\t};\n\n\t\tconst paths = new Set<string>();\n\t\tif (root?.noBaseline && vouched(repoPath)) {\n\t\t\tpaths.add(repoPath);\n\t\t}\n\t\tfor (const [path, , result] of siblings) {\n\t\t\tif (result.noBaseline && vouched(path)) {\n\t\t\t\tpaths.add(path);\n\t\t\t}\n\t\t}\n\t\treturn paths;\n\t}\n\n\t/**\n\t * Applies the common git dir's sighting of linked worktrees' HEADs moving as each worktree's own report would be:\n\t * the shared entries hold each one's HEAD too (where the branch list places its branch, what a checkout's reflog\n\t * says a branch was based on), which a `'worktreeHead'` clears nothing of. One whose own watcher covered the common\n\t * git dir reports it itself, or, should that watcher leave first, has it applied as it leaves. A move not attributed to a registered worktree is applied to `repoPath`, as is a report\n\t * without a baseline (whose shared entries a watcher of the common git dir cleared, if not `repoPath`'s report),\n\t * unless what `repoPath`'s report applied in full saw its own HEAD move (`appliedHead`)\n\t */\n\tprivate applyMovedHeads(\n\t\trepoPath: string,\n\t\tcommonPath: string,\n\t\tcommon: ValidationResult | undefined,\n\t\twatchers: readonly string[],\n\t\tappliedHead: boolean,\n\t): void {\n\t\tif (common == null) return;\n\n\t\tconst paths = new Set<string>();\n\t\tif (common.noBaseline || (common.changes.has('worktreeHead') && common.movedWorktrees == null)) {\n\t\t\tpaths.add(repoPath);\n\t\t} else if (common.changes.has('worktreeHead')) {\n\t\t\tconst pathsById = new Map<string, string>();\n\t\t\tfor (const path of this.cache.getWorktreePaths(commonPath)) {\n\t\t\t\tconst id = this.cache.getLinkedWorktreeId(path);\n\t\t\t\tif (id != null) {\n\t\t\t\t\tpathsById.set(id, path);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const id of common.movedWorktrees ?? []) {\n\t\t\t\tconst path = pathsById.get(id) ?? repoPath;\n\t\t\t\tif (watchers.includes(path)) {\n\t\t\t\t\tthis.getDeferred(path, commonPath).headMoved = true;\n\t\t\t\t} else {\n\t\t\t\t\tpaths.add(path);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (appliedHead) {\n\t\t\tpaths.delete(repoPath);\n\t\t}\n\n\t\tfor (const path of paths) {\n\t\t\tthis.cache.onRepositoryChanged(path, ['head', 'heads']);\n\t\t}\n\t}\n}\n\n/**\n * Runs file-system calls at most {@link maxFsCalls} at once, and at most {@link maxFsCallsPerRepo} at once for a key;\n * the calls waiting start in the order they came, skipping those whose key is busy. A call outstanding past the\n * timeout is stuck, as on a hung mount: it stops counting against {@link maxFsCalls}, so other keys' calls go on, but\n * keeps its key busy and holds one of the threads the gate is allowed until it returns\n */\nclass FileSystemGate {\n\t/** The keys with calls in flight, by how many */\n\tprivate readonly busy = new Map<string, number>();\n\tprivate readonly waiting: { readonly key: string; readonly start: () => void }[] = [];\n\tprivate active = 0;\n\tprivate stuck = 0;\n\t/** The calls made since it was created */\n\tcalls = 0;\n\n\tconstructor(\n\t\tprivate readonly timeoutMs: number,\n\t\t/** Calls in flight at most, stuck ones included */\n\t\tprivate readonly maxThreads: number,\n\t) {}\n\n\tasync run<T>(key: string, call: () => Promise<T>): Promise<T> {\n\t\tif (this.canStart(key)) {\n\t\t\tthis.acquire(key);\n\t\t} else {\n\t\t\tawait new Promise<void>(resolve => this.waiting.push({ key: key, start: resolve }));\n\t\t}\n\n\t\tthis.calls++;\n\t\tlet stuck = false;\n\t\tconst timer = setTimeout(() => {\n\t\t\tstuck = true;\n\t\t\tthis.active--;\n\t\t\tthis.stuck++;\n\t\t\tthis.drain();\n\t\t}, this.timeoutMs);\n\t\t// A call alone must not keep a (Node) process alive; in the browser timers are numbers\n\t\tif (typeof timer !== 'number') {\n\t\t\ttimer.unref();\n\t\t}\n\n\t\ttry {\n\t\t\treturn await call();\n\t\t} finally {\n\t\t\tif (stuck) {\n\t\t\t\tthis.stuck--;\n\t\t\t} else {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tthis.active--;\n\t\t\t}\n\t\t\tthis.release(key);\n\t\t}\n\t}\n\n\t/** The calls outstanding past the timeout */\n\tget stuckCalls(): number {\n\t\treturn this.stuck;\n\t}\n\n\tprivate hasSlot(): boolean {\n\t\treturn this.active < maxFsCalls && this.active + this.stuck < this.maxThreads;\n\t}\n\n\tprivate canStart(key: string): boolean {\n\t\treturn this.hasSlot() && (this.busy.get(key) ?? 0) < maxFsCallsPerRepo;\n\t}\n\n\tprivate acquire(key: string): void {\n\t\tthis.active++;\n\t\tthis.busy.set(key, (this.busy.get(key) ?? 0) + 1);\n\t}\n\n\tprivate release(key: string): void {\n\t\tconst count = (this.busy.get(key) ?? 1) - 1;\n\t\tif (count > 0) {\n\t\t\tthis.busy.set(key, count);\n\t\t} else {\n\t\t\tthis.busy.delete(key);\n\t\t}\n\t\tthis.drain();\n\t}\n\n\tprivate drain(): void {\n\t\tlet i = 0;\n\t\twhile (i < this.waiting.length && this.hasSlot()) {\n\t\t\tconst waiter = this.waiting[i];\n\t\t\tif (!this.canStart(waiter.key)) {\n\t\t\t\ti++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tthis.waiting.splice(i, 1);\n\t\t\t// Claimed before it resumes, so no call that comes meanwhile takes its slot\n\t\t\tthis.acquire(waiter.key);\n\t\t\twaiter.start();\n\t\t}\n\t}\n}\n\ninterface ProbedGitDirOptions {\n\t/** Shared by every git dir the validator reads */\n\treadonly gate: FileSystemGate;\n\treadonly stat: (path: string) => Promise<ProbeStat | undefined>;\n\treadonly readDirectory: (path: string) => Promise<readonly (readonly [string, number])[]>;\n\treadonly readFile: ((path: string) => Promise<Uint8Array | undefined>) | undefined;\n\treadonly getIgnoredWorktreeRoots: ((repoPath: string) => Promise<readonly string[]>) | undefined;\n\treadonly isRacy: (stat: ProbeStat, path: string) => boolean;\n}\n\n/** The probes of a gate's files, read only once the gate moved */\ninterface GatedTarget {\n\treadonly target: GitDirProbeTarget;\n\t/** Whether its baseline was taken */\n\tread: boolean;\n}\n\n/**\n * The readings of one git dir: a worktree's own (`root`), or the common one, whose ref directories and worktree admin\n * entries it finds by listing them. A directory is listed only after its reading was recorded, so whatever a listing\n * missed moves the directory again. A path that can't be read counts as moved as it becomes unreadable and again as it\n * becomes readable; a directory that can't be listed keeps what it held and is listed again at the next validation, so\n * what changes deeper inside it goes unseen until it can be. Without a baseline, a worktree's own git dir reports only\n * what its probes can, the common one everything.\n */\nclass ProbedGitDir {\n\t/** The probes read every time, the gates among them */\n\tprivate target: GitDirProbeTarget;\n\t/** By the path of their gate: the git dir's own, and each admin entry's */\n\tprivate readonly gated = new Map<string, GatedTarget>();\n\tprivate baselined = false;\n\t/** The directories found under the ref namespaces, which a ref created or deleted in them moves */\n\tprivate readonly refDirs = new Set<string>();\n\t/** By admin id, whether core ignores the linked worktree, which leaves only its `gitdir` probed */\n\tprivate readonly worktrees = new Map<string, { ignored: boolean }>();\n\t/** The probes that moved during the current validation, by path */\n\tprivate readonly moved = new Map<string, GitDirProbe>();\n\t/** The paths of the probes that moved in the last poll */\n\tprivate readonly movedInPoll = new Set<string>();\n\t/** The gates that moved during the current validation */\n\tprivate readonly movedGates = new Set<string>();\n\t/** The admin ids found during the current validation */\n\tprivate readonly foundWorktrees = new Set<string>();\n\t/** The admin ids removed during the current validation, by whether they were ignored */\n\tprivate readonly removedWorktrees = new Map<string, boolean>();\n\t/** The admin ids whose ignored status flipped during the current validation */\n\tprivate readonly flippedWorktrees = new Set<string>();\n\t/**\n\t * The directories the next validation lists whether they moved or not: those that couldn't be listed, and those\n\t * left at {@link maxDiscoveryPolls}\n\t */\n\tprivate readonly pendingDirs = new Set<string>();\n\t/** The admin ids left at {@link maxDiscoveryPolls}, whose `gitdir` the next validation reads whether it moved or not */\n\tprivate readonly pendingEntries = new Set<string>();\n\t/** The common git dir's own `reftable/tables.list`; only while it's there do the admin entries have their own */\n\tprivate readonly reftablePath: string | undefined;\n\t/** Whether {@link reftablePath} was there at its last reading */\n\tprivate reftable = false;\n\t/** The current validation's */\n\tprivate memo: StatMemo | undefined;\n\t/** The current validation's repository, whose git dir the cache holds */\n\tprivate repoPath: string | undefined;\n\t/** The current validation's, once a worktree needed them */\n\tprivate ignoredRoots: Promise<readonly string[]> | undefined;\n\n\tconstructor(\n\t\treadonly kind: 'root' | 'common',\n\t\treadonly basePath: string,\n\t\t/** The repository's common path as the cache resolved it */\n\t\treadonly commonPath: string,\n\t\t/**\n\t\t * The repository's common git dir, which keys its file-system calls in the gate, shared with its worktrees':\n\t\t * unlike the common path, the same for a worktree the cache never registered\n\t\t */\n\t\tprivate readonly gateKey: string,\n\t\tprivate readonly options: ProbedGitDirOptions,\n\t) {\n\t\tthis.reftablePath = kind === 'common' ? joinPaths(basePath, reftableProbePath) : undefined;\n\t\tthis.target = this.createTarget(() => this.getProbes());\n\t\tthis.addGated(gitDirGatePath, kind === 'root' ? rootGatedProbes : commonGatedProbes);\n\t}\n\n\t/**\n\t * Polls the probes and answers what moved since the last validation; everything it can report when there's no\n\t * baseline. `memo` holds the stats of the validation it's part of\n\t */\n\tasync validate(memo: StatMemo, repoPath: string): Promise<ValidationResult> {\n\t\tthis.moved.clear();\n\t\tthis.movedGates.clear();\n\t\tthis.foundWorktrees.clear();\n\t\tthis.removedWorktrees.clear();\n\t\tthis.flippedWorktrees.clear();\n\t\tthis.memo = memo;\n\t\tthis.repoPath = repoPath;\n\n\t\tlet failed = false;\n\t\ttry {\n\t\t\tawait this.poll();\n\t\t\tif (this.kind === 'common') {\n\t\t\t\tawait this.discover();\n\t\t\t}\n\t\t\tawait this.pollGated();\n\t\t} catch {\n\t\t\tfailed = true;\n\t\t} finally {\n\t\t\tthis.memo = undefined;\n\t\t\tthis.repoPath = undefined;\n\t\t\tthis.ignoredRoots = undefined;\n\t\t}\n\n\t\tif (failed || !this.baselined) {\n\t\t\tif (failed) {\n\t\t\t\tthis.reset();\n\t\t\t} else {\n\t\t\t\tthis.baselined = true;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tchanges: new Set(this.kind === 'root' ? rootReportableChanges : allWatchedRepositoryChanges),\n\t\t\t\tmovedWorktrees: undefined,\n\t\t\t\tnoBaseline: true,\n\t\t\t};\n\t\t}\n\n\t\treturn this.classify();\n\t}\n\n\t/**\n\t * Whether it holds a reading of the HEAD of the linked worktree with the admin id `id`, so it reports that HEAD's\n\t * every move from here on: a common git dir with a baseline, probing that worktree's admin entry (not ignored), whose\n\t * files it read behind it\n\t */\n\tholdsWorktreeHead(id: string): boolean {\n\t\tif (this.kind !== 'common' || !this.baselined || this.worktrees.get(id)?.ignored !== false) return false;\n\n\t\treturn this.gated.get(`worktrees/${id}`)?.read === true;\n\t}\n\n\t/** Drops every reading, so the next validation has no baseline and reports everything it can */\n\treset(): void {\n\t\tthis.target = this.createTarget(() => this.getProbes());\n\t\tthis.gated.clear();\n\t\tthis.addGated(gitDirGatePath, this.kind === 'root' ? rootGatedProbes : commonGatedProbes);\n\t\tthis.baselined = false;\n\t\tthis.refDirs.clear();\n\t\tthis.worktrees.clear();\n\t\tthis.pendingDirs.clear();\n\t\tthis.pendingEntries.clear();\n\t\tthis.reftable = false;\n\t}\n\n\tprivate createTarget(getProbes: () => Iterable<GitDirProbe>): GitDirProbeTarget {\n\t\treturn new GitDirProbeTarget(\n\t\t\tthis.basePath,\n\t\t\t{ stat: path => this.stat(path), invalidate: () => {} },\n\t\t\tgetProbes,\n\t\t\tnew Map(),\n\t\t\t(_event, probe) => {\n\t\t\t\tif (isGatePath(probe.path)) {\n\t\t\t\t\tthis.movedGates.add(probe.path);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.moved.set(probe.path, probe);\n\t\t\t\tthis.movedInPoll.add(probe.path);\n\t\t\t},\n\t\t\t{ isRacy: this.options.isRacy },\n\t\t);\n\t}\n\n\tprivate addGated(gatePath: string, probes: readonly GitDirProbe[]): void {\n\t\tthis.gated.set(gatePath, { target: this.createTarget(() => probes), read: false });\n\t}\n\n\tprivate addWorktreeGated(id: string): void {\n\t\tthis.addGated(`worktrees/${id}`, [{ path: `worktrees/${id}/HEAD` }, { path: `worktrees/${id}/locked` }]);\n\t}\n\n\tprivate async stat(path: string): Promise<ProbeStat | undefined> {\n\t\tlet stat = this.memo?.get(path);\n\t\tif (stat == null) {\n\t\t\t// Mapped before it's shared, so the root and common git dirs read the same\n\t\t\tstat = this.options.gate\n\t\t\t\t.run(this.gateKey, () => this.options.stat(path))\n\t\t\t\t.catch((ex: unknown) => {\n\t\t\t\t\t// A path under one that is now a file (a ref directory replaced by a ref of its name) isn't there\n\t\t\t\t\tif (isNotFound(ex) || isNotADirectory(ex)) return undefined;\n\n\t\t\t\t\t// Read as a reading of its own rather than skipped (as the probe target skips a stat that throws), so\n\t\t\t\t\t// the path moves as it becomes unreadable and as it becomes readable again\n\t\t\t\t\treturn unreadable;\n\t\t\t\t});\n\t\t\tthis.memo?.set(path, stat);\n\t\t}\n\n\t\tconst result = await stat;\n\t\tif (path === this.reftablePath && result !== unreadable) {\n\t\t\tthis.reftable = result != null;\n\t\t}\n\t\treturn result;\n\t}\n\n\tprivate poll(): Promise<void> {\n\t\tthis.movedInPoll.clear();\n\t\treturn this.target.poll();\n\t}\n\n\t/** Polls the files of each gate that moved during this validation, and of each never read */\n\tprivate async pollGated(): Promise<void> {\n\t\tconst due = [...this.gated].filter(([gate, gated]) => !gated.read || this.movedGates.has(gate));\n\t\tawait Promise.all(\n\t\t\tdue.map(async ([, gated]) => {\n\t\t\t\tawait gated.target.poll();\n\t\t\t\tgated.read = true;\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate getProbes(): GitDirProbe[] {\n\t\tif (this.kind === 'root') return [...rootAlwaysProbes];\n\n\t\tconst probes = [...commonAlwaysProbes];\n\t\tfor (const path of this.refDirs) {\n\t\t\tprobes.push({ path: path });\n\t\t}\n\t\tfor (const [id, { ignored }] of this.worktrees) {\n\t\t\tprobes.push({ path: `worktrees/${id}/gitdir` });\n\t\t\tif (ignored) continue;\n\n\t\t\tprobes.push({ path: `worktrees/${id}` });\n\t\t\tif (this.reftable) {\n\t\t\t\tprobes.push({ path: `worktrees/${id}/${reftableProbePath}` });\n\t\t\t}\n\t\t}\n\t\treturn probes;\n\t}\n\n\t/** The listed directories that moved in the last poll */\n\tprivate getMovedDirs(): string[] {\n\t\treturn [...this.movedInPoll].filter(p => p === 'worktrees' || refNamespaces.includes(p) || this.refDirs.has(p));\n\t}\n\n\t/** The known admin ids whose `gitdir` moved in the last poll */\n\tprivate getMovedGitdirs(): string[] {\n\t\tconst ids: string[] = [];\n\t\tfor (const path of this.movedInPoll) {\n\t\t\tconst entry = parseWorktreeAdminPath(path);\n\t\t\tif (entry?.file === 'gitdir' && this.worktrees.has(entry.id)) {\n\t\t\t\tids.push(entry.id);\n\t\t\t}\n\t\t}\n\t\treturn ids;\n\t}\n\n\t/**\n\t * Lists the directories that moved in the last poll (every one, the first time), and polls again while that finds\n\t * new ones, so they have readings before the caches are read again: the move of the directory they're in already\n\t * reported whatever they hold. Reads whether each admin entry new to it, or whose `gitdir` moved, is ignored, once\n\t * that `gitdir` has a reading. Also lists what an earlier validation left: the directories it couldn't list, and\n\t * what was still to list or read when it reached {@link maxDiscoveryPolls}.\n\t */\n\tprivate async discover(): Promise<void> {\n\t\tlet dirs = this.baselined\n\t\t\t? [...new Set([...this.pendingDirs, ...this.getMovedDirs()])]\n\t\t\t: [...refNamespaces, 'worktrees'];\n\t\tlet entries = this.baselined ? [...new Set([...this.pendingEntries, ...this.getMovedGitdirs()])] : [];\n\t\tthis.pendingEntries.clear();\n\n\t\tfor (let polls = 0; ; polls++) {\n\t\t\tconst found = dirs.length ? await this.list(dirs) : { dirs: [], worktrees: [] };\n\t\t\tconst unignored = entries.length ? await this.readIgnored(entries) : false;\n\t\t\tif (!found.dirs.length && !found.worktrees.length && !unignored) return;\n\n\t\t\t// Even at the cap, so what was just found has a reading before the caches are read again\n\t\t\tawait this.poll();\n\t\t\tdirs = [...found.dirs, ...this.getMovedDirs()];\n\t\t\tentries = [...new Set([...found.worktrees, ...this.getMovedGitdirs()])];\n\n\t\t\tif (polls === maxDiscoveryPolls) {\n\t\t\t\tfor (const dir of dirs) {\n\t\t\t\t\tthis.pendingDirs.add(dir);\n\t\t\t\t}\n\t\t\t\tfor (const id of entries) {\n\t\t\t\t\tthis.pendingEntries.add(id);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Lists `dirs`, dropping the directories (or admin entries) no longer in them, and answers what's new. One that\n\t * can't be listed keeps what it held, and is left for the next validation to list\n\t */\n\tprivate async list(dirs: readonly string[]): Promise<{ dirs: string[]; worktrees: string[] }> {\n\t\tconst found: { dirs: string[]; worktrees: string[] } = { dirs: [], worktrees: [] };\n\n\t\tawait Promise.all(\n\t\t\tdirs.map(async dir => {\n\t\t\t\tconst names = await this.readDirectories(dir);\n\t\t\t\tif (names == null) {\n\t\t\t\t\tthis.pendingDirs.add(dir);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.pendingDirs.delete(dir);\n\t\t\t\tif (dir === 'worktrees') {\n\t\t\t\t\tfor (const [id, { ignored }] of this.worktrees) {\n\t\t\t\t\t\tif (!names.includes(id)) {\n\t\t\t\t\t\t\tthis.removedWorktrees.set(id, ignored);\n\t\t\t\t\t\t\tthis.worktrees.delete(id);\n\t\t\t\t\t\t\tthis.gated.delete(`worktrees/${id}`);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (const id of names) {\n\t\t\t\t\t\tif (!this.worktrees.has(id)) {\n\t\t\t\t\t\t\t// Probed as not ignored until its `gitdir` is read\n\t\t\t\t\t\t\tthis.worktrees.set(id, { ignored: false });\n\t\t\t\t\t\t\tthis.addWorktreeGated(id);\n\t\t\t\t\t\t\tthis.foundWorktrees.add(id);\n\t\t\t\t\t\t\tfound.worktrees.push(id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst children = new Set(names.map(name => `${dir}/${name}`));\n\t\t\t\tfor (const path of this.refDirs) {\n\t\t\t\t\tif (path.substring(0, path.lastIndexOf('/')) !== dir || children.has(path)) continue;\n\n\t\t\t\t\tfor (const p of this.refDirs) {\n\t\t\t\t\t\tif (p === path || p.startsWith(`${path}/`)) {\n\t\t\t\t\t\t\tthis.refDirs.delete(p);\n\t\t\t\t\t\t\tthis.pendingDirs.delete(p);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const path of children) {\n\t\t\t\t\tif (!this.refDirs.has(path)) {\n\t\t\t\t\t\tthis.refDirs.add(path);\n\t\t\t\t\t\tfound.dirs.push(path);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\treturn found;\n\t}\n\n\t/**\n\t * Reads whether core ignores each of the admin entries `ids`, from their `gitdir`; answers whether one known as\n\t * ignored no longer is, whose gate the next poll must take a reading of. A read that fails ignores nothing\n\t */\n\tprivate async readIgnored(ids: readonly string[]): Promise<boolean> {\n\t\tconst { readFile, getIgnoredWorktreeRoots } = this.options;\n\t\tif (readFile == null || getIgnoredWorktreeRoots == null || this.repoPath == null) return false;\n\n\t\tconst repoPath = this.repoPath;\n\t\tconst roots = await (this.ignoredRoots ??= getIgnoredWorktreeRoots(repoPath).catch(() => []));\n\n\t\tlet unignored = false;\n\t\tawait Promise.all(\n\t\t\tids.map(async id => {\n\t\t\t\tlet ignored = false;\n\t\t\t\tif (roots.length) {\n\t\t\t\t\tconst adminDir = joinPaths(this.basePath, 'worktrees', id);\n\t\t\t\t\tlet gitdir: Uint8Array | undefined;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tgitdir = await this.options.gate.run(this.gateKey, () =>\n\t\t\t\t\t\t\treadFile(joinPaths(adminDir, 'gitdir')),\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch {}\n\t\t\t\t\tignored = isIgnoredWorktreeEntry(adminDir, gitdir, roots) === true;\n\t\t\t\t}\n\n\t\t\t\tconst entry = this.worktrees.get(id);\n\t\t\t\tif (entry == null || entry.ignored === ignored) return;\n\n\t\t\t\tentry.ignored = ignored;\n\t\t\t\t// A new entry was reported as the move of the `worktrees` directory it appeared in\n\t\t\t\tif (!this.foundWorktrees.has(id)) {\n\t\t\t\t\tthis.flippedWorktrees.add(id);\n\t\t\t\t}\n\t\t\t\tif (ignored) {\n\t\t\t\t\tthis.gated.delete(`worktrees/${id}`);\n\t\t\t\t} else {\n\t\t\t\t\tthis.addWorktreeGated(id);\n\t\t\t\t\tunignored = true;\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\treturn unignored;\n\t}\n\n\t/** The names of the directories in `dir`; none when it isn't there, and `undefined` when it couldn't be listed */\n\tprivate async readDirectories(dir: string): Promise<string[] | undefined> {\n\t\ttry {\n\t\t\tconst entries = await this.options.gate.run(this.gateKey, () =>\n\t\t\t\tthis.options.readDirectory(joinPaths(this.basePath, dir)),\n\t\t\t);\n\t\t\treturn entries.filter(([, type]) => (type & FileType.Directory) !== 0).map(([name]) => name);\n\t\t} catch (ex) {\n\t\t\tif (isNotFound(ex) || isNotADirectory(ex)) return [];\n\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * The admin ids, not ignored, that the listings of this validation added or removed; none when all were ignored, and\n\t * `undefined` when the listings changed nothing, so what moved the `worktrees` directory is unknown\n\t */\n\tprivate getAddedOrRemovedWorktrees(): string[] | undefined {\n\t\tif (!this.foundWorktrees.size && !this.removedWorktrees.size) return undefined;\n\n\t\tconst ids: string[] = [];\n\t\tfor (const id of this.foundWorktrees) {\n\t\t\tconst entry = this.worktrees.get(id);\n\t\t\tif (entry != null && !entry.ignored) {\n\t\t\t\tids.push(id);\n\t\t\t}\n\t\t}\n\t\tfor (const [id, ignored] of this.removedWorktrees) {\n\t\t\t// One found and gone again within the validation was never reported\n\t\t\tif (!ignored && !this.foundWorktrees.has(id)) {\n\t\t\t\tids.push(id);\n\t\t\t}\n\t\t}\n\t\treturn ids;\n\t}\n\n\tprivate classify(): ValidationResult {\n\t\tconst changes = new Set<RepositoryChange>();\n\t\tconst movedWorktrees = new Set<string>();\n\t\tlet anyWorktreeMoved = false;\n\n\t\tconst add = (...kinds: RepositoryChange[]): void => {\n\t\t\tfor (const kind of kinds) {\n\t\t\t\tchanges.add(kind);\n\t\t\t}\n\t\t};\n\n\t\tfor (const probe of this.moved.values()) {\n\t\t\tif (this.kind === 'common') {\n\t\t\t\t// Nothing in an ignored worktree's admin entry is cached, nor its going\n\t\t\t\tconst entry = parseWorktreeAdminPath(probe.path);\n\t\t\t\tif (entry != null && (this.worktrees.get(entry.id)?.ignored ?? this.removedWorktrees.get(entry.id))) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const path of probe.emitAs ?? [probe.path]) {\n\t\t\t\tif (path === reftableProbePath) {\n\t\t\t\t\tif (this.kind === 'root') {\n\t\t\t\t\t\tadd('head', 'heads');\n\t\t\t\t\t} else {\n\t\t\t\t\t\tadd('heads', 'remotes', 'tags', 'stash');\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (this.kind === 'common') {\n\t\t\t\t\tif (path === 'FETCH_HEAD') {\n\t\t\t\t\t\tadd('lastFetched');\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// An admin entry added or removed, as its HEAD appearing or going would report to a watcher\n\t\t\t\t\tif (path === 'worktrees') {\n\t\t\t\t\t\tconst ids = this.getAddedOrRemovedWorktrees();\n\t\t\t\t\t\tif (ids == null) {\n\t\t\t\t\t\t\tadd('worktrees', 'worktreeHead');\n\t\t\t\t\t\t\tanyWorktreeMoved = true;\n\t\t\t\t\t\t} else if (ids.length) {\n\t\t\t\t\t\t\tadd('worktrees', 'worktreeHead');\n\t\t\t\t\t\t\tfor (const id of ids) {\n\t\t\t\t\t\t\t\tmovedWorktrees.add(id);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst match = worktreeHeadRegex.exec(path);\n\t\t\t\t\tif (match != null) {\n\t\t\t\t\t\tadd('worktrees', 'worktreeHead');\n\t\t\t\t\t\tmovedWorktrees.add(match[1]);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst kinds = classifyGitDirChange(path);\n\t\t\t\tif (kinds != null) {\n\t\t\t\t\tadd(...kinds);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// A worktree ignored or no longer: it left the worktree list or joined it, as an entry removed or added would\n\t\tfor (const id of this.flippedWorktrees) {\n\t\t\tadd('worktrees', 'worktreeHead');\n\t\t\tmovedWorktrees.add(id);\n\t\t}\n\n\t\treturn { changes: changes, movedWorktrees: anyWorktreeMoved ? undefined : movedWorktrees, noBaseline: false };\n\t}\n}\n\n/** A gate's own move reports nothing: the git dir itself, or a linked worktree's admin entry */\nfunction isGatePath(path: string): boolean {\n\tif (path === gitDirGatePath) return true;\n\n\tconst entry = parseWorktreeAdminPath(path);\n\treturn entry != null && entry.file == null;\n}\n\n/** A component of the path is a file: Node's error, or the one VS Code's file system raises */\nfunction isNotADirectory(ex: unknown): boolean {\n\tconst code = (ex as { code?: unknown } | undefined)?.code;\n\treturn code === 'ENOTDIR' || code === 'FileNotADirectory';\n}\n"],"mappings":";;;;;;;;;;;AAk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S,gBAAgB,mBAAmB,KAAA,IAAY;GAAgB,YAAY;EAAM;CAC7G;AACD;;AAGA,SAAS,WAAW,MAAuB;CAC1C,IAAI,SAAS,gBAAgB,OAAO;CAEpC,MAAM,QAAQ,uBAAuB,IAAI;CACzC,OAAO,SAAS,QAAQ,MAAM,QAAQ;AACvC;;AAGA,SAAS,gBAAgB,IAAsB;CAC9C,MAAM,OAAQ,IAAuC;CACrD,OAAO,SAAS,aAAa,SAAS;AACvC"}
1
+ {"version":3,"file":"unwatchedCacheValidator.js","names":[],"sources":["../../../../git/src/watching/unwatchedCacheValidator.ts"],"sourcesContent":["import { raceWithTimeout } from '@gitlens/utils/cancellation.js';\nimport { joinPaths } from '@gitlens/utils/path.js';\nimport type { ResourceUsage } from '@gitlens/utils/resourceUsage.js';\nimport type { Cache } from '../cache.js';\nimport { FileType } from '../context.js';\nimport type { RepositoryChange } from '../models/repository.js';\nimport { isIgnoredWorktreeEntry, parseWorktreeAdminPath } from '../utils/repository.utils.js';\nimport { allWatchedRepositoryChanges, classifyGitDirChange } from './classifyChange.js';\nimport type { GitDirProbe } from './gitDirPoller.js';\nimport { GitDirProbeTarget } from './gitDirPoller.js';\nimport { gitDirCommonProbes, gitDirRootProbes } from './watcherPatterns.js';\nimport { isNotFound } from './watchGroup.js';\nimport { defaultRepoDelay } from './watchSession.js';\n\ntype ProbeStat = { readonly mtime: number; readonly size: number };\n/** The stats of one validation, by absolute path, shared by every git dir it reads */\ntype StatMemo = Map<string, Promise<ProbeStat | undefined>>;\n/** The reading of a path whose stat failed; never a whole second, so never racy */\nconst unreadable: ProbeStat = { mtime: -1, size: -1 };\n/** What a batched stat reads of one path (see {@link UnwatchedCacheValidatorOptions.statMany}) */\nexport type BatchedStat = ProbeStat | 'missing' | 'unreadable';\n\nexport interface UnwatchedCacheValidatorOptions {\n\treadonly cache: Cache;\n\t/**\n\t * A path's modification time (ms since the epoch) and size; `undefined` when it doesn't exist. With\n\t * {@link statMany}, only for the paths of a batch that failed and for the stats made while batching backs off\n\t * after one, so both must read a file alike\n\t */\n\treadonly stat: (path: string) => Promise<ProbeStat | undefined>;\n\t/**\n\t * Stats many paths as one file-system call, answering one reading per path in order: `'missing'` for one that isn't\n\t * there (or under a path that is a file), `'unreadable'` for one whose stat failed otherwise. A rejection fails the\n\t * whole batch, whose paths are then read by {@link stat} one at a time, as are all stats for 30 seconds after.\n\t * When given, the stats a validation needs at once for a repository are made as one call (of at most 128 paths)\n\t * rather than one call each; without it, each is a call of its own\n\t */\n\treadonly statMany?: (paths: readonly string[]) => Promise<readonly BatchedStat[]>;\n\t/** A directory's entries with their `FileType`s; a rejection whose `code` is `ENOENT` or `FileNotFound` means it isn't there */\n\treadonly readDirectory: (path: string) => Promise<readonly (readonly [string, number])[]>;\n\t/** A file's bytes; `undefined` when it doesn't exist. Without it, no worktree is ignored */\n\treadonly readFile?: (path: string) => Promise<Uint8Array | undefined>;\n\t/**\n\t * The absolute, normalized folders whose worktrees core ignores (see `GitProvider.getIgnoredWorktreeRoots`), asked\n\t * with a `repoPath` whose git dir the cache holds; a worktree in one is left out of the worktree list, so what moves\n\t * in its admin entry changes nothing cached. A rejection means none is ignored\n\t */\n\treadonly getIgnoredWorktreeRoots?: (repoPath: string) => Promise<readonly string[]>;\n\t/**\n\t * Caches `repoPath`'s git dir without running git, for a repository nothing resolved one for yet (as when only its\n\t * branches, remotes or tags were read); whether one is cached. Without it, or when it answers `false`, such a\n\t * repository isn't validated: a layout git's files alone can't answer for (a bare repository, a submodule, a\n\t * `--separate-git-dir` checkout, a `core.worktree`) stays unvalidated until a read resolves its git dir. A rejection\n\t * is a failure to look, retried soon; `false` is a repository its files can't answer for, tried again rarely\n\t */\n\treadonly resolveGitDir?: (repoPath: string) => Promise<boolean>;\n\t/**\n\t * Whether a `.git` watcher covers `repoPath` and is live (see `RepositoryWatchService.isRepoWatched`): one that is\n\t * suspended holds what it hears until it resumes, so a repository is unwatched meanwhile, without being announced\n\t */\n\treadonly isWatched: (repoPath: string) => boolean;\n\t/** Milliseconds since the epoch, the clock `stat`'s `mtime` is on. Default: `Date.now` */\n\treadonly now?: () => number;\n\t/**\n\t * How long a read waits for a validation before it's served from the cache as is, and how long a hung file-system\n\t * call holds back other repositories' validations. Default: 1000\n\t */\n\treadonly timeoutMs?: number;\n\t/**\n\t * How many threads the validator's file-system calls may hold at once, counting those hung past {@link timeoutMs}:\n\t * Node's file-system threads (libuv's pool), or, for a {@link statMany} batch, whatever thread the host runs it on;\n\t * at most two run at once. Default: 2, which leaves a host two of the pool's default four\n\t */\n\treadonly maxFsThreads?: number;\n}\n\n/**\n * A target read within this long of its last validation is served as is: a watched repository's read is as stale, as\n * its watch session debounces what its watcher reports by as much\n */\nconst validationWindowMs = defaultRepoDelay;\n/**\n * How long a repository whose files can't show its git dir (a bare repository, a submodule) is left before they are\n * looked at again. Any read that resolves its git dir with git makes the lookup unneeded\n */\nconst unresolvableRetryMs = 30_000;\n/** Targets kept per kind; one dropped just takes a new baseline */\nconst maxTargets = 512;\n/**\n * Other worktrees' first baselines one validation takes with its own. Their stats run one call at a time per repository\n * inside the read that triggered them, so the batch is kept small enough that a slow file system doesn't push that read\n * past its timeout; the worktrees left out batch the rest at their own first validation. Never more than fit under\n * {@link maxTargets}, as a target dropped for them would clear the shared entries again\n */\nconst maxSiblingBaselines = 64;\n/**\n * Linked worktrees' first baselines one validation clears only their own entries for, when the common git dir vouches\n * for each one's HEAD; past it, they clear the shared entries too, once. Clearing the shared entries costs a ref listing,\n * a default branch read and the reader's current branch, and that listing seeds every worktree's current branch again;\n * clearing a worktree's own entries costs it a read of its own current branch. So past a few worktrees, one clear of the\n * shared entries is the cheaper\n */\nconst maxOwnBaselines = 3;\n/** Polls one validation runs to take the baselines of the directories it finds; the next validation resumes from there */\nconst maxDiscoveryPolls = 16;\n/**\n * How long a reading stays racy on a file system whose timestamps tick by whole seconds (or two, as FAT's): a write in\n * the same second as the stat leaves the same mtime. Counted both from the mtime and from when the validator first saw\n * the reading, as a server whose clock runs ahead of ours stamps writes with a second that ends, on our clock, no later\n * than this long after we first saw it\n */\nconst racyMtimeWindowMs = 2000;\n/** Racy candidates whose first sighting is remembered; the oldest is dropped past it, which only extends its raciness */\nconst maxRacyReadings = maxTargets * 8;\n/** How long a read waits for a validation before it's served from the cache as is */\nconst defaultValidationTimeoutMs = 1000;\n/** The longest delay `setTimeout` keeps; a longer one (`Infinity` included) fires at once */\nconst maxValidationTimeoutMs = 2 ** 31 - 1;\n/**\n * A stat, a batch of them or a listing holds a thread (one of Node's file-system threads, libuv's pool of 4 by default,\n * or the one a batch runs on) until it returns, which on a hung mount is never, as it can't be cancelled. A repository\n * makes one call at a time and the validator two, holding no more threads than it's allowed counting those outstanding\n * past the timeout\n */\nconst maxFsCallsPerRepo = 1;\nconst maxFsCalls = 2;\nconst defaultMaxFsThreads = 2;\n/** Paths one batch of stats holds at most; more asked together are split into batches of this many */\nconst maxBatchPaths = 128;\n/**\n * How long after a batch of stats failed each stat is a call of its own, before batching is tried again: what failed it\n * (a worker that can't start or keeps dying) likely fails the next one too\n */\nconst failedBatchBackoffMs = 30_000;\n\nconst refNamespaces: readonly string[] = ['refs/heads', 'refs/remotes', 'refs/tags'];\nconst reftableProbePath = 'reftable/tables.list';\nconst worktreeHeadRegex = /^worktrees\\/([^/]+)\\/(?:HEAD|reftable\\/tables\\.list)$/;\n\n/**\n * The git dir itself, as the gate of the files in it that git writes by lockfile and rename, or creates and deletes:\n * either moves the directory's mtime, so its reading stands in for theirs, which are read only once it moved. Each\n * gate's files have a probe target of their own, whose readings outlast the validations that skip it; were they left\n * out of a shared target instead, their next reading would be a new baseline, losing what changed meanwhile. What git\n * writes in place (`FETCH_HEAD`, an admin entry's `gitdir`, the rebase and sequencer state `--edit-todo` rewrites) is\n * read every time. This saves stats only while the gate holds still: an index write moves the git dir too, so an\n * active checkout reads as much as ever, and an idle one, as unwatched repositories mostly are, reads just the gate.\n */\nconst gitDirGatePath = '';\nconst rootGatedPaths: ReadonlySet<string> = new Set([\n\t'HEAD',\n\t'ORIG_HEAD',\n\t'MERGE_HEAD',\n\t'CHERRY_PICK_HEAD',\n\t'REVERT_HEAD',\n\t'REBASE_HEAD',\n]);\nconst commonGatedPaths: ReadonlySet<string> = new Set(['packed-refs', 'config', 'shallow']);\n\n// The index is what working-tree status reads, which these caches aren't; `info/exclude` clears only the gitignore filter\nconst rootProbes: readonly GitDirProbe[] = gitDirRootProbes.filter(p => p.path !== 'index');\nconst rootAlwaysProbes: readonly GitDirProbe[] = [\n\t{ path: gitDirGatePath },\n\t...rootProbes.filter(p => !rootGatedPaths.has(p.path)),\n\t{ path: reftableProbePath },\n];\nconst rootGatedProbes: readonly GitDirProbe[] = rootProbes.filter(p => rootGatedPaths.has(p.path));\n/**\n * What a worktree's own git dir can report, which is all its validation without a baseline reports: the shared kinds\n * are the common git dir's to report, from a baseline of its own, or by another worktree's watcher that covers it\n */\nconst rootReportableChanges: readonly RepositoryChange[] = [\n\t...new Set(\n\t\t[...rootAlwaysProbes, ...rootGatedProbes].flatMap((p): RepositoryChange[] => {\n\t\t\tif (p.path === gitDirGatePath) return [];\n\t\t\t// As `classify` reports a worktree's own reftable, which moves with its HEAD\n\t\t\tif (p.path === reftableProbePath) return ['head', 'heads'];\n\n\t\t\treturn (p.emitAs ?? [p.path]).flatMap(path => classifyGitDirChange(path) ?? []);\n\t\t}),\n\t),\n];\nconst commonProbes: readonly GitDirProbe[] = [\n\t...gitDirCommonProbes.filter(p => p.path !== 'info/exclude'),\n\t{ path: reftableProbePath },\n\t// Dropping a stash entry other than the newest rewrites only the stash's reflog, leaving `refs/stash` as it was\n\t{ path: 'logs/refs/stash', emitAs: ['refs/stash'] },\n\t// A replacement (`git replace`) changes ancestry, and the cached ref list holds the replace refs\n\t{ path: 'refs/replace' },\n];\nconst commonAlwaysProbes: readonly GitDirProbe[] = [\n\t{ path: gitDirGatePath },\n\t...commonProbes.filter(p => !commonGatedPaths.has(p.path)),\n];\nconst commonGatedProbes: readonly GitDirProbe[] = commonProbes.filter(p => commonGatedPaths.has(p.path));\n\ninterface ValidationResult {\n\treadonly changes: ReadonlySet<RepositoryChange>;\n\t/** With a `'worktreeHead'` among `changes`, the admin ids of the linked worktrees whose HEAD moved; `undefined` when any may have */\n\treadonly movedWorktrees: ReadonlySet<string> | undefined;\n\t/**\n\t * Read without a baseline (a first validation, or one after a failure or a reset dropped it), so `changes` is all its\n\t * git dir can report rather than what moved\n\t */\n\treadonly noBaseline: boolean;\n}\n\n/** Something reads wait for, at most until their timeout */\ninterface Waitable {\n\t/** In flight; settles once what it found was applied */\n\trunning?: Promise<void>;\n\t/** What outlasted a read's wait; while it's still {@link running}, reads don't wait for it */\n\tslow?: Promise<void>;\n\t/** What it started that reads wait for through it, which a wait that outlasts it marks slow too */\n\treadonly started?: (readonly [Waitable, Promise<void>])[];\n\tsettledAt?: number;\n}\n\ninterface TargetState extends Waitable {\n\treadonly dir: ProbedGitDir;\n\truns: number;\n}\n\n/** A resolution of a git dir nothing resolved, then the validation that follows it */\ninterface ResolutionState extends Waitable {\n\treadonly started: (readonly [Waitable, Promise<void>])[];\n\t/** How long after it settled the resolution is tried again: briefly for a failure, longer for a definite \"no\" */\n\tretryAfterMs: number;\n}\n\n/**\n * Keeps the caches that never expire fresh for repositories no `.git` watcher covers: before such a read, stats the\n * files a watcher would have reported (see {@link UnwatchedCacheValidatorOptions.stat}) and applies what moved to the\n * cache as a watcher event would have. Both a worktree's own git dir and the common one are validated while that\n * worktree is unwatched; while another worktree's watcher covers the common one, what moved there clears only the\n * unwatched worktrees' own entries, but for a linked worktree's HEAD moving, which is applied as that worktree's own\n * report would be (see {@link apply}). A repository whose git dir nothing resolved yet is validated once\n * {@link UnwatchedCacheValidatorOptions.resolveGitDir} resolves one; a repository whose files can't show it is looked at\n * again rarely, and one whose resolution failed within the validation window. A read waits at most\n * {@link UnwatchedCacheValidatorOptions.timeoutMs} for a validation (and a resolution before it); one that outlasts it\n * is left to finish on its own, and the reads meanwhile are served as is.\n *\n * Each file-system call goes through a gate, one at a time per repository, so what a validation costs is mostly how\n * many calls it makes, each a round trip to a file-system thread. With\n * {@link UnwatchedCacheValidatorOptions.statMany}, the stats a repository's git dirs ask for together (a poll's, and the\n * root and common git dirs' first polls of one validation) are one call, or one per {@link maxBatchPaths} paths;\n * listings and file reads stay a call each.\n */\nexport class UnwatchedCacheValidator {\n\tprivate readonly cache: Cache;\n\tprivate readonly isWatched: (repoPath: string) => boolean;\n\tprivate readonly now: () => number;\n\tprivate readonly timeoutMs: number;\n\tprivate readonly resolveGitDir: ((repoPath: string) => Promise<boolean>) | undefined;\n\tprivate readonly gate: FileSystemGate;\n\t/** Since it was created; what {@link getResourceUsage} reports */\n\tprivate readonly counts = { validations: 0, validationsApplied: 0, waitsTimedOut: 0, gitDirLookups: 0 };\n\tprivate readonly dirOptions: ProbedGitDirOptions;\n\t/** Keyed by repo path */\n\tprivate readonly roots = new Map<string, TargetState>();\n\t/** Keyed by common path */\n\tprivate readonly commons = new Map<string, TargetState>();\n\t/** Keyed by absolute path; the readings that may be racy, with when each was first read */\n\tprivate readonly racyReadings = new Map<string, { mtime: number; size: number; firstSeen: number }>();\n\t/**\n\t * Keyed by repo path; one that found nothing is kept, so the reads meanwhile don't retry it: for the window after a\n\t * failure, for {@link unresolvableRetryMs} after a git dir the files can't show\n\t */\n\tprivate readonly resolutions = new Map<string, ResolutionState>();\n\t/** The validation {@link onWatched} ran as a watcher attached, by repo path, which reads wait for while it runs */\n\tprivate readonly handoffs = new Map<string, Promise<void>>();\n\t/**\n\t * By the repo path of a watched worktree, what moved in its common git dir that its watcher was left to clear, and\n\t * whether its own HEAD's move, which the common git dir saw, was left to it to report (see {@link applyMovedHeads})\n\t */\n\tprivate readonly deferred = new Map<\n\t\tstring,\n\t\t{ readonly commonPath: string; readonly changes: Set<RepositoryChange>; headMoved: boolean }\n\t>();\n\n\tconstructor(options: UnwatchedCacheValidatorOptions) {\n\t\tthis.cache = options.cache;\n\t\tthis.isWatched = options.isWatched;\n\t\tthis.now = options.now ?? ((): number => Date.now());\n\t\tthis.timeoutMs = Math.min(options.timeoutMs ?? defaultValidationTimeoutMs, maxValidationTimeoutMs);\n\t\tthis.resolveGitDir = options.resolveGitDir;\n\t\t// A `NaN` would fail every slot check, so nothing would ever be validated\n\t\tconst maxFsThreads = Math.floor(options.maxFsThreads ?? defaultMaxFsThreads);\n\t\tthis.gate = new FileSystemGate(\n\t\t\tthis.timeoutMs,\n\t\t\tNumber.isNaN(maxFsThreads) ? defaultMaxFsThreads : Math.max(1, maxFsThreads),\n\t\t);\n\t\tconst stat = options.stat;\n\t\tconst statMany = options.statMany;\n\t\tthis.dirOptions = {\n\t\t\tgate: this.gate,\n\t\t\tstat: stat,\n\t\t\tbatcher: statMany != null ? new StatBatcher(this.gate, statMany, stat, this.now) : undefined,\n\t\t\treadDirectory: options.readDirectory,\n\t\t\treadFile: options.readFile,\n\t\t\tgetIgnoredWorktreeRoots: options.getIgnoredWorktreeRoots,\n\t\t\tisRacy: (stat, path) => this.isRacy(stat, path),\n\t\t};\n\t}\n\n\t/**\n\t * Whether `stat` of `path` may still show the same file a write in its own second would leave. Only a whole-second\n\t * mtime can, and only until its second ended: by the mtime's own clock, and by ours since the reading was first\n\t * seen, whichever comes first\n\t */\n\tprivate isRacy(stat: ProbeStat, path: string): boolean {\n\t\tconst now = this.now();\n\t\tif (stat.mtime % 1000 !== 0 || now - stat.mtime >= racyMtimeWindowMs) {\n\t\t\tthis.racyReadings.delete(path);\n\t\t\treturn false;\n\t\t}\n\n\t\tlet reading = this.racyReadings.get(path);\n\t\tif (reading == null || reading.mtime !== stat.mtime || reading.size !== stat.size) {\n\t\t\treading = { mtime: stat.mtime, size: stat.size, firstSeen: now };\n\t\t\tthis.racyReadings.delete(path);\n\t\t\tthis.racyReadings.set(path, reading);\n\t\t\tif (this.racyReadings.size > maxRacyReadings) {\n\t\t\t\tconst oldest = this.racyReadings.keys().next();\n\t\t\t\tif (!oldest.done) {\n\t\t\t\t\tthis.racyReadings.delete(oldest.value);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Kept newest, so the cap drops the reading read longest ago, not one still read\n\t\t\tthis.racyReadings.delete(path);\n\t\t\tthis.racyReadings.set(path, reading);\n\t\t\t// A clock set back since counts from now, or the reading would stay racy until it caught up\n\t\t\tif (now < reading.firstSeen) {\n\t\t\t\treading.firstSeen = now;\n\t\t\t}\n\t\t}\n\n\t\treturn now - reading.firstSeen < racyMtimeWindowMs;\n\t}\n\n\t/**\n\t * Validates what `repoPath`'s reads would be served from, unless a watcher covers it or it was validated within\n\t * the last 250ms. `undefined` when there's nothing to wait for; otherwise settles once what moved was applied to\n\t * the cache, or after {@link UnwatchedCacheValidatorOptions.timeoutMs} with the cache as is, whichever is first.\n\t * Never rejects. A path that can't be read counts as moved as it becomes unreadable and again as it becomes\n\t * readable; a directory that can't be listed is listed again at the next validation, and what changes deeper inside\n\t * it goes unseen until it can be.\n\t */\n\tvalidate(repoPath: string): Promise<void> | undefined {\n\t\treturn this.handoffs.get(repoPath) ?? this.run(repoPath, false);\n\t}\n\n\t/**\n\t * A watcher attached to `repoPath`, so it reports only what changes from now on: validates now what changed since\n\t * the last validation, whatever the window, and has `repoPath`'s reads wait for it.\n\t */\n\tonWatched(repoPath: string): void {\n\t\tconst validation = this.run(repoPath, true);\n\t\tif (validation == null) return;\n\n\t\tconst handoff: Promise<void> = validation.finally(() => {\n\t\t\tif (this.handoffs.get(repoPath) === handoff) {\n\t\t\t\tthis.handoffs.delete(repoPath);\n\t\t\t}\n\t\t});\n\t\tthis.handoffs.set(repoPath, handoff);\n\t}\n\n\t/**\n\t * A watcher left `repoPath`, dropping what it held back unreported. What moved in its common git dir that an\n\t * unwatched sibling's validation left to it is applied now, since that validation took the shared baseline past it,\n\t * and so is its own HEAD's move that the common git dir saw, as its watcher would have reported it; whatever else it\n\t * dropped is still ahead of its own baselines.\n\t */\n\tonUnwatched(repoPath: string): void {\n\t\tconst deferred = this.deferred.get(repoPath);\n\t\tif (deferred == null) return;\n\n\t\tthis.deferred.delete(repoPath);\n\t\tif (deferred.changes.size) {\n\t\t\t// To the common path, which keys the shared entries, as `repoPath` may already be unregistered\n\t\t\tthis.cache.onRepositoryChanged(deferred.commonPath, deferred.changes);\n\t\t\t// And to a linked worktree's own entries while it is still registered, which its watcher would have cleared too\n\t\t\tif (repoPath !== deferred.commonPath && this.cache.isRegistered(repoPath)) {\n\t\t\t\tthis.cache.applyRepositoryChanges(repoPath, deferred.changes, 'share', { worktreeOnly: true });\n\t\t\t}\n\t\t}\n\t\tif (deferred.headMoved) {\n\t\t\t// Not added to the changes, which would clear the main checkout's own entries along with the shared ones\n\t\t\tconst registered = this.cache.getCommonPath(repoPath) === deferred.commonPath;\n\t\t\tthis.cache.onRepositoryChanged(registered ? repoPath : deferred.commonPath, ['head', 'heads']);\n\t\t}\n\t}\n\n\tprivate run(repoPath: string, force: boolean): Promise<void> | undefined {\n\t\tif (!force && this.isWatched(repoPath)) return undefined;\n\n\t\t// A watcher attaching has no baseline to hand off without a git dir\n\t\tif (this.cache.gitDir.get(repoPath) == null) return force ? undefined : this.resolveThenValidate(repoPath);\n\n\t\tconst waits = this.start(repoPath, force);\n\t\treturn waits?.length ? this.waitAtMost(waits) : undefined;\n\t}\n\n\t/** Starts validating `repoPath`, or joins the validations in flight; what a read waits for */\n\tprivate start(repoPath: string, force: boolean): (readonly [Waitable, Promise<void>])[] | undefined {\n\t\tconst gitDir = this.cache.gitDir.get(repoPath);\n\t\tif (gitDir == null) return undefined;\n\n\t\tconst commonPath = this.cache.getCommonPath(repoPath);\n\t\t// A watcher suspended holds what was left to it until it resumes, and suspending announces nothing\n\t\tfor (const [path, deferred] of this.deferred) {\n\t\t\tif (deferred.commonPath === commonPath && !this.isWatched(path)) {\n\t\t\t\tthis.onUnwatched(path);\n\t\t\t}\n\t\t}\n\n\t\tconst commonGitDir = (gitDir.commonUri ?? gitDir.uri).fsPath;\n\t\tconst root = this.getTarget(this.roots, repoPath, 'root', gitDir.uri.fsPath, commonPath, commonGitDir);\n\t\t// A root never validated reports everything its git dir could have moved, which clears the repository's shared\n\t\t// entries unless the common git dir vouches for its HEAD (see `apply`); the other worktrees never validated take\n\t\t// their first baselines with it, so each clears only its own entries rather than the shared ones again\n\t\tconst siblings = root.runs === 0 ? this.getSiblingTargets(repoPath, commonPath, commonGitDir) : [];\n\t\t// Read even while another worktree's watcher covers it: that watcher clears the shared entries, never this\n\t\t// worktree's own\n\t\tconst common = this.getTarget(this.commons, commonPath, 'common', commonGitDir, commonPath, commonGitDir);\n\n\t\tconst waits: (readonly [Waitable, Promise<void>])[] = [];\n\t\tconst previous: Promise<void>[] = [];\n\t\tconst start = (state: TargetState | undefined): TargetState | undefined => {\n\t\t\tif (state == null) return undefined;\n\n\t\t\tif (state.running != null) {\n\t\t\t\tif (!force) {\n\t\t\t\t\tif (state.slow !== state.running) {\n\t\t\t\t\t\twaits.push([state, state.running]);\n\t\t\t\t\t}\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tprevious.push(state.running);\n\t\t\t} else if (!force && state.settledAt != null) {\n\t\t\t\t// A clock set back since counts as outside the window, or nothing would validate until it caught up\n\t\t\t\tconst elapsed = this.now() - state.settledAt;\n\t\t\t\tif (elapsed >= 0 && elapsed < validationWindowMs) return undefined;\n\t\t\t}\n\t\t\treturn state;\n\t\t};\n\t\tconst startedRoot = start(root);\n\t\tconst startedCommon = start(common);\n\n\t\tif (startedRoot != null || startedCommon != null) {\n\t\t\tconst job = this.runTargets(repoPath, commonPath, startedRoot, startedCommon, common, siblings, previous);\n\t\t\tif (startedRoot != null) {\n\t\t\t\tstartedRoot.running = job;\n\t\t\t}\n\t\t\tif (startedCommon != null) {\n\t\t\t\tstartedCommon.running = job;\n\t\t\t}\n\t\t\t// So a read of one joins this validation rather than starting its own\n\t\t\tfor (const [, state] of siblings) {\n\t\t\t\tstate.running = job;\n\t\t\t}\n\t\t\tfor (const state of [startedRoot, startedCommon, ...siblings.map(([, s]) => s)]) {\n\t\t\t\tif (state != null) {\n\t\t\t\t\twaits.push([state, job]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn waits;\n\t}\n\n\t/**\n\t * Resolves the git dir of `repoPath` (through the gate, as one call, keyed by `repoPath` since its common git dir\n\t * isn't known yet), then validates it as usual within the same wait. That first validation has no baseline.\n\t */\n\tprivate resolveThenValidate(repoPath: string): Promise<void> | undefined {\n\t\tconst resolveGitDir = this.resolveGitDir;\n\t\tif (resolveGitDir == null) return undefined;\n\n\t\tlet state = this.resolutions.get(repoPath);\n\t\tlet running = state?.running;\n\t\tif (state != null && running != null) {\n\t\t\tif (state.slow === running) return undefined;\n\t\t} else {\n\t\t\tif (state?.settledAt != null) {\n\t\t\t\tconst elapsed = this.now() - state.settledAt;\n\t\t\t\tif (elapsed >= 0 && elapsed < state.retryAfterMs) return undefined;\n\t\t\t}\n\n\t\t\tstate = { started: [], retryAfterMs: validationWindowMs };\n\t\t\trunning = this.startResolution(repoPath, resolveGitDir, state);\n\t\t}\n\n\t\treturn this.waitAtMost([[state, running]]);\n\t}\n\n\tprivate startResolution(\n\t\trepoPath: string,\n\t\tresolveGitDir: (repoPath: string) => Promise<boolean>,\n\t\tstate: ResolutionState,\n\t): Promise<void> {\n\t\tlet found = false;\n\t\tthis.counts.gitDirLookups++;\n\t\tconst running: Promise<void> = this.gate\n\t\t\t.run(repoPath, () => resolveGitDir(repoPath))\n\t\t\t.catch((): undefined => undefined)\n\t\t\t.then(async resolved => {\n\t\t\t\tfound = resolved === true;\n\t\t\t\t// Only a definite \"no\" waits long: a failure may pass\n\t\t\t\tif (resolved === false) {\n\t\t\t\t\tstate.retryAfterMs = unresolvableRetryMs;\n\t\t\t\t}\n\t\t\t\tif (!found || this.isWatched(repoPath)) return;\n\n\t\t\t\tconst waits = this.start(repoPath, false);\n\t\t\t\tif (waits == null) return;\n\n\t\t\t\tstate.started.push(...waits);\n\t\t\t\tawait Promise.all(waits.map(([, validation]) => validation));\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tstate.settledAt = this.now();\n\t\t\t\tstate.running = undefined;\n\t\t\t\t// Reads go by the cached git dir from here on\n\t\t\t\tif (found && this.resolutions.get(repoPath) === state) {\n\t\t\t\t\tthis.resolutions.delete(repoPath);\n\t\t\t\t}\n\t\t\t});\n\t\tstate.running = running;\n\n\t\tthis.resolutions.delete(repoPath);\n\t\tthis.resolutions.set(repoPath, state);\n\t\tif (this.resolutions.size > maxTargets) {\n\t\t\tconst oldest = this.resolutions.keys().next();\n\t\t\tif (!oldest.done) {\n\t\t\t\tthis.resolutions.delete(oldest.value);\n\t\t\t}\n\t\t}\n\t\treturn running;\n\t}\n\n\t/**\n\t * Settles once `waits`' validations do, or once the timeout elapses, latching those still running as slow (and what\n\t * they started) so the reads after it don't wait for them again\n\t */\n\tprivate waitAtMost(waits: readonly (readonly [Waitable, Promise<void>])[]): Promise<void> {\n\t\tconst latch = (state: Waitable, running: Promise<void>): void => {\n\t\t\tif (state.running !== running) return;\n\n\t\t\tstate.slow = running;\n\t\t\tfor (const [started, startedRunning] of state.started ?? []) {\n\t\t\t\tlatch(started, startedRunning);\n\t\t\t}\n\t\t};\n\n\t\t// The waits never reject, so only the timeout lands in the rejection handler\n\t\treturn raceWithTimeout(Promise.all(waits.map(([, running]) => running)), this.timeoutMs).then(\n\t\t\t() => undefined,\n\t\t\t() => {\n\t\t\t\tthis.counts.waitsTimedOut++;\n\t\t\t\tfor (const [state, running] of waits) {\n\t\t\t\t\tlatch(state, running);\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * What validating has cost, for a host to weigh against watching: counts since the validator was created of the\n\t * validations run, those that cleared something, the reads served as is after their wait timed out, the git dir\n\t * lookups, the file-system calls made (a batch of stats counting as one) and the batches of stats that failed;\n\t * and, as of now, the calls stuck on a hung mount and the git dirs kept\n\t */\n\tgetResourceUsage(): ResourceUsage {\n\t\treturn {\n\t\t\t'unwatchedValidation.validations.count': this.counts.validations,\n\t\t\t'unwatchedValidation.validationsApplied.count': this.counts.validationsApplied,\n\t\t\t'unwatchedValidation.waitsTimedOut.count': this.counts.waitsTimedOut,\n\t\t\t'unwatchedValidation.gitDirLookups.count': this.counts.gitDirLookups,\n\t\t\t'unwatchedValidation.fsCalls.count': this.gate.calls,\n\t\t\t'unwatchedValidation.fsCallsStuck.count': this.gate.stuckCalls,\n\t\t\t'unwatchedValidation.statBatchesFailed.count': this.dirOptions.batcher?.failedBatches ?? 0,\n\t\t\t'unwatchedValidation.gitDirs.count': this.roots.size + this.commons.size,\n\t\t};\n\t}\n\n\t/** The repository's other worktrees whose watchers cover its common git dir */\n\tprivate getCommonWatchers(repoPath: string, commonPath: string): string[] {\n\t\tconst watchers = new Set<string>();\n\t\tif (commonPath !== repoPath && this.isWatched(commonPath)) {\n\t\t\twatchers.add(commonPath);\n\t\t}\n\t\tfor (const path of this.cache.getWorktreePaths(commonPath)) {\n\t\t\tif (path !== repoPath && this.isWatched(path)) {\n\t\t\t\twatchers.add(path);\n\t\t\t}\n\t\t}\n\t\treturn [...watchers];\n\t}\n\n\tprivate getTarget(\n\t\ttargets: Map<string, TargetState>,\n\t\tkey: string,\n\t\tkind: 'root' | 'common',\n\t\tbasePath: string,\n\t\tcommonPath: string,\n\t\tcommonGitDir: string,\n\t): TargetState {\n\t\tlet state = targets.get(key);\n\t\tif (state?.dir.basePath === basePath && state.dir.commonPath === commonPath) {\n\t\t\t// Kept newest, so the cap drops the target read longest ago\n\t\t\ttargets.delete(key);\n\t\t} else {\n\t\t\tstate = { dir: new ProbedGitDir(kind, basePath, commonPath, commonGitDir, this.dirOptions), runs: 0 };\n\t\t}\n\t\ttargets.set(key, state);\n\n\t\tif (targets.size > maxTargets) {\n\t\t\tconst oldest = targets.keys().next();\n\t\t\tif (!oldest.done) {\n\t\t\t\ttargets.delete(oldest.value);\n\t\t\t}\n\t\t}\n\t\treturn state;\n\t}\n\n\t/**\n\t * The root targets, new, of `repoPath`'s registered sibling worktrees that never had one: unwatched (a watcher covers\n\t * its own git dir, and validates it as it attaches), with a git dir the cache resolved in the same common git dir\n\t */\n\tprivate getSiblingTargets(\n\t\trepoPath: string,\n\t\tcommonPath: string,\n\t\tcommonGitDir: string,\n\t): (readonly [string, TargetState])[] {\n\t\tconst siblings: (readonly [string, TargetState])[] = [];\n\t\tconst room = Math.min(maxSiblingBaselines, maxTargets - this.roots.size);\n\t\tfor (const path of this.cache.getWorktreePaths(commonPath)) {\n\t\t\tif (siblings.length >= room) break;\n\t\t\t// One that failed and was reset still has its target, as does one in flight\n\t\t\tif (path === repoPath || this.roots.has(path) || this.isWatched(path)) continue;\n\t\t\tif (this.cache.getCommonPath(path) !== commonPath) continue;\n\n\t\t\tconst gitDir = this.cache.gitDir.get(path);\n\t\t\tif (gitDir == null || (gitDir.commonUri ?? gitDir.uri).fsPath !== commonGitDir) continue;\n\n\t\t\tsiblings.push([\n\t\t\t\tpath,\n\t\t\t\tthis.getTarget(this.roots, path, 'root', gitDir.uri.fsPath, commonPath, commonGitDir),\n\t\t\t]);\n\t\t}\n\t\treturn siblings;\n\t}\n\n\tprivate async runTargets(\n\t\trepoPath: string,\n\t\tcommonPath: string,\n\t\troot: TargetState | undefined,\n\t\tcommon: TargetState | undefined,\n\t\t/** The repository's common target, whether or not this validation started it */\n\t\tcommonTarget: TargetState,\n\t\tsiblings: readonly (readonly [string, TargetState])[],\n\t\tprevious: readonly Promise<void>[],\n\t): Promise<void> {\n\t\tconst rootRun = root != null ? ++root.runs : 0;\n\t\tconst commonRun = common != null ? ++common.runs : 0;\n\t\tconst siblingRuns = siblings.map(([, state]) => ++state.runs);\n\t\t// Before anything is awaited: a watcher that attaches from here on reports only what changes after it attached,\n\t\t// and its own validation reads the common git dir after this one, from the baseline this one advances\n\t\tconst watchedAtStart = new Set(this.getCommonWatchers(repoPath, commonPath));\n\t\ttry {\n\t\t\t// A forced validation reads after the one in flight, never beside it\n\t\t\tif (previous.length) {\n\t\t\t\tawait Promise.all(previous);\n\t\t\t}\n\n\t\t\t// The root and common git dirs of one validation can share paths: a main checkout's are the same, and a\n\t\t\t// linked worktree's root is an admin entry of the common one\n\t\t\tconst memo: StatMemo = new Map();\n\t\t\tconst [rootResult, commonResult, siblingResults] = await Promise.all([\n\t\t\t\troot?.dir.validate(memo, repoPath),\n\t\t\t\tcommon?.dir.validate(memo, repoPath),\n\t\t\t\tPromise.all(siblings.map(([path, state]) => state.dir.validate(memo, path))),\n\t\t\t]);\n\t\t\tthis.counts.validations++;\n\t\t\tif (rootResult?.changes.size || commonResult?.changes.size) {\n\t\t\t\tthis.counts.validationsApplied++;\n\t\t\t}\n\t\t\tthis.apply(\n\t\t\t\trepoPath,\n\t\t\t\tcommonPath,\n\t\t\t\trootResult,\n\t\t\t\tcommonResult,\n\t\t\t\tcommonTarget.dir,\n\t\t\t\tsiblings.map(([path, state], i) => [path, state, siblingResults[i]] as const),\n\t\t\t\twatchedAtStart,\n\t\t\t);\n\t\t} catch {\n\t\t\t// `validate` never rejects, so only applying can have thrown; whatever it did apply stands, but a sibling\n\t\t\t// may have been left baselined with nothing cleared, so each reports everything again at its next validation\n\t\t\tfor (const [, state] of siblings) {\n\t\t\t\tstate.dir.reset();\n\t\t\t}\n\t\t} finally {\n\t\t\t// Before the validation settles, so a read it gated finds the window open and runs no other\n\t\t\tconst settledAt = this.now();\n\t\t\tif (root != null) {\n\t\t\t\troot.settledAt = settledAt;\n\t\t\t\tif (root.runs === rootRun) {\n\t\t\t\t\troot.running = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (common != null) {\n\t\t\t\tcommon.settledAt = settledAt;\n\t\t\t\tif (common.runs === commonRun) {\n\t\t\t\t\tcommon.running = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Never stamped as validated: a sibling's own first read still validates, from the baseline taken here\n\t\t\tfor (const [i, [, state]] of siblings.entries()) {\n\t\t\t\tif (state.runs === siblingRuns[i]) {\n\t\t\t\t\tstate.running = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Applies what moved to `repoPath`, and what moved in the common git dir to its other unwatched registered worktrees\n\t * too, as the common watcher would have told each of them. While another worktree's watcher covers the common git\n\t * dir, it already cleared the shared entries, so only the worktrees' own are. A watcher covers it only if it watched\n\t * since before the stats began (`watchedAtStart`). What each sibling whose first baseline was taken with it reports\n\t * clears that sibling's own entries, as `repoPath`'s report cleared the shared ones.\n\t *\n\t * Once the common git dir (`commonDir`) holds a reading of a linked worktree's HEAD, it reports that HEAD's every\n\t * move, and a commit on its branch as a ref directory moving. Each such move clears the shared entries, as that\n\t * worktree's own report would (see {@link applyMovedHeads}), or is left to its watcher, which reports it or has it\n\t * applied as it leaves. So nothing the shared entries hold of that worktree can go stale unseen: its first report (or\n\t * its first after a reset) clears only its own entries, for up to {@link maxOwnBaselines} of them\n\t */\n\tprivate apply(\n\t\trepoPath: string,\n\t\tcommonPath: string,\n\t\troot: ValidationResult | undefined,\n\t\tcommon: ValidationResult | undefined,\n\t\tcommonDir: ProbedGitDir,\n\t\tsiblings: readonly (readonly [string, TargetState, ValidationResult])[],\n\t\twatchedAtStart: ReadonlySet<string>,\n\t): void {\n\t\tconst watchers = this.getCommonWatchers(repoPath, commonPath).filter(p => watchedAtStart.has(p));\n\t\tconst commonWatched = watchers.length !== 0;\n\n\t\tconst own = this.getVouchedBaselines(repoPath, commonPath, root, commonDir, siblings);\n\t\t// A common git dir without a baseline before this validation saw none of those HEADs move before now\n\t\tif (common?.noBaseline || own.size > maxOwnBaselines) {\n\t\t\town.clear();\n\t\t}\n\n\t\t// What `repoPath`'s report applies in full, which is what clears the shared entries\n\t\tconst changes = new Set<RepositoryChange>(own.has(repoPath) ? undefined : root?.changes);\n\t\tif (!commonWatched) {\n\t\t\tfor (const change of common?.changes ?? []) {\n\t\t\t\tchanges.add(change);\n\t\t\t}\n\t\t}\n\n\t\tif (root != null && own.has(repoPath)) {\n\t\t\tthis.cache.applyLinkedWorktreeChanges(repoPath, root.changes, 'share');\n\t\t}\n\t\tif (changes.size) {\n\t\t\t// Only the common git dir reports a `'worktreeHead'`\n\t\t\tthis.cache.onRepositoryChanged(repoPath, changes, {\n\t\t\t\tmovedWorktrees: changes.has('worktreeHead') ? common?.movedWorktrees : undefined,\n\t\t\t});\n\t\t}\n\t\tthis.applyMovedHeads(repoPath, commonPath, common, watchers, changes.has('head'));\n\n\t\t// `repoPath`'s report cleared the shared entries of the worktrees registered under its common path as of now, so\n\t\t// it covers a sibling's only while `repoPath` is still under that path and reported all the sibling did\n\t\tconst shared = this.cache.getCommonPath(repoPath) === commonPath;\n\t\tfor (const [path, state, result] of siblings) {\n\t\t\tif (!this.cache.isRegistered(path) || this.cache.getCommonPath(path) !== commonPath) {\n\t\t\t\t// Nothing was cleared for it, so its baseline goes too\n\t\t\t\tstate.dir.reset();\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (own.has(path)) {\n\t\t\t\tthis.cache.applyLinkedWorktreeChanges(path, result.changes, 'share');\n\t\t\t} else if (shared && [...result.changes].every(c => changes.has(c))) {\n\t\t\t\tthis.cache.applyRepositoryChanges(path, result.changes, 'share', { worktreeOnly: true });\n\t\t\t} else {\n\t\t\t\t// As its own first validation would have\n\t\t\t\tthis.cache.onRepositoryChanged(path, result.changes);\n\t\t\t}\n\t\t}\n\n\t\tif (!common?.changes.size) return;\n\n\t\tif (commonWatched) {\n\t\t\tthis.cache.applyRepositoryChanges(repoPath, common.changes, 'share', { worktreeOnly: true });\n\n\t\t\t// Kept for each watcher until it leaves (see `onUnwatched`), since one that leaves first drops what it held back\n\t\t\tfor (const path of watchers) {\n\t\t\t\tconst deferred = this.getDeferred(path, commonPath);\n\t\t\t\tfor (const change of common.changes) {\n\t\t\t\t\tdeferred.changes.add(change);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const path of this.cache.getWorktreePaths(commonPath)) {\n\t\t\tif (path === repoPath || watchers.includes(path)) continue;\n\n\t\t\tthis.cache.applyRepositoryChanges(path, common.changes, 'share', { worktreeOnly: true });\n\t\t}\n\t}\n\n\t/** What is left to the watcher of `path` until it leaves (see {@link onUnwatched}) */\n\tprivate getDeferred(\n\t\tpath: string,\n\t\tcommonPath: string,\n\t): { readonly commonPath: string; readonly changes: Set<RepositoryChange>; headMoved: boolean } {\n\t\tlet deferred = this.deferred.get(path);\n\t\tif (deferred?.commonPath !== commonPath) {\n\t\t\tdeferred = { commonPath: commonPath, changes: new Set(), headMoved: false };\n\t\t\tthis.deferred.set(path, deferred);\n\t\t}\n\t\treturn deferred;\n\t}\n\n\t/**\n\t * The worktrees, of `repoPath` and the `siblings`, whose report without a baseline the common git dir vouches for as\n\t * of now: each a linked worktree registered under `commonPath` whose HEAD `commonDir` holds a reading of\n\t */\n\tprivate getVouchedBaselines(\n\t\trepoPath: string,\n\t\tcommonPath: string,\n\t\troot: ValidationResult | undefined,\n\t\tcommonDir: ProbedGitDir,\n\t\tsiblings: readonly (readonly [string, TargetState, ValidationResult])[],\n\t): Set<string> {\n\t\tconst vouched = (path: string): boolean => {\n\t\t\tif (this.cache.getCommonPath(path) !== commonPath) return false;\n\n\t\t\tconst id = this.cache.getLinkedWorktreeId(path);\n\t\t\treturn id != null && commonDir.holdsWorktreeHead(id);\n\t\t};\n\n\t\tconst paths = new Set<string>();\n\t\tif (root?.noBaseline && vouched(repoPath)) {\n\t\t\tpaths.add(repoPath);\n\t\t}\n\t\tfor (const [path, , result] of siblings) {\n\t\t\tif (result.noBaseline && vouched(path)) {\n\t\t\t\tpaths.add(path);\n\t\t\t}\n\t\t}\n\t\treturn paths;\n\t}\n\n\t/**\n\t * Applies the common git dir's sighting of linked worktrees' HEADs moving as each worktree's own report would be:\n\t * the shared entries hold each one's HEAD too (where the branch list places its branch, what a checkout's reflog\n\t * says a branch was based on), which a `'worktreeHead'` clears nothing of. One whose own watcher covered the common\n\t * git dir reports it itself, or, should that watcher leave first, has it applied as it leaves. A move not attributed to a registered worktree is applied to `repoPath`, as is a report\n\t * without a baseline (whose shared entries a watcher of the common git dir cleared, if not `repoPath`'s report),\n\t * unless what `repoPath`'s report applied in full saw its own HEAD move (`appliedHead`)\n\t */\n\tprivate applyMovedHeads(\n\t\trepoPath: string,\n\t\tcommonPath: string,\n\t\tcommon: ValidationResult | undefined,\n\t\twatchers: readonly string[],\n\t\tappliedHead: boolean,\n\t): void {\n\t\tif (common == null) return;\n\n\t\tconst paths = new Set<string>();\n\t\tif (common.noBaseline || (common.changes.has('worktreeHead') && common.movedWorktrees == null)) {\n\t\t\tpaths.add(repoPath);\n\t\t} else if (common.changes.has('worktreeHead')) {\n\t\t\tconst pathsById = new Map<string, string>();\n\t\t\tfor (const path of this.cache.getWorktreePaths(commonPath)) {\n\t\t\t\tconst id = this.cache.getLinkedWorktreeId(path);\n\t\t\t\tif (id != null) {\n\t\t\t\t\tpathsById.set(id, path);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const id of common.movedWorktrees ?? []) {\n\t\t\t\tconst path = pathsById.get(id) ?? repoPath;\n\t\t\t\tif (watchers.includes(path)) {\n\t\t\t\t\tthis.getDeferred(path, commonPath).headMoved = true;\n\t\t\t\t} else {\n\t\t\t\t\tpaths.add(path);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (appliedHead) {\n\t\t\tpaths.delete(repoPath);\n\t\t}\n\n\t\tfor (const path of paths) {\n\t\t\tthis.cache.onRepositoryChanged(path, ['head', 'heads']);\n\t\t}\n\t}\n}\n\n/**\n * Runs file-system calls at most {@link maxFsCalls} at once, and at most {@link maxFsCallsPerRepo} at once for a key;\n * the calls waiting start in the order they came, skipping those whose key is busy. A call outstanding past the\n * timeout is stuck, as on a hung mount: it stops counting against {@link maxFsCalls}, so other keys' calls go on, but\n * keeps its key busy and holds one of the threads the gate is allowed until it returns\n */\nclass FileSystemGate {\n\t/** The keys with calls in flight, by how many */\n\tprivate readonly busy = new Map<string, number>();\n\tprivate readonly waiting: { readonly key: string; readonly start: () => void }[] = [];\n\tprivate active = 0;\n\tprivate stuck = 0;\n\t/** The calls made since it was created */\n\tcalls = 0;\n\n\tconstructor(\n\t\tprivate readonly timeoutMs: number,\n\t\t/** Calls in flight at most, stuck ones included */\n\t\tprivate readonly maxThreads: number,\n\t) {}\n\n\tasync run<T>(key: string, call: () => Promise<T>): Promise<T> {\n\t\tif (this.canStart(key)) {\n\t\t\tthis.acquire(key);\n\t\t} else {\n\t\t\tawait new Promise<void>(resolve => this.waiting.push({ key: key, start: resolve }));\n\t\t}\n\n\t\tthis.calls++;\n\t\tlet stuck = false;\n\t\tconst timer = setTimeout(() => {\n\t\t\tstuck = true;\n\t\t\tthis.active--;\n\t\t\tthis.stuck++;\n\t\t\tthis.drain();\n\t\t}, this.timeoutMs);\n\t\t// A call alone must not keep a (Node) process alive; in the browser timers are numbers\n\t\tif (typeof timer !== 'number') {\n\t\t\ttimer.unref();\n\t\t}\n\n\t\ttry {\n\t\t\treturn await call();\n\t\t} finally {\n\t\t\tif (stuck) {\n\t\t\t\tthis.stuck--;\n\t\t\t} else {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tthis.active--;\n\t\t\t}\n\t\t\tthis.release(key);\n\t\t}\n\t}\n\n\t/** The calls outstanding past the timeout */\n\tget stuckCalls(): number {\n\t\treturn this.stuck;\n\t}\n\n\tprivate hasSlot(): boolean {\n\t\treturn this.active < maxFsCalls && this.active + this.stuck < this.maxThreads;\n\t}\n\n\tprivate canStart(key: string): boolean {\n\t\treturn this.hasSlot() && (this.busy.get(key) ?? 0) < maxFsCallsPerRepo;\n\t}\n\n\tprivate acquire(key: string): void {\n\t\tthis.active++;\n\t\tthis.busy.set(key, (this.busy.get(key) ?? 0) + 1);\n\t}\n\n\tprivate release(key: string): void {\n\t\tconst count = (this.busy.get(key) ?? 1) - 1;\n\t\tif (count > 0) {\n\t\t\tthis.busy.set(key, count);\n\t\t} else {\n\t\t\tthis.busy.delete(key);\n\t\t}\n\t\tthis.drain();\n\t}\n\n\tprivate drain(): void {\n\t\tlet i = 0;\n\t\twhile (i < this.waiting.length && this.hasSlot()) {\n\t\t\tconst waiter = this.waiting[i];\n\t\t\tif (!this.canStart(waiter.key)) {\n\t\t\t\ti++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tthis.waiting.splice(i, 1);\n\t\t\t// Claimed before it resumes, so no call that comes meanwhile takes its slot\n\t\t\tthis.acquire(waiter.key);\n\t\t\twaiter.start();\n\t\t}\n\t}\n}\n\n/**\n * Collects the stats asked for a gate key in one synchronous run (a poll's probes, the root and common git dirs' first\n * polls of a validation) and makes them, once that run is over, as one call through the gate per {@link maxBatchPaths}\n * paths. A batch that fails has its paths read one at a time, each a call of its own, once it gave its slot back: a key\n * runs one call at a time. For {@link failedBatchBackoffMs} after, every stat is read that way\n */\nclass StatBatcher {\n\t/** By gate key, the paths asked for since its last batch went out, each with its reading and what settles it */\n\tprivate readonly pending = new Map<string, Map<string, PendingStat>>();\n\t/** When the last batch failed */\n\tprivate failedAt: number | undefined;\n\t/** The batches that failed since it was created */\n\tfailedBatches = 0;\n\n\tconstructor(\n\t\tprivate readonly gate: FileSystemGate,\n\t\tprivate readonly statMany: (paths: readonly string[]) => Promise<readonly BatchedStat[]>,\n\t\tprivate readonly stat: (path: string) => Promise<ProbeStat | undefined>,\n\t\tprivate readonly now: () => number,\n\t) {}\n\n\t/** `path`'s reading, as {@link statThroughGate} reads it; never rejects */\n\tread(gateKey: string, path: string): Promise<ProbeStat | undefined> {\n\t\tif (this.failedAt != null) {\n\t\t\tconst backingOff = this.now() - this.failedAt < failedBatchBackoffMs;\n\t\t\tif (backingOff) return statThroughGate(this.gate, gateKey, this.stat, path);\n\n\t\t\tthis.failedAt = undefined;\n\t\t}\n\n\t\tlet batch = this.pending.get(gateKey);\n\t\tif (batch == null) {\n\t\t\tbatch = new Map();\n\t\t\tthis.pending.set(gateKey, batch);\n\t\t\t// A microtask, not a timer: it runs as soon as the synchronous run that asked is over\n\t\t\tvoid Promise.resolve().then(() => this.flush(gateKey));\n\t\t}\n\n\t\t// Asked again in the same batch only by git dirs that don't share a memo, which read it alike\n\t\tlet pending = batch.get(path);\n\t\tif (pending == null) {\n\t\t\tlet settle!: PendingStat['settle'];\n\t\t\tconst reading = new Promise<ProbeStat | undefined>(resolve => {\n\t\t\t\tsettle = resolve;\n\t\t\t});\n\t\t\tpending = { reading: reading, settle: settle };\n\t\t\tbatch.set(path, pending);\n\t\t}\n\t\treturn pending.reading;\n\t}\n\n\tprivate flush(gateKey: string): void {\n\t\tconst batch = this.pending.get(gateKey);\n\t\tif (batch == null) return;\n\n\t\tthis.pending.delete(gateKey);\n\t\tconst paths = [...batch.keys()];\n\t\tfor (let i = 0; i < paths.length; i += maxBatchPaths) {\n\t\t\tthis.send(gateKey, batch, paths.slice(i, i + maxBatchPaths));\n\t\t}\n\t}\n\n\t/** Makes the stats of `paths` as one call through the gate, settling each one's reading in `batch` */\n\tprivate send(gateKey: string, batch: Map<string, PendingStat>, paths: readonly string[]): void {\n\t\tvoid this.gate\n\t\t\t.run(gateKey, async () => {\n\t\t\t\tconst readings = await this.statMany(paths);\n\t\t\t\tif (readings.length !== paths.length) {\n\t\t\t\t\tthrow new Error(`Expected ${paths.length} stats, got ${readings.length}`);\n\t\t\t\t}\n\t\t\t\treturn readings;\n\t\t\t})\n\t\t\t.then(\n\t\t\t\treadings => {\n\t\t\t\t\tfor (const [i, path] of paths.entries()) {\n\t\t\t\t\t\tconst reading = readings[i];\n\t\t\t\t\t\tbatch\n\t\t\t\t\t\t\t.get(path)\n\t\t\t\t\t\t\t?.settle(\n\t\t\t\t\t\t\t\treading === 'missing' ? undefined : reading === 'unreadable' ? unreadable : reading,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tthis.failedBatches++;\n\t\t\t\t\tthis.failedAt = this.now();\n\t\t\t\t\t// The batch gave its slot back before this runs, so each waits its turn rather than for itself\n\t\t\t\t\tfor (const path of paths) {\n\t\t\t\t\t\tbatch.get(path)?.settle(statThroughGate(this.gate, gateKey, this.stat, path));\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t}\n}\n\ninterface PendingStat {\n\treadonly reading: Promise<ProbeStat | undefined>;\n\treadonly settle: (reading: ProbeStat | undefined | Promise<ProbeStat | undefined>) => void;\n}\n\n/**\n * `path`'s reading as one call through the gate: `undefined` when it isn't there, {@link unreadable} when its stat\n * failed otherwise; never rejects\n */\nfunction statThroughGate(\n\tgate: FileSystemGate,\n\tgateKey: string,\n\tstat: (path: string) => Promise<ProbeStat | undefined>,\n\tpath: string,\n): Promise<ProbeStat | undefined> {\n\treturn gate\n\t\t.run(gateKey, () => stat(path))\n\t\t.catch((ex: unknown) => {\n\t\t\t// A path under one that is now a file (a ref directory replaced by a ref of its name) isn't there\n\t\t\tif (isNotFound(ex) || isNotADirectory(ex)) return undefined;\n\n\t\t\t// Read as a reading of its own rather than skipped (as the probe target skips a stat that throws), so the\n\t\t\t// path moves as it becomes unreadable and as it becomes readable again\n\t\t\treturn unreadable;\n\t\t});\n}\n\ninterface ProbedGitDirOptions {\n\t/** Shared by every git dir the validator reads */\n\treadonly gate: FileSystemGate;\n\treadonly stat: (path: string) => Promise<ProbeStat | undefined>;\n\t/** Shared by every git dir the validator reads; without it, each stat is a call of its own */\n\treadonly batcher: StatBatcher | undefined;\n\treadonly readDirectory: (path: string) => Promise<readonly (readonly [string, number])[]>;\n\treadonly readFile: ((path: string) => Promise<Uint8Array | undefined>) | undefined;\n\treadonly getIgnoredWorktreeRoots: ((repoPath: string) => Promise<readonly string[]>) | undefined;\n\treadonly isRacy: (stat: ProbeStat, path: string) => boolean;\n}\n\n/** The probes of a gate's files, read only once the gate moved */\ninterface GatedTarget {\n\treadonly target: GitDirProbeTarget;\n\t/** Whether its baseline was taken */\n\tread: boolean;\n}\n\n/**\n * The readings of one git dir: a worktree's own (`root`), or the common one, whose ref directories and worktree admin\n * entries it finds by listing them. A directory is listed only after its reading was recorded, so whatever a listing\n * missed moves the directory again. A path that can't be read counts as moved as it becomes unreadable and again as it\n * becomes readable; a directory that can't be listed keeps what it held and is listed again at the next validation, so\n * what changes deeper inside it goes unseen until it can be. Without a baseline, a worktree's own git dir reports only\n * what its probes can, the common one everything.\n */\nclass ProbedGitDir {\n\t/** The probes read every time, the gates among them */\n\tprivate target: GitDirProbeTarget;\n\t/** By the path of their gate: the git dir's own, and each admin entry's */\n\tprivate readonly gated = new Map<string, GatedTarget>();\n\tprivate baselined = false;\n\t/** The directories found under the ref namespaces, which a ref created or deleted in them moves */\n\tprivate readonly refDirs = new Set<string>();\n\t/** By admin id, whether core ignores the linked worktree, which leaves only its `gitdir` probed */\n\tprivate readonly worktrees = new Map<string, { ignored: boolean }>();\n\t/** The probes that moved during the current validation, by path */\n\tprivate readonly moved = new Map<string, GitDirProbe>();\n\t/** The paths of the probes that moved in the last poll */\n\tprivate readonly movedInPoll = new Set<string>();\n\t/** The gates that moved during the current validation */\n\tprivate readonly movedGates = new Set<string>();\n\t/** The admin ids found during the current validation */\n\tprivate readonly foundWorktrees = new Set<string>();\n\t/** The admin ids removed during the current validation, by whether they were ignored */\n\tprivate readonly removedWorktrees = new Map<string, boolean>();\n\t/** The admin ids whose ignored status flipped during the current validation */\n\tprivate readonly flippedWorktrees = new Set<string>();\n\t/**\n\t * The directories the next validation lists whether they moved or not: those that couldn't be listed, and those\n\t * left at {@link maxDiscoveryPolls}\n\t */\n\tprivate readonly pendingDirs = new Set<string>();\n\t/** The admin ids left at {@link maxDiscoveryPolls}, whose `gitdir` the next validation reads whether it moved or not */\n\tprivate readonly pendingEntries = new Set<string>();\n\t/** The common git dir's own `reftable/tables.list`; only while it's there do the admin entries have their own */\n\tprivate readonly reftablePath: string | undefined;\n\t/** Whether {@link reftablePath} was there at its last reading */\n\tprivate reftable = false;\n\t/** The current validation's */\n\tprivate memo: StatMemo | undefined;\n\t/** The current validation's repository, whose git dir the cache holds */\n\tprivate repoPath: string | undefined;\n\t/** The current validation's, once a worktree needed them */\n\tprivate ignoredRoots: Promise<readonly string[]> | undefined;\n\n\tconstructor(\n\t\treadonly kind: 'root' | 'common',\n\t\treadonly basePath: string,\n\t\t/** The repository's common path as the cache resolved it */\n\t\treadonly commonPath: string,\n\t\t/**\n\t\t * The repository's common git dir, which keys its file-system calls in the gate, shared with its worktrees':\n\t\t * unlike the common path, the same for a worktree the cache never registered\n\t\t */\n\t\tprivate readonly gateKey: string,\n\t\tprivate readonly options: ProbedGitDirOptions,\n\t) {\n\t\tthis.reftablePath = kind === 'common' ? joinPaths(basePath, reftableProbePath) : undefined;\n\t\tthis.target = this.createTarget(() => this.getProbes());\n\t\tthis.addGated(gitDirGatePath, kind === 'root' ? rootGatedProbes : commonGatedProbes);\n\t}\n\n\t/**\n\t * Polls the probes and answers what moved since the last validation; everything it can report when there's no\n\t * baseline. `memo` holds the stats of the validation it's part of\n\t */\n\tasync validate(memo: StatMemo, repoPath: string): Promise<ValidationResult> {\n\t\tthis.moved.clear();\n\t\tthis.movedGates.clear();\n\t\tthis.foundWorktrees.clear();\n\t\tthis.removedWorktrees.clear();\n\t\tthis.flippedWorktrees.clear();\n\t\tthis.memo = memo;\n\t\tthis.repoPath = repoPath;\n\n\t\tlet failed = false;\n\t\ttry {\n\t\t\tawait this.poll();\n\t\t\tif (this.kind === 'common') {\n\t\t\t\tawait this.discover();\n\t\t\t}\n\t\t\tawait this.pollGated();\n\t\t} catch {\n\t\t\tfailed = true;\n\t\t} finally {\n\t\t\tthis.memo = undefined;\n\t\t\tthis.repoPath = undefined;\n\t\t\tthis.ignoredRoots = undefined;\n\t\t}\n\n\t\tif (failed || !this.baselined) {\n\t\t\tif (failed) {\n\t\t\t\tthis.reset();\n\t\t\t} else {\n\t\t\t\tthis.baselined = true;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tchanges: new Set(this.kind === 'root' ? rootReportableChanges : allWatchedRepositoryChanges),\n\t\t\t\tmovedWorktrees: undefined,\n\t\t\t\tnoBaseline: true,\n\t\t\t};\n\t\t}\n\n\t\treturn this.classify();\n\t}\n\n\t/**\n\t * Whether it holds a reading of the HEAD of the linked worktree with the admin id `id`, so it reports that HEAD's\n\t * every move from here on: a common git dir with a baseline, probing that worktree's admin entry (not ignored), whose\n\t * files it read behind it\n\t */\n\tholdsWorktreeHead(id: string): boolean {\n\t\tif (this.kind !== 'common' || !this.baselined || this.worktrees.get(id)?.ignored !== false) return false;\n\n\t\treturn this.gated.get(`worktrees/${id}`)?.read === true;\n\t}\n\n\t/** Drops every reading, so the next validation has no baseline and reports everything it can */\n\treset(): void {\n\t\tthis.target = this.createTarget(() => this.getProbes());\n\t\tthis.gated.clear();\n\t\tthis.addGated(gitDirGatePath, this.kind === 'root' ? rootGatedProbes : commonGatedProbes);\n\t\tthis.baselined = false;\n\t\tthis.refDirs.clear();\n\t\tthis.worktrees.clear();\n\t\tthis.pendingDirs.clear();\n\t\tthis.pendingEntries.clear();\n\t\tthis.reftable = false;\n\t}\n\n\tprivate createTarget(getProbes: () => Iterable<GitDirProbe>): GitDirProbeTarget {\n\t\treturn new GitDirProbeTarget(\n\t\t\tthis.basePath,\n\t\t\t{ stat: path => this.stat(path), invalidate: () => {} },\n\t\t\tgetProbes,\n\t\t\tnew Map(),\n\t\t\t(_event, probe) => {\n\t\t\t\tif (isGatePath(probe.path)) {\n\t\t\t\t\tthis.movedGates.add(probe.path);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.moved.set(probe.path, probe);\n\t\t\t\tthis.movedInPoll.add(probe.path);\n\t\t\t},\n\t\t\t{ isRacy: this.options.isRacy },\n\t\t);\n\t}\n\n\tprivate addGated(gatePath: string, probes: readonly GitDirProbe[]): void {\n\t\tthis.gated.set(gatePath, { target: this.createTarget(() => probes), read: false });\n\t}\n\n\tprivate addWorktreeGated(id: string): void {\n\t\tthis.addGated(`worktrees/${id}`, [{ path: `worktrees/${id}/HEAD` }, { path: `worktrees/${id}/locked` }]);\n\t}\n\n\tprivate async stat(path: string): Promise<ProbeStat | undefined> {\n\t\tlet stat = this.memo?.get(path);\n\t\tif (stat == null) {\n\t\t\t// Mapped before it's shared, so the root and common git dirs read the same\n\t\t\tconst { gate, batcher } = this.options;\n\t\t\tstat =\n\t\t\t\tbatcher != null\n\t\t\t\t\t? batcher.read(this.gateKey, path)\n\t\t\t\t\t: statThroughGate(gate, this.gateKey, this.options.stat, path);\n\t\t\tthis.memo?.set(path, stat);\n\t\t}\n\n\t\tconst result = await stat;\n\t\tif (path === this.reftablePath && result !== unreadable) {\n\t\t\tthis.reftable = result != null;\n\t\t}\n\t\treturn result;\n\t}\n\n\tprivate poll(): Promise<void> {\n\t\tthis.movedInPoll.clear();\n\t\treturn this.target.poll();\n\t}\n\n\t/** Polls the files of each gate that moved during this validation, and of each never read */\n\tprivate async pollGated(): Promise<void> {\n\t\tconst due = [...this.gated].filter(([gate, gated]) => !gated.read || this.movedGates.has(gate));\n\t\tawait Promise.all(\n\t\t\tdue.map(async ([, gated]) => {\n\t\t\t\tawait gated.target.poll();\n\t\t\t\tgated.read = true;\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate getProbes(): GitDirProbe[] {\n\t\tif (this.kind === 'root') return [...rootAlwaysProbes];\n\n\t\tconst probes = [...commonAlwaysProbes];\n\t\tfor (const path of this.refDirs) {\n\t\t\tprobes.push({ path: path });\n\t\t}\n\t\tfor (const [id, { ignored }] of this.worktrees) {\n\t\t\tprobes.push({ path: `worktrees/${id}/gitdir` });\n\t\t\tif (ignored) continue;\n\n\t\t\tprobes.push({ path: `worktrees/${id}` });\n\t\t\tif (this.reftable) {\n\t\t\t\tprobes.push({ path: `worktrees/${id}/${reftableProbePath}` });\n\t\t\t}\n\t\t}\n\t\treturn probes;\n\t}\n\n\t/** The listed directories that moved in the last poll */\n\tprivate getMovedDirs(): string[] {\n\t\treturn [...this.movedInPoll].filter(p => p === 'worktrees' || refNamespaces.includes(p) || this.refDirs.has(p));\n\t}\n\n\t/** The known admin ids whose `gitdir` moved in the last poll */\n\tprivate getMovedGitdirs(): string[] {\n\t\tconst ids: string[] = [];\n\t\tfor (const path of this.movedInPoll) {\n\t\t\tconst entry = parseWorktreeAdminPath(path);\n\t\t\tif (entry?.file === 'gitdir' && this.worktrees.has(entry.id)) {\n\t\t\t\tids.push(entry.id);\n\t\t\t}\n\t\t}\n\t\treturn ids;\n\t}\n\n\t/**\n\t * Lists the directories that moved in the last poll (every one, the first time), and polls again while that finds\n\t * new ones, so they have readings before the caches are read again: the move of the directory they're in already\n\t * reported whatever they hold. Reads whether each admin entry new to it, or whose `gitdir` moved, is ignored, once\n\t * that `gitdir` has a reading. Also lists what an earlier validation left: the directories it couldn't list, and\n\t * what was still to list or read when it reached {@link maxDiscoveryPolls}.\n\t */\n\tprivate async discover(): Promise<void> {\n\t\tlet dirs = this.baselined\n\t\t\t? [...new Set([...this.pendingDirs, ...this.getMovedDirs()])]\n\t\t\t: [...refNamespaces, 'worktrees'];\n\t\tlet entries = this.baselined ? [...new Set([...this.pendingEntries, ...this.getMovedGitdirs()])] : [];\n\t\tthis.pendingEntries.clear();\n\n\t\tfor (let polls = 0; ; polls++) {\n\t\t\tconst found = dirs.length ? await this.list(dirs) : { dirs: [], worktrees: [] };\n\t\t\tconst unignored = entries.length ? await this.readIgnored(entries) : false;\n\t\t\tif (!found.dirs.length && !found.worktrees.length && !unignored) return;\n\n\t\t\t// Even at the cap, so what was just found has a reading before the caches are read again\n\t\t\tawait this.poll();\n\t\t\tdirs = [...found.dirs, ...this.getMovedDirs()];\n\t\t\tentries = [...new Set([...found.worktrees, ...this.getMovedGitdirs()])];\n\n\t\t\tif (polls === maxDiscoveryPolls) {\n\t\t\t\tfor (const dir of dirs) {\n\t\t\t\t\tthis.pendingDirs.add(dir);\n\t\t\t\t}\n\t\t\t\tfor (const id of entries) {\n\t\t\t\t\tthis.pendingEntries.add(id);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Lists `dirs`, dropping the directories (or admin entries) no longer in them, and answers what's new. One that\n\t * can't be listed keeps what it held, and is left for the next validation to list\n\t */\n\tprivate async list(dirs: readonly string[]): Promise<{ dirs: string[]; worktrees: string[] }> {\n\t\tconst found: { dirs: string[]; worktrees: string[] } = { dirs: [], worktrees: [] };\n\n\t\tawait Promise.all(\n\t\t\tdirs.map(async dir => {\n\t\t\t\tconst names = await this.readDirectories(dir);\n\t\t\t\tif (names == null) {\n\t\t\t\t\tthis.pendingDirs.add(dir);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.pendingDirs.delete(dir);\n\t\t\t\tif (dir === 'worktrees') {\n\t\t\t\t\tfor (const [id, { ignored }] of this.worktrees) {\n\t\t\t\t\t\tif (!names.includes(id)) {\n\t\t\t\t\t\t\tthis.removedWorktrees.set(id, ignored);\n\t\t\t\t\t\t\tthis.worktrees.delete(id);\n\t\t\t\t\t\t\tthis.gated.delete(`worktrees/${id}`);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (const id of names) {\n\t\t\t\t\t\tif (!this.worktrees.has(id)) {\n\t\t\t\t\t\t\t// Probed as not ignored until its `gitdir` is read\n\t\t\t\t\t\t\tthis.worktrees.set(id, { ignored: false });\n\t\t\t\t\t\t\tthis.addWorktreeGated(id);\n\t\t\t\t\t\t\tthis.foundWorktrees.add(id);\n\t\t\t\t\t\t\tfound.worktrees.push(id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst children = new Set(names.map(name => `${dir}/${name}`));\n\t\t\t\tfor (const path of this.refDirs) {\n\t\t\t\t\tif (path.substring(0, path.lastIndexOf('/')) !== dir || children.has(path)) continue;\n\n\t\t\t\t\tfor (const p of this.refDirs) {\n\t\t\t\t\t\tif (p === path || p.startsWith(`${path}/`)) {\n\t\t\t\t\t\t\tthis.refDirs.delete(p);\n\t\t\t\t\t\t\tthis.pendingDirs.delete(p);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const path of children) {\n\t\t\t\t\tif (!this.refDirs.has(path)) {\n\t\t\t\t\t\tthis.refDirs.add(path);\n\t\t\t\t\t\tfound.dirs.push(path);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\treturn found;\n\t}\n\n\t/**\n\t * Reads whether core ignores each of the admin entries `ids`, from their `gitdir`; answers whether one known as\n\t * ignored no longer is, whose gate the next poll must take a reading of. A read that fails ignores nothing\n\t */\n\tprivate async readIgnored(ids: readonly string[]): Promise<boolean> {\n\t\tconst { readFile, getIgnoredWorktreeRoots } = this.options;\n\t\tif (readFile == null || getIgnoredWorktreeRoots == null || this.repoPath == null) return false;\n\n\t\tconst repoPath = this.repoPath;\n\t\tconst roots = await (this.ignoredRoots ??= getIgnoredWorktreeRoots(repoPath).catch(() => []));\n\n\t\tlet unignored = false;\n\t\tawait Promise.all(\n\t\t\tids.map(async id => {\n\t\t\t\tlet ignored = false;\n\t\t\t\tif (roots.length) {\n\t\t\t\t\tconst adminDir = joinPaths(this.basePath, 'worktrees', id);\n\t\t\t\t\tlet gitdir: Uint8Array | undefined;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tgitdir = await this.options.gate.run(this.gateKey, () =>\n\t\t\t\t\t\t\treadFile(joinPaths(adminDir, 'gitdir')),\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch {}\n\t\t\t\t\tignored = isIgnoredWorktreeEntry(adminDir, gitdir, roots) === true;\n\t\t\t\t}\n\n\t\t\t\tconst entry = this.worktrees.get(id);\n\t\t\t\tif (entry == null || entry.ignored === ignored) return;\n\n\t\t\t\tentry.ignored = ignored;\n\t\t\t\t// A new entry was reported as the move of the `worktrees` directory it appeared in\n\t\t\t\tif (!this.foundWorktrees.has(id)) {\n\t\t\t\t\tthis.flippedWorktrees.add(id);\n\t\t\t\t}\n\t\t\t\tif (ignored) {\n\t\t\t\t\tthis.gated.delete(`worktrees/${id}`);\n\t\t\t\t} else {\n\t\t\t\t\tthis.addWorktreeGated(id);\n\t\t\t\t\tunignored = true;\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\treturn unignored;\n\t}\n\n\t/** The names of the directories in `dir`; none when it isn't there, and `undefined` when it couldn't be listed */\n\tprivate async readDirectories(dir: string): Promise<string[] | undefined> {\n\t\ttry {\n\t\t\tconst entries = await this.options.gate.run(this.gateKey, () =>\n\t\t\t\tthis.options.readDirectory(joinPaths(this.basePath, dir)),\n\t\t\t);\n\t\t\treturn entries.filter(([, type]) => (type & FileType.Directory) !== 0).map(([name]) => name);\n\t\t} catch (ex) {\n\t\t\tif (isNotFound(ex) || isNotADirectory(ex)) return [];\n\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * The admin ids, not ignored, that the listings of this validation added or removed; none when all were ignored, and\n\t * `undefined` when the listings changed nothing, so what moved the `worktrees` directory is unknown\n\t */\n\tprivate getAddedOrRemovedWorktrees(): string[] | undefined {\n\t\tif (!this.foundWorktrees.size && !this.removedWorktrees.size) return undefined;\n\n\t\tconst ids: string[] = [];\n\t\tfor (const id of this.foundWorktrees) {\n\t\t\tconst entry = this.worktrees.get(id);\n\t\t\tif (entry != null && !entry.ignored) {\n\t\t\t\tids.push(id);\n\t\t\t}\n\t\t}\n\t\tfor (const [id, ignored] of this.removedWorktrees) {\n\t\t\t// One found and gone again within the validation was never reported\n\t\t\tif (!ignored && !this.foundWorktrees.has(id)) {\n\t\t\t\tids.push(id);\n\t\t\t}\n\t\t}\n\t\treturn ids;\n\t}\n\n\tprivate classify(): ValidationResult {\n\t\tconst changes = new Set<RepositoryChange>();\n\t\tconst movedWorktrees = new Set<string>();\n\t\tlet anyWorktreeMoved = false;\n\n\t\tconst add = (...kinds: RepositoryChange[]): void => {\n\t\t\tfor (const kind of kinds) {\n\t\t\t\tchanges.add(kind);\n\t\t\t}\n\t\t};\n\n\t\tfor (const probe of this.moved.values()) {\n\t\t\tif (this.kind === 'common') {\n\t\t\t\t// Nothing in an ignored worktree's admin entry is cached, nor its going\n\t\t\t\tconst entry = parseWorktreeAdminPath(probe.path);\n\t\t\t\tif (entry != null && (this.worktrees.get(entry.id)?.ignored ?? this.removedWorktrees.get(entry.id))) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const path of probe.emitAs ?? [probe.path]) {\n\t\t\t\tif (path === reftableProbePath) {\n\t\t\t\t\tif (this.kind === 'root') {\n\t\t\t\t\t\tadd('head', 'heads');\n\t\t\t\t\t} else {\n\t\t\t\t\t\tadd('heads', 'remotes', 'tags', 'stash');\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (this.kind === 'common') {\n\t\t\t\t\tif (path === 'FETCH_HEAD') {\n\t\t\t\t\t\tadd('lastFetched');\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// An admin entry added or removed, as its HEAD appearing or going would report to a watcher\n\t\t\t\t\tif (path === 'worktrees') {\n\t\t\t\t\t\tconst ids = this.getAddedOrRemovedWorktrees();\n\t\t\t\t\t\tif (ids == null) {\n\t\t\t\t\t\t\tadd('worktrees', 'worktreeHead');\n\t\t\t\t\t\t\tanyWorktreeMoved = true;\n\t\t\t\t\t\t} else if (ids.length) {\n\t\t\t\t\t\t\tadd('worktrees', 'worktreeHead');\n\t\t\t\t\t\t\tfor (const id of ids) {\n\t\t\t\t\t\t\t\tmovedWorktrees.add(id);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst match = worktreeHeadRegex.exec(path);\n\t\t\t\t\tif (match != null) {\n\t\t\t\t\t\tadd('worktrees', 'worktreeHead');\n\t\t\t\t\t\tmovedWorktrees.add(match[1]);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst kinds = classifyGitDirChange(path);\n\t\t\t\tif (kinds != null) {\n\t\t\t\t\tadd(...kinds);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// A worktree ignored or no longer: it left the worktree list or joined it, as an entry removed or added would\n\t\tfor (const id of this.flippedWorktrees) {\n\t\t\tadd('worktrees', 'worktreeHead');\n\t\t\tmovedWorktrees.add(id);\n\t\t}\n\n\t\treturn { changes: changes, movedWorktrees: anyWorktreeMoved ? undefined : movedWorktrees, noBaseline: false };\n\t}\n}\n\n/** A gate's own move reports nothing: the git dir itself, or a linked worktree's admin entry */\nfunction isGatePath(path: string): boolean {\n\tif (path === gitDirGatePath) return true;\n\n\tconst entry = parseWorktreeAdminPath(path);\n\treturn entry != null && entry.file == null;\n}\n\n/** A component of the path is a file: Node's error, or the one VS Code's file system raises */\nfunction isNotADirectory(ex: unknown): boolean {\n\tconst code = (ex as { code?: unknown } | undefined)?.code;\n\treturn code === 'ENOTDIR' || code === 'FileNotADirectory';\n}\n"],"mappings":";;;;;;;;;;;AAkBA,MAAM,aAAwB;CAAE,OAAO;CAAI,MAAM;AAAG;;;;;AA8DpD,MAAM,qBAAA;;;;;AAKN,MAAM,sBAAsB;;AAE5B,MAAM,aAAa;;;;;;;AAOnB,MAAM,sBAAsB;;;;;;;;AAQ5B,MAAM,kBAAkB;;AAExB,MAAM,oBAAoB;;;;;;;AAO1B,MAAM,oBAAoB;;AAE1B,MAAM,kBAAkB,aAAa;;AAErC,MAAM,6BAA6B;;AAEnC,MAAM,yBAAyB,KAAK,KAAK;;;;;;;AAOzC,MAAM,oBAAoB;AAC1B,MAAM,aAAa;AACnB,MAAM,sBAAsB;;AAE5B,MAAM,gBAAgB;;;;;AAKtB,MAAM,uBAAuB;AAE7B,MAAM,gBAAmC;CAAC;CAAc;CAAgB;AAAW;AACnF,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;;;;;;;;;;AAW1B,MAAM,iBAAiB;AACvB,MAAM,iCAAsC,IAAI,IAAI;CACnD;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;AACD,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cAAc;MAC/B,eAAe,IAAI,MAAM,EAAE;MAC3B;KACD;IACD;IAEA,MAAM,QAAQ,qBAAqB,IAAI;IACvC,IAAI,SAAS,MACZ,IAAI,GAAG,KAAK;GAEd;EACD;EAGA,KAAK,MAAM,MAAM,KAAK,kBAAkB;GACvC,IAAI,aAAa,cAAc;GAC/B,eAAe,IAAI,EAAE;EACtB;EAEA,OAAO;GAAW;GAAS,gBAAgB,mBAAmB,KAAA,IAAY;GAAgB,YAAY;EAAM;CAC7G;AACD;;AAGA,SAAS,WAAW,MAAuB;CAC1C,IAAI,SAAS,gBAAgB,OAAO;CAEpC,MAAM,QAAQ,uBAAuB,IAAI;CACzC,OAAO,SAAS,QAAQ,MAAM,QAAQ;AACvC;;AAGA,SAAS,gBAAgB,IAAsB;CAC9C,MAAM,OAAQ,IAAuC;CACrD,OAAO,SAAS,aAAa,SAAS;AACvC"}
@@ -0,0 +1,50 @@
1
+ import { BatchedStat } from "../../git/watching/unwatchedCacheValidator.js";
2
+ import { Worker } from "node:worker_threads";
3
+ //#region ../git-cli/src/exec/statWorkers.d.ts
4
+ /**
5
+ * `path`'s modification time (ms since the epoch) and size, read from the local file system; `undefined` when it isn't
6
+ * there, or is under a path that is a file. Rejects when the stat failed otherwise
7
+ */
8
+ export declare function statLocal(path: string): Promise<{
9
+ mtime: number;
10
+ size: number;
11
+ } | undefined>;
12
+ export interface StatWorkerPoolOptions {
13
+ /**
14
+ * Workers at most, each serving one batch at a time, hung and starting ones included; at most 4, and read as
15
+ * `UnwatchedCacheValidatorOptions.maxFsThreads` is (2 when it isn't a number, at least 1)
16
+ */
17
+ readonly maxWorkers: number;
18
+ /** How long a worker beyond the first stays idle before it's stopped. Default: 30 seconds */
19
+ readonly idleTimeoutMs?: number;
20
+ }
21
+ /**
22
+ * Worker threads that stat many paths as one call (see `UnwatchedCacheValidatorOptions.statMany`). A batch takes an
23
+ * idle running worker. When none is free, the batch is served on the calling thread, one asynchronous stat at a time,
24
+ * and, while fewer than `maxWorkers` run and none is starting, a worker is started in the background for the batches
25
+ * after it, so no read waits for a worker to start. A worker whose batch never returns (a hung mount) stays busy and
26
+ * is never handed another; one that fails or exits rejects its batch and leaves the pool, and one that does so without a
27
+ * batch rejects the next one. A busy worker keeps the process alive, as a pending file-system call does; an idle or
28
+ * starting one doesn't. One idle worker is kept; the others are stopped once idle for `idleTimeoutMs`.
29
+ */
30
+ export declare class StatWorkerPool {
31
+ private readonly workers;
32
+ private readonly maxWorkers;
33
+ private readonly idleTimeoutMs;
34
+ /** Why the last worker to fail without a batch failed, until a batch is rejected with it */
35
+ private idleFailure;
36
+ private disposed;
37
+ constructor(options: StatWorkerPoolOptions);
38
+ dispose(): void;
39
+ /** One reading per path, in order; rejects when a worker failed the batch, or once disposed. Never throws */
40
+ statMany(paths: readonly string[]): Promise<readonly BatchedStat[]>;
41
+ /** Starts a worker that answers each batch of paths it's sent with one {@link BatchedStat} per path, in order */
42
+ protected createWorker(): Worker;
43
+ private spawn;
44
+ /** Stops an idle worker once it stayed idle for {@link idleTimeoutMs}, unless it's the only idle one */
45
+ private startIdleTimer;
46
+ /** Takes `pooled` out of the pool and stops it, rejecting its batch in flight with `reason` */
47
+ private drop;
48
+ }
49
+ //#endregion
50
+ //# sourceMappingURL=statWorkers.d.ts.map