@gitkraken/core-gitlens 0.32.0 → 0.34.0
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.
- package/CHANGELOG.md +42 -1
- package/dist/git/cache.d.ts +121 -15
- package/dist/git/cache.js +316 -74
- package/dist/git/cache.js.map +1 -1
- package/dist/git/context.d.ts +3 -1
- package/dist/git/context.js.map +1 -1
- package/dist/git/errors.d.ts +3 -1
- package/dist/git/errors.js +4 -1
- package/dist/git/errors.js.map +1 -1
- package/dist/git/models/pullRequest.d.ts +90 -1
- package/dist/git/models/pullRequest.js +18 -2
- package/dist/git/models/pullRequest.js.map +1 -1
- package/dist/git/models/repositoryIdentities.d.ts +0 -1
- package/dist/git/models/repositoryIdentities.js +1 -4
- package/dist/git/models/repositoryIdentities.js.map +1 -1
- package/dist/git/providers/provider.d.ts +7 -0
- package/dist/git/providers/shared/remotes.js +2 -0
- package/dist/git/providers/shared/remotes.js.map +1 -1
- package/dist/git/remotes/gitlab.js +15 -9
- package/dist/git/remotes/gitlab.js.map +1 -1
- package/dist/git/service.js +4 -1
- package/dist/git/service.js.map +1 -1
- package/dist/git/utils/pullRequest.utils.d.ts +72 -1
- package/dist/git/utils/pullRequest.utils.js +99 -1
- package/dist/git/utils/pullRequest.utils.js.map +1 -1
- package/dist/git/utils/repository.utils.d.ts +16 -0
- package/dist/git/utils/repository.utils.js +37 -2
- package/dist/git/utils/repository.utils.js.map +1 -1
- package/dist/git/watching/changeEvent.d.ts +13 -3
- package/dist/git/watching/changeEvent.js +19 -4
- package/dist/git/watching/changeEvent.js.map +1 -1
- package/dist/git/watching/gitDirPoller.d.ts +10 -1
- package/dist/git/watching/gitDirPoller.js +9 -3
- package/dist/git/watching/gitDirPoller.js.map +1 -1
- package/dist/git/watching/unwatchedCacheValidator.d.ts +144 -0
- package/dist/git/watching/unwatchedCacheValidator.js +884 -0
- package/dist/git/watching/unwatchedCacheValidator.js.map +1 -0
- package/dist/git/watching/watchGroup.d.ts +6 -2
- package/dist/git/watching/watchGroup.js +35 -24
- package/dist/git/watching/watchGroup.js.map +1 -1
- package/dist/git/watching/watchService.d.ts +27 -1
- package/dist/git/watching/watchService.js +60 -17
- package/dist/git/watching/watchService.js.map +1 -1
- package/dist/git/watching/watchSession.d.ts +29 -12
- package/dist/git/watching/watchSession.js +52 -21
- package/dist/git/watching/watchSession.js.map +1 -1
- package/dist/git/watching/worktreeSummary.js +7 -7
- package/dist/git/watching/worktreeSummary.js.map +1 -1
- package/dist/git-cli/cliGitProvider.d.ts +28 -2
- package/dist/git-cli/cliGitProvider.js +63 -20
- package/dist/git-cli/cliGitProvider.js.map +1 -1
- package/dist/git-cli/exec/commandClassifier.d.ts +31 -1
- package/dist/git-cli/exec/commandClassifier.js +67 -16
- package/dist/git-cli/exec/commandClassifier.js.map +1 -1
- package/dist/git-cli/exec/git.d.ts +46 -2
- package/dist/git-cli/exec/git.js +87 -9
- package/dist/git-cli/exec/git.js.map +1 -1
- package/dist/git-cli/exec/gitDirResolver.d.ts +11 -0
- package/dist/git-cli/exec/gitDirResolver.js +34 -1
- package/dist/git-cli/exec/gitDirResolver.js.map +1 -1
- package/dist/git-cli/exec/gitQueue.js +2 -28
- package/dist/git-cli/exec/gitQueue.js.map +1 -1
- package/dist/git-cli/providers/branches.d.ts +1 -0
- package/dist/git-cli/providers/branches.js +21 -10
- package/dist/git-cli/providers/branches.js.map +1 -1
- package/dist/git-cli/providers/config.d.ts +15 -1
- package/dist/git-cli/providers/config.js +67 -22
- package/dist/git-cli/providers/config.js.map +1 -1
- package/dist/git-cli/providers/pausedOperations.d.ts +1 -0
- package/dist/git-cli/providers/pausedOperations.js +4 -0
- package/dist/git-cli/providers/pausedOperations.js.map +1 -1
- package/dist/git-cli/providers/revision.js +2 -0
- package/dist/git-cli/providers/revision.js.map +1 -1
- package/dist/git-cli/providers/worktrees.js +36 -10
- package/dist/git-cli/providers/worktrees.js.map +1 -1
- package/dist/git-cli/service.d.ts +25 -1
- package/dist/git-cli/service.js +46 -1
- package/dist/git-cli/service.js.map +1 -1
- package/dist/plus/ai/errors.d.ts +8 -2
- package/dist/plus/ai/errors.js +15 -3
- package/dist/plus/ai/errors.js.map +1 -1
- package/dist/plus/git-github/api/github.d.ts +51 -1
- package/dist/plus/git-github/api/github.js +276 -3
- package/dist/plus/git-github/api/github.js.map +1 -1
- package/dist/plus/git-github/models.d.ts +54 -1
- package/dist/plus/git-github/models.js +48 -3
- package/dist/plus/git-github/models.js.map +1 -1
- package/dist/plus/integrations/fieldPresence.d.ts +6 -1
- package/dist/plus/integrations/fieldPresence.js +19 -9
- package/dist/plus/integrations/fieldPresence.js.map +1 -1
- package/dist/plus/integrations/models/gitHostIntegration.d.ts +26 -1
- package/dist/plus/integrations/models/gitHostIntegration.js +51 -0
- package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
- package/dist/plus/integrations/models/integration.d.ts +15 -2
- package/dist/plus/integrations/models/integration.js +1 -1
- package/dist/plus/integrations/models/integration.js.map +1 -1
- package/dist/plus/integrations/providers/github.d.ts +16 -1
- package/dist/plus/integrations/providers/github.js +53 -1
- package/dist/plus/integrations/providers/github.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +10 -0
- package/dist/plus/integrations/providers/gitlab/gitlab.js +62 -15
- package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/gitlab.utils.d.ts +8 -0
- package/dist/plus/integrations/providers/gitlab/gitlab.utils.js +32 -16
- package/dist/plus/integrations/providers/gitlab/gitlab.utils.js.map +1 -1
- package/dist/plus/integrations/reads/etag.js +11 -0
- package/dist/plus/integrations/reads/etag.js.map +1 -1
- package/docs/integrations.md +39 -6
- package/package.json +1 -1
|
@@ -0,0 +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}\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uBAAuB,IAAI;CACzC,OAAO,SAAS,QAAQ,MAAM,QAAQ;AACvC;;AAGA,SAAS,gBAAgB,IAAsB;CAC9C,MAAM,OAAQ,IAAuC;CACrD,OAAO,SAAS,aAAa,SAAS;AACvC"}
|
|
@@ -14,9 +14,11 @@ export interface WatchGroupHooks {
|
|
|
14
14
|
* is unknown. `overflow` marks the every-kind rescan of a watcher that dropped events, which no single write can
|
|
15
15
|
* account for. `configBranches`, with a `config` change, are the local branches (full ref names) whose
|
|
16
16
|
* `branch.<name>` sections are all that changed in the shared `.git/config`; without it, the config change may be
|
|
17
|
-
* anywhere.
|
|
17
|
+
* anywhere. `movedWorktree`, with a `worktreeHead` change, is the admin id (the `<id>` of `worktrees/<id>`) of the
|
|
18
|
+
* linked worktree whose `HEAD` file changed, or whose admin entry was created or removed; without it, any linked
|
|
19
|
+
* worktree's HEAD may have moved.
|
|
18
20
|
*/
|
|
19
|
-
readonly onRepoChanged: (repoPath: string, changes: RepositoryChange[], ref?: string | false, overflow?: boolean, configBranches?: ReadonlySet<string
|
|
21
|
+
readonly onRepoChanged: (repoPath: string, changes: RepositoryChange[], ref?: string | false, overflow?: boolean, configBranches?: ReadonlySet<string>, movedWorktree?: string) => void;
|
|
20
22
|
readonly onFetchHeadChanged?: (repoPath: string) => void;
|
|
21
23
|
readonly onIgnoresChanged?: (repoPath: string) => void;
|
|
22
24
|
/** The refs whose loose files a poll stats for this session, read at each poll */
|
|
@@ -270,5 +272,7 @@ export declare class WatchGroup implements UnifiedDisposable {
|
|
|
270
272
|
*/
|
|
271
273
|
private deliverConfigChange;
|
|
272
274
|
}
|
|
275
|
+
/** The path doesn't exist: Node's error, or the one VS Code's file system raises */
|
|
276
|
+
export declare function isNotFound(ex: unknown): boolean;
|
|
273
277
|
//#endregion
|
|
274
278
|
//# sourceMappingURL=watchGroup.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { some } from "../../utils/iterable.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isDescendant, joinPaths, normalizePath, relative } from "../../utils/path.js";
|
|
3
|
+
import { getWorktreeAdminId, isIgnoredWorktreeEntry, parseWorktreeAdminPath } from "../utils/repository.utils.js";
|
|
3
4
|
import { FileType } from "../context.js";
|
|
4
5
|
import { GitDirProbeTarget } from "./gitDirPoller.js";
|
|
5
6
|
import { dotGitGlobCombined, dotGitGlobCommon, dotGitGlobRoot, getGitDirRefProbes, getIgnoredWorktreeFolderExcludes, gitDirCommonProbes, gitDirExcludes, gitDirProbesByEmittedPath, gitDirRootProbes, shouldIgnoreRepoPath } from "./watcherPatterns.js";
|
|
@@ -205,11 +206,7 @@ var WatchGroup = class {
|
|
|
205
206
|
if (this._commonWatcher != null && !some(this._sessions.values(), (e) => !e.coversCommon)) this.disposeCommonWatcher();
|
|
206
207
|
}
|
|
207
208
|
getWorktreeId(gitDirPath) {
|
|
208
|
-
|
|
209
|
-
const rel = relative(this.commonGitDir, gitDirPath);
|
|
210
|
-
if (!rel.startsWith("worktrees/")) return void 0;
|
|
211
|
-
const id = rel.substring(10);
|
|
212
|
-
return id.length > 0 && !id.includes("/") ? id : void 0;
|
|
209
|
+
return getWorktreeAdminId(gitDirPath, this.commonGitDir);
|
|
213
210
|
}
|
|
214
211
|
ensureCommonWatcher() {
|
|
215
212
|
if (this._commonWatcher != null || this._disposed) return;
|
|
@@ -357,17 +354,14 @@ var WatchGroup = class {
|
|
|
357
354
|
const changes = isFetchHead ? void 0 : withWorktreeEntryHead(classifyGitDirChange(relativePath), relativePath, event.reason);
|
|
358
355
|
if (changes == null && !isFetchHead && !isExclude) return;
|
|
359
356
|
const ref = changes != null ? getChangedRef(relativePath) : void 0;
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
const idEnd = relativePath.indexOf("/", 10);
|
|
363
|
-
if (idEnd !== -1 && relativePath.substring(idEnd + 1) === "HEAD") ownerId = relativePath.substring(10, idEnd);
|
|
364
|
-
}
|
|
357
|
+
const ownerId = changes != null ? getMovedWorktreeId(relativePath) : void 0;
|
|
358
|
+
const movedWorktree = getReportedWorktreeId(relativePath, changes);
|
|
365
359
|
if (changes != null && this.isWorktreesReport(changes)) {
|
|
366
360
|
const sessions = [...this._sessions.values()].filter((e) => !e.coversCommon && (ownerId == null || e.worktreeId !== ownerId));
|
|
367
361
|
this.onWorktreesReported(relativePath, event.reason, () => {
|
|
368
362
|
for (const entry of sessions) {
|
|
369
363
|
if (this._disposed || this._sessions.get(entry.repoPath) !== entry) continue;
|
|
370
|
-
|
|
364
|
+
deliverRepoChanged(entry, changes, ref, movedWorktree);
|
|
371
365
|
}
|
|
372
366
|
});
|
|
373
367
|
return;
|
|
@@ -378,7 +372,7 @@ var WatchGroup = class {
|
|
|
378
372
|
entry.hooks.onFetchHeadChanged?.(entry.repoPath);
|
|
379
373
|
continue;
|
|
380
374
|
}
|
|
381
|
-
if (changes != null && (ownerId == null || entry.worktreeId !== ownerId))
|
|
375
|
+
if (changes != null && (ownerId == null || entry.worktreeId !== ownerId)) deliverRepoChanged(entry, changes, ref, movedWorktree);
|
|
382
376
|
if (isExclude) entry.hooks.onIgnoresChanged?.(entry.repoPath);
|
|
383
377
|
}
|
|
384
378
|
}
|
|
@@ -405,11 +399,12 @@ var WatchGroup = class {
|
|
|
405
399
|
return;
|
|
406
400
|
}
|
|
407
401
|
const changes = withWorktreeEntryHead(classifyGitDirChange(relativePath), relativePath, event.reason);
|
|
402
|
+
const movedWorktree = entry.coversCommon ? getReportedWorktreeId(relativePath, changes) : void 0;
|
|
408
403
|
if (changes != null && entry.coversCommon && this.isWorktreesReport(changes)) this.onWorktreesReported(relativePath, event.reason, () => {
|
|
409
404
|
if (this._disposed || this._sessions.get(entry.repoPath) !== entry) return;
|
|
410
|
-
|
|
405
|
+
deliverRepoChanged(entry, changes, getChangedRef(relativePath), movedWorktree);
|
|
411
406
|
});
|
|
412
|
-
else if (changes != null)
|
|
407
|
+
else if (changes != null) deliverRepoChanged(entry, changes, getChangedRef(relativePath), movedWorktree);
|
|
413
408
|
if (relativePath === "info/exclude") entry.hooks.onIgnoresChanged?.(entry.repoPath);
|
|
414
409
|
}
|
|
415
410
|
/** A report of the `worktrees` directory, an admin entry or a file in it, once the group may tell them apart */
|
|
@@ -435,9 +430,12 @@ var WatchGroup = class {
|
|
|
435
430
|
this.queueWorktreesRescan(reason, deliver);
|
|
436
431
|
return;
|
|
437
432
|
}
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
433
|
+
const entry = parseWorktreeAdminPath(relativePath);
|
|
434
|
+
if (entry == null) {
|
|
435
|
+
deliver();
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
const { id, file } = entry;
|
|
441
439
|
if (reason === "delete" && (file == null || file === "gitdir")) {
|
|
442
440
|
if (this.forgetWorktreeId(id) !== true) deliver();
|
|
443
441
|
return;
|
|
@@ -581,11 +579,7 @@ var WatchGroup = class {
|
|
|
581
579
|
async readIgnoredWorktree(id) {
|
|
582
580
|
const adminDir = joinPaths(this.commonGitDir, "worktrees", id);
|
|
583
581
|
const content = await this.readWithTimeout(joinPaths(adminDir, "gitdir"));
|
|
584
|
-
|
|
585
|
-
const dotGitPath = dotGit ? normalizePath(isAbsolute(dotGit) ? dotGit : joinPaths(adminDir, dotGit)) : "";
|
|
586
|
-
if (!dotGitPath.endsWith("/.git")) return void 0;
|
|
587
|
-
const worktreePath = dirname(dotGitPath);
|
|
588
|
-
return this._ignoredWorktreeRoots.some((root) => isDescendant(worktreePath, root));
|
|
582
|
+
return isIgnoredWorktreeEntry(adminDir, content, this._ignoredWorktreeRoots);
|
|
589
583
|
}
|
|
590
584
|
queueWorktreesBaseline(take) {
|
|
591
585
|
this._worktreesBaselining = true;
|
|
@@ -766,6 +760,23 @@ function withWorktreeEntryHead(changes, relativePath, reason) {
|
|
|
766
760
|
if (idEnd === -1) return reason === "create" || reason === "delete" ? ["worktrees", "worktreeHead"] : changes;
|
|
767
761
|
return reason === "delete" && relativePath.substring(idEnd + 1) === "gitdir" ? ["worktrees", "worktreeHead"] : changes;
|
|
768
762
|
}
|
|
763
|
+
/** The admin id of the linked worktree whose `HEAD` file `relativePath` (relative to the common git dir) is */
|
|
764
|
+
function getMovedWorktreeId(relativePath) {
|
|
765
|
+
const entry = parseWorktreeAdminPath(relativePath);
|
|
766
|
+
return entry?.file === "HEAD" ? entry.id : void 0;
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* The admin id of the linked worktree a `worktreeHead` among `changes` is for: the entry `relativePath` (relative to the
|
|
770
|
+
* common git dir) is, or is a file of
|
|
771
|
+
*/
|
|
772
|
+
function getReportedWorktreeId(relativePath, changes) {
|
|
773
|
+
return changes?.includes("worktreeHead") ? parseWorktreeAdminPath(relativePath)?.id : void 0;
|
|
774
|
+
}
|
|
775
|
+
/** Tells `entry` of `changes`, naming the linked worktree whose HEAD moved only when the report knows it */
|
|
776
|
+
function deliverRepoChanged(entry, changes, ref, movedWorktree) {
|
|
777
|
+
if (movedWorktree != null) entry.hooks.onRepoChanged(entry.repoPath, changes, ref, void 0, void 0, movedWorktree);
|
|
778
|
+
else entry.hooks.onRepoChanged(entry.repoPath, changes, ref);
|
|
779
|
+
}
|
|
769
780
|
/** The path doesn't exist: Node's error, or the one VS Code's file system raises */
|
|
770
781
|
function isNotFound(ex) {
|
|
771
782
|
const code = ex?.code;
|
|
@@ -786,6 +797,6 @@ function getChangedRef(relativePath) {
|
|
|
786
797
|
return ref.startsWith("refs/") || ref === "HEAD" || ref === "ORIG_HEAD" ? ref : void 0;
|
|
787
798
|
}
|
|
788
799
|
//#endregion
|
|
789
|
-
export { WatchGroup };
|
|
800
|
+
export { WatchGroup, isNotFound };
|
|
790
801
|
|
|
791
802
|
//# sourceMappingURL=watchGroup.js.map
|