@gitkraken/core-gitlens 0.37.1 → 0.38.1

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 (116) hide show
  1. package/CHANGELOG.md +69 -1
  2. package/dist/git/cache.d.ts +128 -8
  3. package/dist/git/cache.js +425 -46
  4. package/dist/git/cache.js.map +1 -1
  5. package/dist/git/features.d.ts +1 -1
  6. package/dist/git/features.js +3 -0
  7. package/dist/git/features.js.map +1 -1
  8. package/dist/git/providers/branches.d.ts +42 -1
  9. package/dist/git/providers/diff.d.ts +17 -0
  10. package/dist/git/providers/provider.d.ts +7 -0
  11. package/dist/git/providers/shared/remotes.js +8 -4
  12. package/dist/git/providers/shared/remotes.js.map +1 -1
  13. package/dist/git/remotes/matcher.js +2 -2
  14. package/dist/git/remotes/matcher.js.map +1 -1
  15. package/dist/git/repositoryService.d.ts +16 -1
  16. package/dist/git/repositoryService.js +51 -3
  17. package/dist/git/repositoryService.js.map +1 -1
  18. package/dist/git/run.types.d.ts +1 -0
  19. package/dist/git/service.js +6 -2
  20. package/dist/git/service.js.map +1 -1
  21. package/dist/git/utils/fileStatus.utils.d.ts +5 -0
  22. package/dist/git/utils/fileStatus.utils.js +18 -1
  23. package/dist/git/utils/fileStatus.utils.js.map +1 -1
  24. package/dist/git/watching/changeEvent.d.ts +13 -3
  25. package/dist/git/watching/changeEvent.js +15 -4
  26. package/dist/git/watching/changeEvent.js.map +1 -1
  27. package/dist/git/watching/changeOrdinal.d.ts +9 -0
  28. package/dist/git/watching/changeOrdinal.js +14 -0
  29. package/dist/git/watching/changeOrdinal.js.map +1 -0
  30. package/dist/git/watching/unwatchedCacheValidator.d.ts +38 -5
  31. package/dist/git/watching/unwatchedCacheValidator.js +180 -36
  32. package/dist/git/watching/unwatchedCacheValidator.js.map +1 -1
  33. package/dist/git/watching/watchGroup.d.ts +63 -14
  34. package/dist/git/watching/watchGroup.js +213 -74
  35. package/dist/git/watching/watchGroup.js.map +1 -1
  36. package/dist/git/watching/watchService.js +4 -3
  37. package/dist/git/watching/watchService.js.map +1 -1
  38. package/dist/git/watching/watchSession.d.ts +10 -2
  39. package/dist/git/watching/watchSession.js +18 -4
  40. package/dist/git/watching/watchSession.js.map +1 -1
  41. package/dist/git/watching/watcherPatterns.d.ts +18 -4
  42. package/dist/git/watching/watcherPatterns.js +39 -8
  43. package/dist/git/watching/watcherPatterns.js.map +1 -1
  44. package/dist/git/watching/worktreeSummary.d.ts +23 -12
  45. package/dist/git/watching/worktreeSummary.js +164 -41
  46. package/dist/git/watching/worktreeSummary.js.map +1 -1
  47. package/dist/git-cli/cliGitProvider.d.ts +1 -0
  48. package/dist/git-cli/cliGitProvider.js +11 -2
  49. package/dist/git-cli/cliGitProvider.js.map +1 -1
  50. package/dist/git-cli/exec/git.d.ts +7 -2
  51. package/dist/git-cli/exec/git.js +46 -10
  52. package/dist/git-cli/exec/git.js.map +1 -1
  53. package/dist/git-cli/exec/headState.d.ts +24 -0
  54. package/dist/git-cli/exec/headState.js +46 -6
  55. package/dist/git-cli/exec/headState.js.map +1 -1
  56. package/dist/git-cli/parsers/logParser.js +6 -3
  57. package/dist/git-cli/parsers/logParser.js.map +1 -1
  58. package/dist/git-cli/providers/branches.d.ts +135 -10
  59. package/dist/git-cli/providers/branches.js +622 -80
  60. package/dist/git-cli/providers/branches.js.map +1 -1
  61. package/dist/git-cli/providers/commits.d.ts +16 -0
  62. package/dist/git-cli/providers/commits.js +80 -28
  63. package/dist/git-cli/providers/commits.js.map +1 -1
  64. package/dist/git-cli/providers/config.d.ts +10 -0
  65. package/dist/git-cli/providers/config.js +50 -12
  66. package/dist/git-cli/providers/config.js.map +1 -1
  67. package/dist/git-cli/providers/contributors.js +11 -7
  68. package/dist/git-cli/providers/contributors.js.map +1 -1
  69. package/dist/git-cli/providers/diff.d.ts +12 -0
  70. package/dist/git-cli/providers/diff.js +107 -15
  71. package/dist/git-cli/providers/diff.js.map +1 -1
  72. package/dist/git-cli/providers/graph.js +32 -25
  73. package/dist/git-cli/providers/graph.js.map +1 -1
  74. package/dist/git-cli/providers/operations.d.ts +37 -3
  75. package/dist/git-cli/providers/operations.js +124 -46
  76. package/dist/git-cli/providers/operations.js.map +1 -1
  77. package/dist/git-cli/providers/patch.js +1 -1
  78. package/dist/git-cli/providers/patch.js.map +1 -1
  79. package/dist/git-cli/providers/refs.d.ts +1 -1
  80. package/dist/git-cli/providers/refs.js +10 -11
  81. package/dist/git-cli/providers/refs.js.map +1 -1
  82. package/dist/git-cli/providers/status.d.ts +4 -5
  83. package/dist/git-cli/providers/status.js +36 -33
  84. package/dist/git-cli/providers/status.js.map +1 -1
  85. package/dist/git-cli/providers/tags.d.ts +8 -0
  86. package/dist/git-cli/providers/tags.js +53 -34
  87. package/dist/git-cli/providers/tags.js.map +1 -1
  88. package/dist/git-cli/service.d.ts +15 -0
  89. package/dist/git-cli/service.js +19 -1
  90. package/dist/git-cli/service.js.map +1 -1
  91. package/dist/plus/git-github/providers/github/diff.d.ts +1 -0
  92. package/dist/plus/git-github/providers/github/diff.js +6 -1
  93. package/dist/plus/git-github/providers/github/diff.js.map +1 -1
  94. package/dist/plus/integrations/integrationService.js +9 -0
  95. package/dist/plus/integrations/integrationService.js.map +1 -1
  96. package/dist/plus/integrations/providers/jira-server.js +1 -1
  97. package/dist/plus/integrations/providers/jira-server.js.map +1 -1
  98. package/dist/plus/integrations/providers/jira.d.ts +20 -9
  99. package/dist/plus/integrations/providers/jira.js +114 -99
  100. package/dist/plus/integrations/providers/jira.js.map +1 -1
  101. package/dist/plus/integrations/providers/linear.d.ts +11 -4
  102. package/dist/plus/integrations/providers/linear.js +75 -32
  103. package/dist/plus/integrations/providers/linear.js.map +1 -1
  104. package/dist/plus/integrations/providers/utils/discoveryCache.d.ts +35 -4
  105. package/dist/plus/integrations/providers/utils/discoveryCache.js +45 -11
  106. package/dist/plus/integrations/providers/utils/discoveryCache.js.map +1 -1
  107. package/dist/utils/env/node/exec.d.ts +8 -4
  108. package/dist/utils/env/node/exec.js +115 -9
  109. package/dist/utils/env/node/exec.js.map +1 -1
  110. package/dist/utils/holdOffMap.d.ts +23 -0
  111. package/dist/utils/holdOffMap.js +43 -0
  112. package/dist/utils/holdOffMap.js.map +1 -0
  113. package/dist/utils/promiseCache.d.ts +15 -2
  114. package/dist/utils/promiseCache.js +34 -4
  115. package/dist/utils/promiseCache.js.map +1 -1
  116. 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/** 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}\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. 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/** By the repo path of a watched worktree, what moved in its common git dir that its watcher was left to clear */\n\tprivate readonly deferred = new Map<\n\t\tstring,\n\t\t{ readonly commonPath: string; readonly changes: Set<RepositoryChange> }\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 * whatever else it 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\t// To the common path, which keys the shared entries, as `repoPath` may already be unregistered\n\t\tthis.cache.onRepositoryChanged(deferred.commonPath, deferred.changes);\n\t\t// And to a linked worktree's own entries while it is still registered, which its watcher would have cleared too\n\t\tif (repoPath !== deferred.commonPath && this.cache.isRegistered(repoPath)) {\n\t\t\tthis.cache.applyRepositoryChanges(repoPath, deferred.changes, 'share', { worktreeOnly: true });\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// 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, 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\tfor (const state of [startedRoot, startedCommon]) {\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\tprivate async runTargets(\n\t\trepoPath: string,\n\t\tcommonPath: string,\n\t\troot: TargetState | undefined,\n\t\tcommon: TargetState | undefined,\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\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] = 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]);\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(repoPath, commonPath, rootResult, commonResult, watchedAtStart);\n\t\t} catch {\n\t\t\t// `validate` never rejects, so only applying can have thrown; whatever it did apply stands\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}\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`)\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\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\t\tconst changes = new Set<RepositoryChange>(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 (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\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\tlet deferred = this.deferred.get(path);\n\t\t\t\tif (deferred?.commonPath !== commonPath) {\n\t\t\t\t\tdeferred = { commonPath: commonPath, changes: new Set() };\n\t\t\t\t\tthis.deferred.set(path, deferred);\n\t\t\t\t}\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\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.target = this.createTarget(() => this.getProbes());\n\t\t\t\tthis.gated.clear();\n\t\t\t\tthis.addGated(gitDirGatePath, this.kind === 'root' ? rootGatedProbes : commonGatedProbes);\n\t\t\t\tthis.baselined = false;\n\t\t\t\tthis.refDirs.clear();\n\t\t\t\tthis.worktrees.clear();\n\t\t\t\tthis.pendingDirs.clear();\n\t\t\t\tthis.pendingEntries.clear();\n\t\t\t\tthis.reftable = false;\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};\n\t\t}\n\n\t\treturn this.classify();\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 };\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;;;;;AA+CpD,MAAM,qBAAA;;;;;AAKN,MAAM,sBAAsB;;AAE5B,MAAM,aAAa;;AAEnB,MAAM,oBAAoB;;;;;;;AAO1B,MAAM,oBAAoB;;AAE1B,MAAM,kBAAkB,aAAa;;AAErC,MAAM,6BAA6B;;AAEnC,MAAM,yBAAyB,KAAK,KAAK;;;;;;AAMzC,MAAM,oBAAoB;AAC1B,MAAM,aAAa;AACnB,MAAM,sBAAsB;AAE5B,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,MAAM,mCAAwC,IAAI,IAAI;CAAC;CAAe;CAAU;AAAS,CAAC;AAG1F,MAAM,aAAqC,iBAAiB,QAAO,MAAK,EAAE,SAAS,OAAO;AAC1F,MAAM,mBAA2C;CAChD,EAAE,MAAM,eAAe;CACvB,GAAG,WAAW,QAAO,MAAK,CAAC,eAAe,IAAI,EAAE,IAAI,CAAC;CACrD,EAAE,MAAM,kBAAkB;AAC3B;AACA,MAAM,kBAA0C,WAAW,QAA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aAAa,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;EAAe;CAC1F;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\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":";;;;;;;;;;;AAkBA,MAAM,aAAwB;CAAE,OAAO;CAAI,MAAM;AAAG;;;;;AA+CpD,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;;;;;;AAMzC,MAAM,oBAAoB;AAC1B,MAAM,aAAa;AACnB,MAAM,sBAAsB;AAE5B,MAAM,gBAAmC;CAAC;CAAc;CAAgB;AAAW;AACnF,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;;;;;;;;;;AAW1B,MAAM,iBAAiB;AACvB,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OAAO;UAEnB,IAAI,SAAS,WAAW,QAAQ,OAAO;KAExC;IACD;IAEA,IAAI,KAAK,SAAS,UAAU;KAC3B,IAAI,SAAS,cAAc;MAC1B,IAAI,aAAa;MACjB;KACD;KAGA,IAAI,SAAS,aAAa;MACzB,MAAM,MAAM,KAAK,2BAA2B;MAC5C,IAAI,OAAO,MAAM;OAChB,IAAI,aAAa,cAAc;OAC/B,mBAAmB;MACpB,OAAO,IAAI,IAAI,QAAQ;OACtB,IAAI,aAAa,cAAc;OAC/B,KAAK,MAAM,MAAM,KAChB,eAAe,IAAI,EAAE;MAEvB;MACA;KACD;KAEA,MAAM,QAAQ,kBAAkB,KAAK,IAAI;KACzC,IAAI,SAAS,MAAM;MAClB,IAAI,aAAa,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"}
@@ -28,13 +28,13 @@ export interface WatchGroupHooks {
28
28
  }
29
29
  /**
30
30
  * Tracks one session's connection to a WatchGroup.
31
- * Each session has its own root watcher but shares the common watcher.
31
+ * Each session has its own root watcher; linked sessions share the watch of the common files.
32
32
  */
33
33
  interface SessionEntry {
34
34
  readonly repoPath: string;
35
35
  readonly gitDirPath: string;
36
36
  readonly rootWatcher: FileWatcher;
37
- /** True when the root watcher is on the common dir itself, so it already sees every common file */
37
+ /** True when the root watcher is on the common dir itself, so it sees every common file, for linked sessions too */
38
38
  readonly coversCommon: boolean;
39
39
  /** For a linked session, its `<n>` in `<common>/worktrees/<n>`; otherwise `undefined` */
40
40
  readonly worktreeId: string | undefined;
@@ -48,12 +48,14 @@ interface SessionEntry {
48
48
  * shared across all worktrees that reference it.
49
49
  *
50
50
  * Structure:
51
- * - 1 common watcher: config, refs/**, info/exclude, etc. Delivers to linked sessions only; a
52
- * session rooted at the common dir hears the same files from its own combined root watcher.
53
- * - N root watchers: one per worktree (index, HEAD, *_HEAD, etc.)
54
- *
55
- * For a standard (non-worktree) repo, the common and root directories
56
- * are the same, but we still create separate watchers for clean separation.
51
+ * - N root watchers: one per session, on its own `.git` directory (index, HEAD, *_HEAD, etc.). A session rooted at the
52
+ * common dir (a main checkout) watches it with the combined glob, so it sees every common file too (config,
53
+ * refs/**, info/exclude, etc.), and linked sessions hear those through it.
54
+ * - 1 common watcher on the common dir, for the common files only, while there are linked sessions and no session
55
+ * rooted at the common dir for them to hear those through. It delivers to linked sessions only. When one of the two
56
+ * takes the common files over from the other, the old one keeps delivering to linked sessions for a moment beside
57
+ * the new one (see {@link handOverOverlapMs}), however many hand-overs follow within it, so only once each such
58
+ * moment has passed is a single watcher left on the common dir.
57
59
  *
58
60
  * Given a `readFile`, the group keeps the shared `.git/config` as it last read it, section by section. A report of
59
61
  * that file (or its lock), from whichever watcher, is read and compared with it once, and every session hears what
@@ -85,7 +87,7 @@ interface SessionEntry {
85
87
  * when a real entry was added or removed since the last listing, and to none when only ignored ones were. Git removes
86
88
  * the directory with its last entry, so a directory that isn't there is an empty listing, as is a removal of it that
87
89
  * can't be listed. Since a listing (or a worktree moved into or out of a folder) changes what every session shows, it
88
- * is told to all of them; the other watcher's report of the same change then finds nothing left to tell. Where only a
90
+ * is told to all of them; another report of the same change (a poll's) then finds nothing left to tell. Where only a
89
91
  * poll watches the common dir, it sees just the `worktrees` directory, so an entry removed and added again under the
90
92
  * same id between two polls, or an entry's HEAD or lock changed in place, goes untold.
91
93
  *
@@ -112,6 +114,12 @@ export declare class WatchGroup implements UnifiedDisposable {
112
114
  private _commonWatcher;
113
115
  private _commonReliability;
114
116
  private _commonTarget;
117
+ /**
118
+ * The watchers on the common dir that were taken over from, each still delivering to linked sessions until its own
119
+ * overlap ends: a common watcher (with its poll, if any), or the root watcher of a session rooted at the common dir
120
+ * that went. A hand-over inside another's overlap leaves the earlier one running, since only it may be live yet
121
+ */
122
+ private readonly _retiring;
115
123
  private _disposed;
116
124
  /** The shared `.git/config`, by section, as the last read that could parse it found it */
117
125
  private _config;
@@ -169,14 +177,28 @@ export declare class WatchGroup implements UnifiedDisposable {
169
177
  /** Dispose the entire group (common watcher + all root watchers). */
170
178
  dispose(): void;
171
179
  get sessions(): ReadonlyMap<string, SessionEntry>;
172
- /** True when a watcher the session hears through — its root watcher, or a linked session's common one — can't watch */
180
+ /**
181
+ * True when a watcher the session hears through — its root watcher, or for a linked session the watch of the common
182
+ * files (see {@link getCommonReliability}) — can't watch
183
+ */
173
184
  isUnwatchable(repoPath: string): boolean;
174
185
  /** Add a session to this group. Creates the root watcher for the session's gitDir. */
175
186
  addSession(repoPath: string, gitDir: GitDir, hooks: WatchGroupHooks): void;
176
187
  /** Remove a session from this group. Disposes its root watcher. */
177
188
  removeSession(repoPath: string): void;
178
189
  private getWorktreeId;
190
+ /** `handingOver`: it takes the common files over from a session's root watcher, which tells linked sessions itself */
179
191
  private ensureCommonWatcher;
192
+ /** The common watcher keeps delivering to linked sessions until a root watcher's watch on the common dir is live */
193
+ private retireCommonWatcher;
194
+ /**
195
+ * Keeps `watcher` (and its poll) delivering to linked sessions for {@link handOverOverlapMs}, beside any earlier one
196
+ * still in its own overlap. A watcher retires once: the group never makes one current again
197
+ */
198
+ private retire;
199
+ private endRetiring;
200
+ private endAllRetiring;
201
+ private isRetiringTarget;
180
202
  private disposeCommonWatcher;
181
203
  /** Hosts that didn't opt into polling get exactly the options they always had */
182
204
  private getWatcherOptions;
@@ -188,11 +210,26 @@ export declare class WatchGroup implements UnifiedDisposable {
188
210
  private getExcludes;
189
211
  private setRootReliability;
190
212
  private setCommonReliability;
213
+ /** Polls the common dir in place of (or beside) the common watcher while it isn't `reliable` */
214
+ private setCommonPolling;
215
+ /** The watch linked sessions hear the common files through went down or came back: whatever changed meanwhile went unseen */
216
+ private tellLinkedUnwatchableChanged;
217
+ /**
218
+ * How much of the common files linked sessions hear: what the root watcher of a session rooted at the common dir
219
+ * reports while there is one (the most reliable, should there be several), the common watcher's otherwise. A watcher
220
+ * kept delivering beside the one that took over from it doesn't count: it is about to go
221
+ */
222
+ private getCommonReliability;
223
+ /**
224
+ * Linked sessions now hear the common files through another watcher than one that was `previous`. Where either isn't
225
+ * `reliable`, what changed between the two may have gone unseen (a poll's first pass only records), so each rescans,
226
+ * and hears whether the watch went down or came back
227
+ */
228
+ private handOverCommon;
191
229
  private stopPolling;
192
230
  /**
193
231
  * A session rooted at the common dir polls the common files too, with the refs of every session in the group: its
194
- * combined watcher would hear them all. While the common dir is polled too, the poller stats each shared file once
195
- * for both, and each keeps its own readings, so what one watcher reported is held back from its own sessions only
232
+ * combined watcher would hear them all, for linked sessions too
196
233
  */
197
234
  private getRootProbes;
198
235
  /**
@@ -202,9 +239,20 @@ export declare class WatchGroup implements UnifiedDisposable {
202
239
  private onLinkedHeadMoved;
203
240
  /** The common files, with the refs of every linked session (the only ones the common watcher delivers to) */
204
241
  private getCommonProbes;
242
+ /**
243
+ * An event of a watcher on the common dir that delivers to linked sessions only: the common watcher, or a root watcher
244
+ * whose session went (`sharedOnly`, since it watched that session's own files too)
245
+ */
205
246
  private onCommonEvent;
206
247
  private deliverOverflow;
207
248
  private onRootEvent;
249
+ /**
250
+ * Tells `entry`, and the linked sessions when `linked`, of a change at `relativePath`, relative to the `.git`
251
+ * directory whose watcher (or poll) reported it; `common` when that is the common dir
252
+ */
253
+ private onGitDirChanged;
254
+ /** Calls `hook` of `entry`, and of the linked sessions when `linked` */
255
+ private callHook;
208
256
  /** A report of the `worktrees` directory, an admin entry or a file in it, once the group may tell them apart */
209
257
  private isWorktreesReport;
210
258
  /** `deliver` tells the sessions the report reaches of it, should the report concern them (see above) */
@@ -224,8 +272,9 @@ export declare class WatchGroup implements UnifiedDisposable {
224
272
  private scheduleWorktreeRetry;
225
273
  /**
226
274
  * A report whose read couldn't read the entry waits on the entry's next read, and `deliver` is told then, unless that
227
- * read finds an ignored worktree's; one still unreadable is told. Both watchers report each change of an entry, so
228
- * the reports of one id wait on one read. Resolves with what it found, as {@link settleWorktreeRetry} does
275
+ * read finds an ignored worktree's; one still unreadable is told. One change of an entry can be reported more than
276
+ * once (by a watcher and a poll, or for each file it touched), so the reports of one id wait on one read. Resolves
277
+ * with what it found, as {@link settleWorktreeRetry} does
229
278
  */
230
279
  private waitForWorktreeRetry;
231
280
  /**