@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watchGroup.js","names":[],"sources":["../../../../git/src/watching/watchGroup.ts"],"sourcesContent":["import type { UnifiedDisposable } from '@gitlens/utils/disposable.js';\nimport { some } from '@gitlens/utils/iterable.js';\nimport { dirname, isAbsolute, isDescendant, joinPaths, normalizePath, relative } from '@gitlens/utils/path.js';\nimport { FileType } from '../context.js';\nimport type { GitDir, RepositoryChange } from '../models/repository.js';\nimport { allWatchedRepositoryChanges, classifyGitDirChange } from './classifyChange.js';\nimport type { GitConfigSections, GitConfigSectionsChange } from './configSections.js';\nimport { diffGitConfigSections, parseGitConfigBytes } from './configSections.js';\nimport type { GitDirPoller, GitDirProbe } from './gitDirPoller.js';\nimport { GitDirProbeTarget } from './gitDirPoller.js';\nimport type {\n\tFileWatcher,\n\tFileWatcherOptions,\n\tFileWatcherReliability,\n\tFileWatchEvent,\n\tFileWatchingProvider,\n} from './provider.js';\nimport {\n\tdotGitGlobCombined,\n\tdotGitGlobCommon,\n\tdotGitGlobRoot,\n\tgetGitDirRefProbes,\n\tgetIgnoredWorktreeFolderExcludes,\n\tgitDirCommonProbes,\n\tgitDirExcludes,\n\tgitDirProbesByEmittedPath,\n\tgitDirRootProbes,\n\tshouldIgnoreRepoPath,\n} from './watcherPatterns.js';\n\n/**\n * How long a read of the shared `.git/config`, or of the worktrees' admin entries, may take before it counts as failed.\n * Reads of each run one at a time, so one that never settles, as on a hung network or WSL mount, would otherwise hold\n * back every later report.\n */\nconst readTimeoutMs = 5000;\n\n/**\n * How many removed admin entries are remembered. Each watcher reports a removal once for each file it watched in the\n * entry, and two watchers see the common dir beside a main checkout, so its reports outlive any single one of them\n */\nconst removedWorktreeIdsLimit = 64;\n\n/**\n * How long after an admin entry's `gitdir` couldn't be read it is read once more. A watcher can report the entry before\n * git wrote its `gitdir`, and then miss the write itself (a new directory's files go unseen until it is watched)\n */\nconst worktreeRetryDelayMs = 250;\n\nfunction noop(): void {}\n\n/**\n * Hooks that the WatchGroup fires when events are interpreted.\n * These are raw, un-debounced events — the session handles debouncing.\n */\nexport interface WatchGroupHooks {\n\t/**\n\t * `ref` is the full ref name (or ref directory) or pseudo-ref (`HEAD`, `ORIG_HEAD`) whose file changed, with a\n\t * trailing `.lock` stripped; `false` when config changed without moving refs, and `undefined` when ref movement\n\t * is unknown. `overflow` marks the every-kind rescan of a watcher that dropped events, which no single write can\n\t * account for. `configBranches`, with a `config` change, are the local branches (full ref names) whose\n\t * `branch.<name>` sections are all that changed in the shared `.git/config`; without it, the config change may be\n\t * anywhere.\n\t */\n\treadonly onRepoChanged: (\n\t\trepoPath: string,\n\t\tchanges: RepositoryChange[],\n\t\tref?: string | false,\n\t\toverflow?: boolean,\n\t\tconfigBranches?: ReadonlySet<string>,\n\t) => void;\n\treadonly onFetchHeadChanged?: (repoPath: string) => void;\n\treadonly onIgnoresChanged?: (repoPath: string) => void;\n\t/** The refs whose loose files a poll stats for this session, read at each poll */\n\treadonly getProbeRefs?: () => Iterable<string>;\n\t/** A watcher this session hears through went `unwatchable`, or stopped being it (see {@link WatchGroup.isUnwatchable}) */\n\treadonly onUnwatchableChanged?: (repoPath: string) => void;\n}\n\n/**\n * Tracks one session's connection to a WatchGroup.\n * Each session has its own root watcher but shares the common watcher.\n */\ninterface SessionEntry {\n\treadonly repoPath: string;\n\treadonly gitDirPath: string;\n\treadonly rootWatcher: FileWatcher;\n\t/** True when the root watcher is on the common dir itself, so it already sees every common file */\n\treadonly coversCommon: boolean;\n\t/** For a linked session, its `<n>` in `<common>/worktrees/<n>`; otherwise `undefined` */\n\treadonly worktreeId: string | undefined;\n\treadonly hooks: WatchGroupHooks;\n\treliability: FileWatcherReliability;\n\t/** Polls in place of (or beside) the root watcher while it isn't `reliable` */\n\ttarget?: GitDirProbeTarget;\n}\n\n/**\n * Manages filesystem watchers for a single physical `.git` directory,\n * shared across all worktrees that reference it.\n *\n * Structure:\n * - 1 common watcher: config, refs/**, info/exclude, etc. Delivers to linked sessions only; a\n * session rooted at the common dir hears the same files from its own combined root watcher.\n * - N root watchers: one per worktree (index, HEAD, *_HEAD, etc.)\n *\n * For a standard (non-worktree) repo, the common and root directories\n * are the same, but we still create separate watchers for clean separation.\n *\n * Given a `readFile`, the group keeps the shared `.git/config` as it last read it, section by section. A report of\n * that file (or its lock), from whichever watcher, is read and compared with it once, and every session hears what\n * changed: only some branches' `branch.<name>` sections (`config`, confined to them), anything else (`config` and\n * `remotes`, unconfined), or nothing at all, when an earlier report's read already delivered the change. Reads run\n * one at a time, so each compares with the one before it and none is skipped. The first read, taken as the group\n * starts, is the baseline and delivers nothing; a report arriving before it completes may describe a change it\n * already holds, so it is delivered unconfined. A read that fails or doesn't settle within a few seconds, or a file\n * git couldn't parse, is unconfined too.\n *\n * Given a `readFile`, a `readDirectory` (a directory's entries with their types, only the directories counting as\n * admin entries) and the folders whose worktrees the host has core ignore (a tool's throwaway worktrees, which no\n * host shows), the group reports no change of an ignored worktree's admin entry\n * (`<common>/worktrees/<id>`) to any session. Only registered folders count, since a user may keep real worktrees\n * anywhere, `.git` included. It lists the entries and reads each one's `gitdir` once as it starts, and again after a\n * watcher dropped events; a report arriving meanwhile is told at once, and decided once the listing settles, so what\n * is known of its entry catches up. From then on it reads an entry only when its `gitdir` may be new (the entry was\n * created, or its `gitdir` written, or it was removed before), so a real worktree's HEAD moves are told at once,\n * unread. Of two reads of one entry, the later decides both reports. An entry it doesn't know whose `gitdir` can't be\n * read (a watcher can report one before git writes it, and miss the write) is read once more a moment later, its\n * reports held until then, and told if it still can't be. Only the entry's directory or its `gitdir` going is a\n * removal; a deleted `HEAD` (a watcher may report git's lock file renamed over it as a delete) or `locked` is told as\n * the entry is known. Removing an entry deletes the `gitdir` a read needs, so a removal is told from what the entry was\n * known to be (before a read that couldn't read it, if one is waiting to read it again), and an entry it never knew is\n * told as real. Any other report of a removed entry but a delete is read, and one that can't be read is the removal's\n * own (a watcher may report the entry's directory changed beside each file it deletes), unless it creates the entry\n * again. A report of the `worktrees` directory itself (a coalesced\n * removal, a parent directory change, a poll, which sees nothing finer) lists it again: it is told to every session\n * when a real entry was added or removed since the last listing, and to none when only ignored ones were. Git removes\n * the directory with its last entry, so a directory that isn't there is an empty listing, as is a removal of it that\n * can't be listed. Since a listing (or a worktree moved into or out of a folder) changes what every session shows, it\n * is told to all of them; the other watcher's report of the same change then finds nothing left to tell. Where only a\n * poll watches the common dir, it sees just the `worktrees` directory, so an entry removed and added again under the\n * same id between two polls, or an entry's HEAD or lock changed in place, goes untold.\n *\n * Given the folders, the watchers over the common dir leave each one unwatched, since a tool's checkout there would\n * otherwise have every directory of it watched; one that shares a top-level directory with what the `.git` watch reads\n * stays watched.\n */\nexport class WatchGroup implements UnifiedDisposable {\n\tprivate readonly _sessions = new Map<string, SessionEntry>();\n\tprivate _commonWatcher: FileWatcher | undefined;\n\tprivate _commonReliability: FileWatcherReliability = 'reliable';\n\tprivate _commonTarget: GitDirProbeTarget | undefined;\n\tprivate _disposed = false;\n\n\t/** The shared `.git/config`, by section, as the last read that could parse it found it */\n\tprivate _config: GitConfigSections | undefined;\n\t/** The baseline read is in flight */\n\tprivate _configBaselining = false;\n\tprivate _configReading = false;\n\tprivate _configRereadQueued = false;\n\n\t/**\n\t * Settles once the latest baseline of the admin entries was taken; `undefined` when the group can't tell an\n\t * ignored worktree's, so every report is told at once\n\t */\n\tprivate _worktreesBaseline: Promise<void> | undefined;\n\t/** A baseline is pending, so a report waits for it */\n\tprivate _worktreesBaselining = false;\n\tprivate _worktreesRebaselineQueued = false;\n\t/** Set by the first baseline; while empty, nothing is ignored and every report is told at once */\n\tprivate _ignoredWorktreeRoots: readonly string[] = [];\n\t/** Listings run one at a time, so each compares with the one before it */\n\tprivate _worktreesQueue: Promise<void> = Promise.resolve();\n\t/** The `worktrees` directory's reports waiting on the queued listing; `undefined` while none is queued */\n\tprivate _worktreesRescanQueued:\n\t\t| {\n\t\t\t\treadonly delivers: (() => void)[];\n\t\t\t\t/** One of them is a removal of the directory */\n\t\t\t\tremoval: boolean;\n\t\t }\n\t\t| undefined;\n\t/** The admin entries the last listing found */\n\tprivate _listedWorktreeIds: ReadonlySet<string> = new Set();\n\t/** Admin entries known to exist, by id: whether each is an ignored worktree's */\n\tprivate readonly _worktreeIds = new Map<string, boolean>();\n\t/** What removed admin entries were, by id, oldest first */\n\tprivate readonly _removedWorktreeIds = new Map<string, boolean>();\n\t/**\n\t * Each id's latest `gitdir` read, settling with what it found and what the id was known to be before it; only it\n\t * may update what is known of the id. A removal of the entry drops it\n\t */\n\tprivate readonly _worktreeReads = new Map<\n\t\tstring,\n\t\tPromise<[ignored: boolean | undefined, previous: boolean | undefined]>\n\t>();\n\t/** Admin entries whose `gitdir` couldn't be read, by id, waiting to be read once more */\n\tprivate readonly _worktreeRetries = new Map<\n\t\tstring,\n\t\t{\n\t\t\treadonly timer: ReturnType<typeof setTimeout>;\n\t\t\t/** The reports waiting on it, told unless the entry turns out to be an ignored worktree's */\n\t\t\treadonly delivers: (() => void)[];\n\t\t\t/**\n\t\t\t * What the entry was known to be before its `gitdir` couldn't be read, so a move or a removal is still told\n\t\t\t * as it was\n\t\t\t */\n\t\t\tprevious: boolean | undefined;\n\t\t\t/**\n\t\t\t * Settles with whether the entry is an ignored worktree's; `undefined` when it still can't tell, or it was\n\t\t\t * removed\n\t\t\t */\n\t\t\treadonly decided: Promise<boolean | undefined>;\n\t\t\treadonly resolve: (ignored: boolean | undefined) => void;\n\t\t}\n\t>();\n\t/** The `.git` excludes of a watcher over the common git dir, with the ignored worktrees' folders it may leave out */\n\tprivate readonly _commonGitDirExcludes: readonly string[];\n\n\tconstructor(\n\t\treadonly commonGitDir: string,\n\t\tprivate readonly provider: FileWatchingProvider,\n\t\t/** When given, a watcher that reports it can't be trusted is polled; otherwise none is asked */\n\t\tprivate readonly poller?: GitDirPoller,\n\t\t/**\n\t\t * When given, reports of the shared `.git/config` are classified by what changed in it, and admin entries are\n\t\t * read to tell an ignored worktree's (see above)\n\t\t */\n\t\tprivate readonly readFile?: (path: string) => Promise<Uint8Array>,\n\t\t/**\n\t\t * Returns a directory's entries with their types; with `readFile`, the admin entries are listed, only the\n\t\t * directories counting (see above)\n\t\t */\n\t\tprivate readonly readDirectory?: (path: string) => Promise<readonly (readonly [string, number])[]>,\n\t\t/** The absolute, normalized folders whose worktrees are ignored; none reads no admin entry */\n\t\tignoredWorktreeRoots?: Promise<readonly string[]>,\n\t\t/** The folders whose worktrees are ignored, relative to the common git dir */\n\t\tignoredWorktreeFolders?: readonly string[],\n\t) {\n\t\tconst folders = getIgnoredWorktreeFolderExcludes(ignoredWorktreeFolders);\n\t\tthis._commonGitDirExcludes = folders.length ? [...gitDirExcludes, ...folders] : gitDirExcludes;\n\t\tif (readFile != null) {\n\t\t\tvoid this.readConfigBaseline();\n\t\t}\n\t\tif (readFile != null && readDirectory != null && ignoredWorktreeRoots != null) {\n\t\t\tthis.queueWorktreesBaseline(async () => {\n\t\t\t\tconst roots = await this.withTimeout(() => Promise.resolve(ignoredWorktreeRoots));\n\t\t\t\tif (this._disposed || !Array.isArray(roots) || !roots.length) return;\n\n\t\t\t\tthis._ignoredWorktreeRoots = roots;\n\t\t\t\tawait this.listWorktrees('baseline');\n\t\t\t});\n\t\t}\n\t}\n\n\t[Symbol.dispose](): void {\n\t\tthis.dispose();\n\t}\n\n\t/** Dispose the entire group (common watcher + all root watchers). */\n\tdispose(): void {\n\t\tif (this._disposed) return;\n\n\t\tthis._disposed = true;\n\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tentry.rootWatcher.dispose();\n\t\t\tthis.stopPolling(entry);\n\t\t}\n\t\tthis._sessions.clear();\n\n\t\tthis.disposeCommonWatcher();\n\n\t\tfor (const retry of this._worktreeRetries.values()) {\n\t\t\tclearTimeout(retry.timer);\n\t\t\tretry.resolve(undefined);\n\t\t}\n\t\tthis._worktreeRetries.clear();\n\t}\n\n\tget sessions(): ReadonlyMap<string, SessionEntry> {\n\t\treturn this._sessions;\n\t}\n\n\t/** True when a watcher the session hears through — its root watcher, or a linked session's common one — can't watch */\n\tisUnwatchable(repoPath: string): boolean {\n\t\tconst entry = this._sessions.get(repoPath);\n\t\tif (entry == null) return false;\n\n\t\treturn (\n\t\t\tentry.reliability === 'unwatchable' || (!entry.coversCommon && this._commonReliability === 'unwatchable')\n\t\t);\n\t}\n\n\t/** Add a session to this group. Creates the root watcher for the session's gitDir. */\n\taddSession(repoPath: string, gitDir: GitDir, hooks: WatchGroupHooks): void {\n\t\tif (this._disposed) return;\n\t\tif (this._sessions.has(repoPath)) return; // Already tracked\n\n\t\t// Determine the glob pattern for the root watcher\n\t\tconst isStandard = gitDir.commonUri == null;\n\t\tconst rootPattern = isStandard ? dotGitGlobCombined : dotGitGlobRoot;\n\n\t\t// The watcher can report its reliability before `createWatcher` returns, so before the entry exists\n\t\tlet entry: SessionEntry | undefined;\n\t\tlet initialReliability: FileWatcherReliability = 'reliable';\n\n\t\tconst rootWatcher = this.provider.createWatcher(\n\t\t\tgitDir.uri.fsPath,\n\t\t\trootPattern,\n\t\t\t(event: FileWatchEvent) => {\n\t\t\t\tconst e = this._sessions.get(repoPath);\n\t\t\t\tif (e != null) {\n\t\t\t\t\tif (event.reason !== 'overflow') {\n\t\t\t\t\t\te.target?.forget(event.path);\n\t\t\t\t\t}\n\t\t\t\t\tthis.onRootEvent(event, e);\n\t\t\t\t}\n\t\t\t},\n\t\t\tthis.getWatcherOptions(gitDir.uri.fsPath, state => {\n\t\t\t\tif (entry == null) {\n\t\t\t\t\tinitialReliability = state;\n\t\t\t\t} else if (this._sessions.get(repoPath) === entry) {\n\t\t\t\t\tthis.setRootReliability(entry, state);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\tconst entryGitDirPath = gitDir.uri.fsPath;\n\t\tentry = {\n\t\t\trepoPath: repoPath,\n\t\t\tgitDirPath: entryGitDirPath,\n\t\t\trootWatcher: rootWatcher,\n\t\t\tcoversCommon: isStandard,\n\t\t\tworktreeId: isStandard ? undefined : this.getWorktreeId(entryGitDirPath),\n\t\t\thooks: hooks,\n\t\t\treliability: 'reliable',\n\t\t};\n\n\t\tthis._sessions.set(repoPath, entry);\n\t\tif (initialReliability !== 'reliable') {\n\t\t\tthis.setRootReliability(entry, initialReliability, true);\n\t\t}\n\n\t\t// Start the common watcher if this is a worktree repo and we haven't yet.\n\t\t// Standard repos don't need a separate common watcher because their root\n\t\t// watcher uses dotGitGlobCombined which already covers all patterns.\n\t\tif (!isStandard) {\n\t\t\tthis.ensureCommonWatcher();\n\t\t}\n\t}\n\n\t/** Remove a session from this group. Disposes its root watcher. */\n\tremoveSession(repoPath: string): void {\n\t\tconst entry = this._sessions.get(repoPath);\n\t\tif (entry == null) return;\n\n\t\tentry.rootWatcher.dispose();\n\t\tthis.stopPolling(entry);\n\t\tthis._sessions.delete(repoPath);\n\n\t\t// Once no linked session is left, dispose the common watcher — it delivers to linked sessions only\n\t\tif (this._commonWatcher != null && !some(this._sessions.values(), e => !e.coversCommon)) {\n\t\t\tthis.disposeCommonWatcher();\n\t\t}\n\t}\n\n\tprivate getWorktreeId(gitDirPath: string): string | undefined {\n\t\tif (!isDescendant(gitDirPath, this.commonGitDir)) return undefined;\n\n\t\tconst rel = relative(this.commonGitDir, gitDirPath);\n\t\tif (!rel.startsWith('worktrees/')) return undefined;\n\n\t\tconst id = rel.substring(10);\n\t\treturn id.length > 0 && !id.includes('/') ? id : undefined;\n\t}\n\n\tprivate ensureCommonWatcher(): void {\n\t\tif (this._commonWatcher != null || this._disposed) return;\n\n\t\t// The watcher can report its reliability before `createWatcher` returns\n\t\tlet watcher: FileWatcher | undefined;\n\t\tlet initialReliability: FileWatcherReliability = 'reliable';\n\t\tconst options = this.getWatcherOptions(this.commonGitDir, state => {\n\t\t\tif (watcher == null) {\n\t\t\t\tinitialReliability = state;\n\t\t\t} else if (this._commonWatcher === watcher) {\n\t\t\t\tthis.setCommonReliability(state);\n\t\t\t}\n\t\t});\n\n\t\twatcher = this.provider.createWatcher(\n\t\t\tthis.commonGitDir,\n\t\t\tdotGitGlobCommon,\n\t\t\t(event: FileWatchEvent) => {\n\t\t\t\tif (event.reason !== 'overflow') {\n\t\t\t\t\tthis._commonTarget?.forget(event.path);\n\t\t\t\t}\n\t\t\t\tthis.onCommonEvent(event);\n\t\t\t},\n\t\t\toptions,\n\t\t);\n\t\tthis._commonWatcher = watcher;\n\t\tif (initialReliability !== 'reliable') {\n\t\t\tthis.setCommonReliability(initialReliability, true);\n\t\t}\n\t}\n\n\tprivate disposeCommonWatcher(): void {\n\t\tthis._commonWatcher?.dispose();\n\t\tthis._commonWatcher = undefined;\n\t\tthis._commonReliability = 'reliable';\n\t\tif (this._commonTarget != null) {\n\t\t\tthis.poller?.delete(this._commonTarget);\n\t\t\tthis._commonTarget = undefined;\n\t\t}\n\t}\n\n\t/** Hosts that didn't opt into polling get exactly the options they always had */\n\tprivate getWatcherOptions(\n\t\tbasePath: string,\n\t\tonDidChangeReliability: (state: FileWatcherReliability) => void,\n\t): FileWatcherOptions {\n\t\tconst excludes = this.getExcludes(basePath);\n\t\treturn this.poller != null\n\t\t\t? { excludes: excludes, onDidChangeReliability: onDidChangeReliability }\n\t\t\t: { excludes: excludes };\n\t}\n\n\t/**\n\t * The ignored worktrees' folders join the `.git` excludes of a watcher over the common git dir: a tool that keeps its\n\t * throwaway checkouts inside the git dir would otherwise have each one's every directory watched, and every file it\n\t * writes reported. Every other watcher sits on a linked worktree's admin entry, which holds none of them\n\t */\n\tprivate getExcludes(basePath: string): readonly string[] {\n\t\tif (this._commonGitDirExcludes === gitDirExcludes) return gitDirExcludes;\n\n\t\treturn normalizePath(basePath) === normalizePath(this.commonGitDir)\n\t\t\t? this._commonGitDirExcludes\n\t\t\t: gitDirExcludes;\n\t}\n\n\tprivate setRootReliability(entry: SessionEntry, state: FileWatcherReliability, initial?: boolean): void {\n\t\tconst previous = entry.reliability;\n\t\tif (previous === state || this.poller == null) return;\n\n\t\tentry.reliability = state;\n\t\tif (state === 'reliable') {\n\t\t\tthis.stopPolling(entry);\n\t\t} else if (entry.target == null) {\n\t\t\tconst target = new GitDirProbeTarget(\n\t\t\t\tentry.gitDirPath,\n\t\t\t\tthis.poller,\n\t\t\t\t() => this.getRootProbes(entry),\n\t\t\t\tgitDirProbesByEmittedPath,\n\t\t\t\t(event, probe) => {\n\t\t\t\t\tif (entry.target !== target) return;\n\n\t\t\t\t\tthis.onRootEvent(event, entry);\n\t\t\t\t\tif (probe.path === 'logs/HEAD' && !entry.coversCommon) {\n\t\t\t\t\t\tthis.onLinkedHeadMoved();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\tentry.target = target;\n\t\t\tthis.poller.add(target);\n\t\t}\n\n\t\tif ((state === 'unwatchable') === (previous === 'unwatchable')) return;\n\n\t\t// The watch went down or came back: whatever changed meanwhile went unseen\n\t\tif (!initial) {\n\t\t\tthis.deliverOverflow(entry);\n\t\t\tif (entry.coversCommon) {\n\t\t\t\tthis.rebaselineWorktrees();\n\t\t\t}\n\t\t}\n\t\tentry.hooks.onUnwatchableChanged?.(entry.repoPath);\n\t}\n\n\tprivate setCommonReliability(state: FileWatcherReliability, initial?: boolean): void {\n\t\tconst previous = this._commonReliability;\n\t\tif (previous === state || this.poller == null) return;\n\n\t\tthis._commonReliability = state;\n\t\tif (state === 'reliable') {\n\t\t\tif (this._commonTarget != null) {\n\t\t\t\tthis.poller.delete(this._commonTarget);\n\t\t\t\tthis._commonTarget = undefined;\n\t\t\t}\n\t\t} else if (this._commonTarget == null) {\n\t\t\tconst target = new GitDirProbeTarget(\n\t\t\t\tthis.commonGitDir,\n\t\t\t\tthis.poller,\n\t\t\t\t() => this.getCommonProbes(),\n\t\t\t\tgitDirProbesByEmittedPath,\n\t\t\t\tevent => {\n\t\t\t\t\tif (this._commonTarget === target) {\n\t\t\t\t\t\tthis.onCommonEvent(event);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\tthis._commonTarget = target;\n\t\t\tthis.poller.add(target);\n\t\t}\n\n\t\tif ((state === 'unwatchable') === (previous === 'unwatchable')) return;\n\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (entry.coversCommon) continue;\n\n\t\t\tif (!initial) {\n\t\t\t\tthis.deliverOverflow(entry);\n\t\t\t}\n\t\t\tentry.hooks.onUnwatchableChanged?.(entry.repoPath);\n\t\t}\n\t\tif (!initial) {\n\t\t\tthis.rebaselineWorktrees();\n\t\t}\n\t}\n\n\tprivate stopPolling(entry: SessionEntry): void {\n\t\tif (entry.target == null) return;\n\n\t\tthis.poller?.delete(entry.target);\n\t\tentry.target = undefined;\n\t}\n\n\t/**\n\t * A session rooted at the common dir polls the common files too, with the refs of every session in the group: its\n\t * combined watcher would hear them all. While the common dir is polled too, the poller stats each shared file once\n\t * for both, and each keeps its own readings, so what one watcher reported is held back from its own sessions only\n\t */\n\tprivate getRootProbes(entry: SessionEntry): readonly GitDirProbe[] {\n\t\tif (!entry.coversCommon) return gitDirRootProbes;\n\n\t\tconst refs = new Set<string>();\n\t\tfor (const e of this._sessions.values()) {\n\t\t\tfor (const ref of e.hooks.getProbeRefs?.() ?? []) {\n\t\t\t\trefs.add(ref);\n\t\t\t}\n\t\t}\n\t\treturn [...gitDirRootProbes, ...gitDirCommonProbes, ...getGitDirRefProbes(refs)];\n\t}\n\n\t/**\n\t * A linked worktree's `logs/HEAD` moved — a commit or reset there, on a branch a polled session rooted at the common\n\t * dir may not probe — so each such session hears a `heads` change its combined watcher would have heard\n\t */\n\tprivate onLinkedHeadMoved(): void {\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (!entry.coversCommon || entry.target == null) continue;\n\n\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['heads']);\n\t\t}\n\t}\n\n\t/** The common files, with the refs of every linked session (the only ones the common watcher delivers to) */\n\tprivate getCommonProbes(): GitDirProbe[] {\n\t\tconst refs = new Set<string>();\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (entry.coversCommon) continue;\n\n\t\t\tfor (const ref of entry.hooks.getProbeRefs?.() ?? []) {\n\t\t\t\trefs.add(ref);\n\t\t\t}\n\t\t}\n\t\treturn [...gitDirCommonProbes, ...getGitDirRefProbes(refs)];\n\t}\n\n\tprivate onCommonEvent(event: FileWatchEvent): void {\n\t\tif (event.reason === 'overflow') {\n\t\t\tfor (const entry of this._sessions.values()) {\n\t\t\t\tif (entry.coversCommon) continue;\n\n\t\t\t\tthis.deliverOverflow(entry);\n\t\t\t}\n\t\t\tthis.rebaselineWorktrees();\n\t\t\treturn;\n\t\t}\n\n\t\t// Compute relative path from common git dir\n\t\tif (!isDescendant(event.path, this.commonGitDir)) return;\n\n\t\tconst relativePath = relative(this.commonGitDir, event.path);\n\t\tif (shouldIgnoreRepoPath(relativePath)) return;\n\n\t\tif (this.readFile != null && isConfigFile(relativePath)) {\n\t\t\tthis.onConfigReported();\n\t\t\treturn;\n\t\t}\n\n\t\tconst isFetchHead = relativePath === 'FETCH_HEAD';\n\t\tconst isExclude = relativePath === 'info/exclude';\n\t\tconst changes = isFetchHead\n\t\t\t? undefined\n\t\t\t: withWorktreeEntryHead(classifyGitDirChange(relativePath), relativePath, event.reason);\n\t\tif (changes == null && !isFetchHead && !isExclude) return;\n\n\t\tconst ref = changes != null ? getChangedRef(relativePath) : undefined;\n\n\t\t// `worktrees/<n>/HEAD`: the owner hears its own HEAD from its root watcher. Its `locked` and `gitdir` aren't in\n\t\t// the root glob, so the owner hears those only from here\n\t\tlet ownerId: string | undefined;\n\t\tif (changes != null && relativePath.length > 10 && relativePath.startsWith('worktrees/')) {\n\t\t\tconst idEnd = relativePath.indexOf('/', 10);\n\t\t\tif (idEnd !== -1 && relativePath.substring(idEnd + 1) === 'HEAD') {\n\t\t\t\townerId = relativePath.substring(10, idEnd);\n\t\t\t}\n\t\t}\n\n\t\tif (changes != null && this.isWorktreesReport(changes)) {\n\t\t\tconst sessions = [...this._sessions.values()].filter(\n\t\t\t\te => !e.coversCommon && (ownerId == null || e.worktreeId !== ownerId),\n\t\t\t);\n\t\t\tthis.onWorktreesReported(relativePath, event.reason, () => {\n\t\t\t\tfor (const entry of sessions) {\n\t\t\t\t\tif (this._disposed || this._sessions.get(entry.repoPath) !== entry) continue;\n\n\t\t\t\t\tentry.hooks.onRepoChanged(entry.repoPath, changes, ref);\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\t// A session rooted at the common dir sees every common file (hooks included) through its own\n\t\t\t// combined root watcher, so delivering here too would duplicate it\n\t\t\tif (entry.coversCommon) continue;\n\n\t\t\tif (isFetchHead) {\n\t\t\t\t// FETCH_HEAD lives in the main .git dir; each worktree updates its last-fetched state\n\t\t\t\tentry.hooks.onFetchHeadChanged?.(entry.repoPath);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (changes != null && (ownerId == null || entry.worktreeId !== ownerId)) {\n\t\t\t\tentry.hooks.onRepoChanged(entry.repoPath, changes, ref);\n\t\t\t}\n\n\t\t\tif (isExclude) {\n\t\t\t\tentry.hooks.onIgnoresChanged?.(entry.repoPath);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate deliverOverflow(entry: SessionEntry): void {\n\t\t// Every kind, no ref (ref kinds stay unnamed). Never `'unknown'` — the cache would unregister the path\n\t\tentry.hooks.onRepoChanged(entry.repoPath, [...allWatchedRepositoryChanges], undefined, true);\n\t\tentry.hooks.onFetchHeadChanged?.(entry.repoPath);\n\t\tentry.hooks.onIgnoresChanged?.(entry.repoPath);\n\t}\n\n\tprivate onRootEvent(event: FileWatchEvent, entry: SessionEntry): void {\n\t\tif (event.reason === 'overflow') {\n\t\t\tthis.deliverOverflow(entry);\n\t\t\tif (entry.coversCommon) {\n\t\t\t\tthis.rebaselineWorktrees();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (!isDescendant(event.path, entry.gitDirPath)) return;\n\n\t\tconst relativePath = relative(entry.gitDirPath, event.path);\n\t\tif (shouldIgnoreRepoPath(relativePath)) return;\n\n\t\t// Check for FETCH_HEAD before interpretation\n\t\tif (relativePath === 'FETCH_HEAD') {\n\t\t\tentry.hooks.onFetchHeadChanged?.(entry.repoPath);\n\t\t\treturn;\n\t\t}\n\n\t\t// A linked worktree's git dir isn't the common one, so no file there is the shared config\n\t\tif (entry.coversCommon && this.readFile != null && isConfigFile(relativePath)) {\n\t\t\tthis.onConfigReported();\n\t\t\treturn;\n\t\t}\n\n\t\tconst changes = withWorktreeEntryHead(classifyGitDirChange(relativePath), relativePath, event.reason);\n\t\t// A linked worktree's git dir isn't the common one, so no path there is a worktree's admin entry\n\t\tif (changes != null && entry.coversCommon && this.isWorktreesReport(changes)) {\n\t\t\tthis.onWorktreesReported(relativePath, event.reason, () => {\n\t\t\t\tif (this._disposed || this._sessions.get(entry.repoPath) !== entry) return;\n\n\t\t\t\tentry.hooks.onRepoChanged(entry.repoPath, changes, getChangedRef(relativePath));\n\t\t\t});\n\t\t} else if (changes != null) {\n\t\t\tentry.hooks.onRepoChanged(entry.repoPath, changes, getChangedRef(relativePath));\n\t\t}\n\n\t\tif (relativePath === 'info/exclude') {\n\t\t\tentry.hooks.onIgnoresChanged?.(entry.repoPath);\n\t\t}\n\t}\n\n\t/** A report of the `worktrees` directory, an admin entry or a file in it, once the group may tell them apart */\n\tprivate isWorktreesReport(changes: readonly RepositoryChange[]): boolean {\n\t\treturn (\n\t\t\tthis._worktreesBaseline != null &&\n\t\t\tchanges.includes('worktrees') &&\n\t\t\tchanges.every(c => c === 'worktrees' || c === 'worktreeHead')\n\t\t);\n\t}\n\n\t/** `deliver` tells the sessions the report reaches of it, should the report concern them (see above) */\n\tprivate onWorktreesReported(relativePath: string, reason: FileWatchEvent['reason'], deliver: () => void): void {\n\t\tif (this._worktreesBaselining && this._worktreesBaseline != null) {\n\t\t\t// The baseline may have read the entry before the change reported, so the report is told; it is still decided\n\t\t\t// once the baseline settles, so what is known of the entry catches up with it\n\t\t\tdeliver();\n\t\t\tvoid this._worktreesBaseline.then(() => this.decideWorktreesReport(relativePath, reason, noop));\n\t\t\treturn;\n\t\t}\n\n\t\tthis.decideWorktreesReport(relativePath, reason, deliver);\n\t}\n\n\tprivate decideWorktreesReport(relativePath: string, reason: FileWatchEvent['reason'], deliver: () => void): void {\n\t\tif (this._disposed) return;\n\t\tif (!this._ignoredWorktreeRoots.length) {\n\t\t\tdeliver();\n\t\t\treturn;\n\t\t}\n\n\t\tif (relativePath === 'worktrees') {\n\t\t\tthis.queueWorktreesRescan(reason, deliver);\n\t\t\treturn;\n\t\t}\n\n\t\tconst idEnd = relativePath.indexOf('/', 10);\n\t\tconst id = idEnd === -1 ? relativePath.substring(10) : relativePath.substring(10, idEnd);\n\t\tconst file = idEnd === -1 ? undefined : relativePath.substring(idEnd + 1);\n\n\t\t// Only the entry or its `gitdir` going is a removal: an unlock deletes `locked` from an entry that stays, and a\n\t\t// watcher may report git's lock file renamed over `HEAD` as `HEAD` deleted and created again\n\t\tif (reason === 'delete' && (file == null || file === 'gitdir')) {\n\t\t\tif (this.forgetWorktreeId(id) !== true) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// What a removed entry was decides the removal's other reports. Any other report of its id is read: one that finds\n\t\t// the entry is of an entry created again, which may be another worktree's. One that can't is the removal's own\n\t\t// unless it creates the entry, since a watcher may report the entry's directory changed beside each file the\n\t\t// removal deletes\n\t\tconst removed = this._worktreeIds.has(id) ? undefined : this._removedWorktreeIds.get(id);\n\t\tconst known = this._worktreeIds.get(id) ?? (reason === 'delete' ? removed : undefined);\n\t\t// Only a new entry or a written `gitdir` can name another worktree; anything else is told as the id is known\n\t\tif (known != null && file !== 'gitdir' && !(file == null && reason === 'create')) {\n\t\t\tif (!known) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst retry = removed == null || reason === 'create';\n\t\tvoid this.readWorktreeId(id, retry).then(([ignored, previous]) => {\n\t\t\tif (this._disposed) return;\n\n\t\t\tif (ignored == null) {\n\t\t\t\tif (retry) {\n\t\t\t\t\tvoid this.waitForWorktreeRetry(id, deliver);\n\t\t\t\t} else if (removed === false) {\n\t\t\t\t\tdeliver();\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Moved into or out of an ignored folder: every session's list gained or lost it\n\t\t\tif (previous != null && ignored !== previous) {\n\t\t\t\tthis.deliverWorktreesChange();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!ignored) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Reads the entry's `gitdir`: whether it names an ignored worktree (`undefined` when it can't be read), and what the\n\t * id was known to be when this read replaced it. Reads of one id can settle out of order (a slow one from before the\n\t * worktree moved out of the folder), so only the latest updates what is known of it; an earlier one settles with\n\t * what the latest finds, without what the id was, since the latest tells a move itself, or once the entry was removed\n\t * since, with what the removal found it was. One that can't read the entry forgets what it was known to be, since git\n\t * may be writing its `gitdir` again, and reads it once more a moment later, unless `retry` is false (it then leaves\n\t * what is known as it was); one that can settles that read, if pending.\n\t */\n\tprivate readWorktreeId(\n\t\tid: string,\n\t\tretry: boolean = true,\n\t): Promise<[ignored: boolean | undefined, previous: boolean | undefined]> {\n\t\tconst read: Promise<[ignored: boolean | undefined, previous: boolean | undefined]> = this.readIgnoredWorktree(\n\t\t\tid,\n\t\t).then(ignored => {\n\t\t\tconst latest = this._worktreeReads.get(id);\n\t\t\tif (latest !== read) {\n\t\t\t\tif (latest == null) return [this._removedWorktreeIds.get(id), undefined];\n\n\t\t\t\treturn latest.then(([found]): [boolean | undefined, undefined] => {\n\t\t\t\t\t// A later read that couldn't read the entry may not read it again, but this one's report may be of\n\t\t\t\t\t// the entry created again, unless it was removed since\n\t\t\t\t\tif (found == null && retry && this._worktreeReads.has(id)) {\n\t\t\t\t\t\tthis.scheduleWorktreeRetry(id, undefined);\n\t\t\t\t\t}\n\t\t\t\t\treturn [found, undefined];\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst previous = this._worktreeIds.get(id);\n\t\t\tif (ignored == null) {\n\t\t\t\tif (!retry) return [undefined, previous];\n\n\t\t\t\tthis._removedWorktreeIds.delete(id);\n\t\t\t\tthis._worktreeIds.delete(id);\n\t\t\t\tthis.scheduleWorktreeRetry(id, previous);\n\t\t\t\treturn [undefined, previous];\n\t\t\t}\n\n\t\t\tthis._removedWorktreeIds.delete(id);\n\t\t\tthis._worktreeIds.set(id, ignored);\n\t\t\tthis.settleWorktreeRetry(id, ignored);\n\t\t\treturn [ignored, previous];\n\t\t});\n\t\tthis._worktreeReads.set(id, read);\n\t\treturn read;\n\t}\n\n\t/** Reads the entry once more a moment later, unless that is already pending; `previous` is what it was known to be */\n\tprivate scheduleWorktreeRetry(id: string, previous: boolean | undefined): void {\n\t\tif (this._disposed) return;\n\n\t\tconst pending = this._worktreeRetries.get(id);\n\t\tif (pending != null) {\n\t\t\tpending.previous ??= previous;\n\t\t\treturn;\n\t\t}\n\n\t\tlet resolve!: (ignored: boolean | undefined) => void;\n\t\tconst decided = new Promise<boolean | undefined>(r => {\n\t\t\tresolve = r;\n\t\t});\n\t\tconst timer = setTimeout(() => {\n\t\t\tvoid this.readWorktreeId(id).then(([ignored]) => {\n\t\t\t\t// A removal, or a later read that could read the entry, may have settled it meanwhile\n\t\t\t\tif (this._worktreeRetries.get(id)?.decided === decided) {\n\t\t\t\t\tthis.settleWorktreeRetry(id, ignored);\n\t\t\t\t}\n\t\t\t});\n\t\t}, worktreeRetryDelayMs);\n\t\tthis._worktreeRetries.set(id, {\n\t\t\ttimer: timer,\n\t\t\tdelivers: [],\n\t\t\tprevious: previous,\n\t\t\tdecided: decided,\n\t\t\tresolve: resolve,\n\t\t});\n\t}\n\n\t/**\n\t * A report whose read couldn't read the entry waits on the entry's next read, and `deliver` is told then, unless that\n\t * read finds an ignored worktree's; one still unreadable is told. Both watchers report each change of an entry, so\n\t * the reports of one id wait on one read. Resolves with what it found, as {@link settleWorktreeRetry} does\n\t */\n\tprivate waitForWorktreeRetry(id: string, deliver?: () => void): Promise<boolean | undefined> {\n\t\t// A later read may already have found what the entry is\n\t\tconst known = this._worktreeIds.get(id);\n\t\tif (known != null) {\n\t\t\tif (!known) {\n\t\t\t\tdeliver?.();\n\t\t\t}\n\t\t\treturn Promise.resolve(known);\n\t\t}\n\n\t\t// None is pending only when the entry was removed since, and the removal is told itself\n\t\tconst retry = this._worktreeRetries.get(id);\n\t\tif (retry == null) return Promise.resolve(undefined);\n\n\t\tif (deliver != null) {\n\t\t\tretry.delivers.push(deliver);\n\t\t}\n\t\treturn retry.decided;\n\t}\n\n\t/**\n\t * Tells the reports waiting on the id's retry what the entry turned out to be: nothing when an ignored worktree's,\n\t * every session when it moved into or out of an ignored folder, and the reports' own sessions otherwise, `ignored`\n\t * being `undefined` when it still couldn't be read\n\t */\n\tprivate settleWorktreeRetry(id: string, ignored: boolean | undefined): void {\n\t\tconst pending = this._worktreeRetries.get(id);\n\t\tif (pending == null) return;\n\n\t\tthis._worktreeRetries.delete(id);\n\t\tclearTimeout(pending.timer);\n\t\t// Settled before any session is told: a listing waits on it, and a hook that throws would otherwise hold back\n\t\t// every later listing for good\n\t\tpending.resolve(ignored);\n\t\tif (ignored != null && pending.previous != null && ignored !== pending.previous) {\n\t\t\tthis.deliverWorktreesChange();\n\t\t} else if (ignored !== true) {\n\t\t\tfor (const deliver of pending.delivers) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Takes `id` as removed, remembering what it was for the removal's other reports; returns that, or `undefined` when\n\t * the id was never known\n\t */\n\tprivate forgetWorktreeId(id: string): boolean | undefined {\n\t\t// A read still in flight read the entry before it went, and would bring the removed id back as known\n\t\tthis._worktreeReads.delete(id);\n\n\t\tlet ignored = this._worktreeIds.get(id);\n\t\t// The reports waiting to read the entry again are dropped: the removal is told for what the id was, which only\n\t\t// the retry still knows once a read couldn't read the entry\n\t\tconst retry = this._worktreeRetries.get(id);\n\t\tif (retry != null) {\n\t\t\tthis._worktreeRetries.delete(id);\n\t\t\tclearTimeout(retry.timer);\n\t\t\tretry.resolve(undefined);\n\t\t\tignored ??= retry.previous;\n\t\t}\n\n\t\tif (ignored == null) return this._removedWorktreeIds.get(id);\n\n\t\tthis._worktreeIds.delete(id);\n\t\tthis._removedWorktreeIds.delete(id);\n\t\tthis._removedWorktreeIds.set(id, ignored);\n\t\tif (this._removedWorktreeIds.size > removedWorktreeIdsLimit) {\n\t\t\tconst [oldest] = this._removedWorktreeIds.keys();\n\t\t\tthis._removedWorktreeIds.delete(oldest);\n\t\t}\n\t\treturn ignored;\n\t}\n\n\t/** Whether the entry's `gitdir` names an ignored worktree, or `undefined` when it can't be read. Never rejects */\n\tprivate async readIgnoredWorktree(id: string): Promise<boolean | undefined> {\n\t\tconst adminDir = joinPaths(this.commonGitDir, 'worktrees', id);\n\t\tconst content = await this.readWithTimeout(joinPaths(adminDir, 'gitdir'));\n\t\t// Git writes the path of the worktree's `.git` file, relative to the entry under `worktree.useRelativePaths`\n\t\tconst dotGit = content != null ? new TextDecoder().decode(content).trim() : '';\n\t\tconst dotGitPath = dotGit ? normalizePath(isAbsolute(dotGit) ? dotGit : joinPaths(adminDir, dotGit)) : '';\n\t\tif (!dotGitPath.endsWith('/.git')) return undefined;\n\n\t\tconst worktreePath = dirname(dotGitPath);\n\t\treturn this._ignoredWorktreeRoots.some(root => isDescendant(worktreePath, root));\n\t}\n\n\tprivate queueWorktreesBaseline(take: () => Promise<void>): void {\n\t\tthis._worktreesBaselining = true;\n\t\tconst baseline: Promise<void> = this._worktreesQueue\n\t\t\t.then(take)\n\t\t\t.catch(() => {})\n\t\t\t.finally(() => {\n\t\t\t\tif (this._worktreesBaseline === baseline) {\n\t\t\t\t\tthis._worktreesBaselining = false;\n\t\t\t\t}\n\t\t\t});\n\t\tthis._worktreesBaseline = baseline;\n\t\tthis._worktreesQueue = baseline;\n\t}\n\n\t/** A watcher of the `worktrees` directory dropped events: whatever changed meanwhile went unseen */\n\tprivate rebaselineWorktrees(): void {\n\t\tif (this._worktreesBaseline == null || this._worktreesRebaselineQueued || this._disposed) return;\n\t\t// The first baseline found no folder to ignore, and none is asked for again, so there is nothing to retake\n\t\tif (!this._worktreesBaselining && !this._ignoredWorktreeRoots.length) return;\n\n\t\tthis._worktreesRebaselineQueued = true;\n\t\tthis.queueWorktreesBaseline(async () => {\n\t\t\tthis._worktreesRebaselineQueued = false;\n\t\t\tif (this._disposed || !this._ignoredWorktreeRoots.length) return;\n\n\t\t\tawait this.listWorktrees('rebaseline');\n\t\t});\n\t}\n\n\t/** The watchers' reports of the directory pile onto one queued listing, which tells them apart */\n\tprivate queueWorktreesRescan(reason: FileWatchEvent['reason'], deliver: () => void): void {\n\t\tconst queued = this._worktreesRescanQueued;\n\t\tif (queued != null) {\n\t\t\tqueued.delivers.push(deliver);\n\t\t\tqueued.removal ||= reason === 'delete';\n\t\t\treturn;\n\t\t}\n\n\t\tconst rescan = { delivers: [deliver], removal: reason === 'delete' };\n\t\tthis._worktreesRescanQueued = rescan;\n\t\tthis._worktreesQueue = this._worktreesQueue\n\t\t\t.then(() => {\n\t\t\t\tthis._worktreesRescanQueued = undefined;\n\t\t\t\treturn this.listWorktrees('rescan', rescan.delivers, rescan.removal);\n\t\t\t})\n\t\t\t.catch(() => {});\n\t}\n\n\t/**\n\t * Lists the admin entries and compares them with the last listing. A baseline (or a rebaseline, after a watcher\n\t * dropped events) reads every entry; a rescan only those it doesn't know, reading one it can't read once more a\n\t * moment later. Git removes the directory with its last entry, so a directory that isn't there is an empty listing,\n\t * whatever the reports said of it (a poll sees its removal as a change). A listing that fails otherwise is a\n\t * baseline's empty directory, and a rescan's too when one of its reports (`delivers`) removed the directory. For any\n\t * other rescan, it is a change it can't rule out, told to the reports' own sessions\n\t */\n\tprivate async listWorktrees(\n\t\tmode: 'baseline' | 'rebaseline' | 'rescan',\n\t\tdelivers?: readonly (() => void)[],\n\t\tremoval?: boolean,\n\t): Promise<void> {\n\t\tconst readDirectory = this.readDirectory;\n\t\tif (readDirectory == null) return;\n\n\t\tconst entries = await this.withTimeout(() =>\n\t\t\treadDirectory(joinPaths(this.commonGitDir, 'worktrees')).catch((ex: unknown) => {\n\t\t\t\tif (isNotFound(ex)) return [];\n\n\t\t\t\tthrow ex;\n\t\t\t}),\n\t\t);\n\t\tif (this._disposed) return;\n\n\t\t// An admin entry is a directory, so a stray file such as `.DS_Store` is none\n\t\tconst names = entries?.filter(([, type]) => type & FileType.Directory).map(([name]) => name);\n\n\t\tif (names == null && mode === 'rescan' && !removal) {\n\t\t\tfor (const deliver of delivers ?? []) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst listing = new Set(names);\n\t\tconst previous = this._listedWorktreeIds;\n\t\tthis._listedWorktreeIds = listing;\n\n\t\tlet changed = false;\n\t\tif (mode !== 'baseline') {\n\t\t\t// An entry known only from its own reports since the last listing may be gone too\n\t\t\tfor (const id of new Set([...previous, ...this._worktreeIds.keys()])) {\n\t\t\t\tif (listing.has(id)) continue;\n\n\t\t\t\tif (this.forgetWorktreeId(id) !== true) {\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst reads = await Promise.all(\n\t\t\t[...listing]\n\t\t\t\t.filter(id => mode !== 'rescan' || (!previous.has(id) && !this._worktreeIds.has(id)))\n\t\t\t\t.map(async id => {\n\t\t\t\t\tconst [ignored, known] = await this.readWorktreeId(id);\n\t\t\t\t\tif (ignored != null || mode !== 'rescan' || this._disposed) return [id, [ignored, known]] as const;\n\n\t\t\t\t\t// An entry listed before its `gitdir` is written won't be listed as new again\n\t\t\t\t\treturn [id, [await this.waitForWorktreeRetry(id), undefined]] as const;\n\t\t\t\t}),\n\t\t);\n\t\tif (this._disposed || mode === 'baseline') return;\n\n\t\tconst read = new Map(reads);\n\t\tfor (const id of listing) {\n\t\t\tconst result = read.get(id);\n\t\t\tif (!previous.has(id)) {\n\t\t\t\t// An entry whose `gitdir` still can't be read counts as real\n\t\t\t\tif ((result != null ? result[0] : this._worktreeIds.get(id)) !== true) {\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t} else if (result?.[0] != null && result[1] != null && result[0] !== result[1]) {\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t}\n\n\t\tif (changed) {\n\t\t\tthis.deliverWorktreesChange();\n\t\t}\n\t}\n\n\tprivate deliverWorktreesChange(): void {\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['worktrees', 'worktreeHead'], undefined);\n\t\t}\n\t}\n\n\tprivate onConfigReported(): void {\n\t\t// The baseline may already hold the change reported, which comparing with it would lose\n\t\tif (this._configBaselining) {\n\t\t\tthis.deliverConfigChange(undefined);\n\t\t\treturn;\n\t\t}\n\t\tif (this._configReading) {\n\t\t\tthis._configRereadQueued = true;\n\t\t\treturn;\n\t\t}\n\n\t\tvoid this.readConfigChanges();\n\t}\n\n\tprivate async readConfigBaseline(): Promise<void> {\n\t\tthis._configBaselining = true;\n\t\tthis._configReading = true;\n\t\ttry {\n\t\t\tconst config = await this.readConfig();\n\t\t\tif (this._disposed) return;\n\n\t\t\tthis._config = config;\n\t\t} finally {\n\t\t\tthis._configBaselining = false;\n\t\t\tthis._configReading = false;\n\t\t}\n\t}\n\n\t/** Reads and compares until no report came in during the last read: it may describe a change the read missed */\n\tprivate async readConfigChanges(): Promise<void> {\n\t\tthis._configReading = true;\n\t\ttry {\n\t\t\tdo {\n\t\t\t\tthis._configRereadQueued = false;\n\t\t\t\tconst config = await this.readConfig();\n\t\t\t\tif (this._disposed) return;\n\n\t\t\t\tconst previous = this._config;\n\t\t\t\tif (config == null || previous == null) {\n\t\t\t\t\t// Unreadable now, or never readable before: the change may be anywhere. A failed read keeps the last\n\t\t\t\t\t// snapshot, so the next read still compares with what every session was told\n\t\t\t\t\tthis._config ??= config;\n\t\t\t\t\tthis.deliverConfigChange(undefined);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tthis._config = config;\n\t\t\t\tconst change = diffGitConfigSections(previous, config);\n\t\t\t\tif (change != null) {\n\t\t\t\t\tthis.deliverConfigChange(change);\n\t\t\t\t}\n\t\t\t} while (this._configRereadQueued);\n\t\t} finally {\n\t\t\tthis._configReading = false;\n\t\t}\n\t}\n\n\t/** `undefined` when the file couldn't be read or parsed, or the read didn't settle in time */\n\tprivate async readConfig(): Promise<GitConfigSections | undefined> {\n\t\tconst data = await this.readWithTimeout(joinPaths(this.commonGitDir, 'config'));\n\t\ttry {\n\t\t\treturn data != null ? parseGitConfigBytes(data) : undefined;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/** `undefined` when the file couldn't be read, or the read didn't settle in time */\n\tprivate readWithTimeout(path: string): Promise<Uint8Array | undefined> {\n\t\tconst readFile = this.readFile;\n\t\tif (readFile == null) return Promise.resolve(undefined);\n\n\t\treturn this.withTimeout(() => readFile(path));\n\t}\n\n\t/** `undefined` when `read` rejects, or doesn't settle in time */\n\tprivate async withTimeout<T>(read: () => Promise<T>): Promise<T | undefined> {\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\ttry {\n\t\t\treturn await Promise.race([\n\t\t\t\tread(),\n\t\t\t\tnew Promise<undefined>(resolve => {\n\t\t\t\t\ttimer = setTimeout(resolve, readTimeoutMs, undefined);\n\t\t\t\t}),\n\t\t\t]);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t}\n\n\t/**\n\t * Tells every session of a change to the shared `.git/config`: confined to some branches' sections, or (`undefined`,\n\t * or a change outside them) anywhere, which may have changed a remote's settings too. Either way no ref moved\n\t */\n\tprivate deliverConfigChange(change: GitConfigSectionsChange | undefined): void {\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (change?.confined) {\n\t\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['config'], false, false, change.branches);\n\t\t\t} else {\n\t\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['config', 'remotes'], false);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * `changes` with `worktreeHead` for a report that can stand for an entry's HEAD created or deleted with it: the\n * `worktrees` directory, an entry created or deleted, or its `gitdir` deleted. A watcher may coalesce the subtree a\n * removal deletes into one report of its parent, so no report of the HEAD comes. An entry's directory merely changed\n * stays `worktrees` alone: a watcher may report it beside each file in it, a lock's `locked` included\n */\nfunction withWorktreeEntryHead(\n\tchanges: RepositoryChange[] | undefined,\n\trelativePath: string,\n\treason: FileWatchEvent['reason'],\n): RepositoryChange[] | undefined {\n\tif (changes?.length !== 1 || changes[0] !== 'worktrees') return changes;\n\tif (relativePath === 'worktrees') return ['worktrees', 'worktreeHead'];\n\n\tconst idEnd = relativePath.indexOf('/', 10);\n\tif (idEnd === -1) return reason === 'create' || reason === 'delete' ? ['worktrees', 'worktreeHead'] : changes;\n\n\treturn reason === 'delete' && relativePath.substring(idEnd + 1) === 'gitdir'\n\t\t? ['worktrees', 'worktreeHead']\n\t\t: changes;\n}\n\n/** The path doesn't exist: Node's error, or the one VS Code's file system raises */\nfunction isNotFound(ex: unknown): boolean {\n\tconst code = (ex as { code?: unknown } | undefined)?.code;\n\treturn code === 'ENOENT' || code === 'FileNotFound';\n}\n\n/** The shared `.git/config` (or the lock git writes it through), relative to the common git dir */\nfunction isConfigFile(relativePath: string): boolean {\n\treturn relativePath === 'config' || relativePath === 'config.lock';\n}\n\n/**\n * The ref a `.git`-relative path names: a loose ref (or ref directory) under `refs/`, or the `HEAD`/`ORIG_HEAD`\n * pseudo-refs. A lock file names the ref it locks; the only ones classification lets through are the pseudo-refs' and\n * `refs/stash.lock`.\n */\nfunction getChangedRef(relativePath: string): string | false | undefined {\n\tconst ref = relativePath.endsWith('.lock') ? relativePath.substring(0, relativePath.length - 5) : relativePath;\n\t// Remote config still invalidates remote and branch caches, but doesn't itself move any ref.\n\tif (ref === 'config' || ref === 'config.worktree') return false;\n\n\treturn ref.startsWith('refs/') || ref === 'HEAD' || ref === 'ORIG_HEAD' ? ref : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;AAmCA,MAAM,gBAAgB;;;;;AAMtB,MAAM,0BAA0B;;;;;AAMhC,M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Ac,IAC5B;AACJ;;AAGA,SAAS,WAAW,IAAsB;CACzC,MAAM,OAAQ,IAAuC;CACrD,OAAO,SAAS,YAAY,SAAS;AACtC;;AAGA,SAAS,aAAa,cAA+B;CACpD,OAAO,iBAAiB,YAAY,iBAAiB;AACtD;;;;;;AAOA,SAAS,cAAc,cAAkD;CACxE,MAAM,MAAM,aAAa,SAAS,OAAO,IAAI,aAAa,UAAU,GAAG,aAAa,SAAS,CAAC,IAAI;CAElG,IAAI,QAAQ,YAAY,QAAQ,mBAAmB,OAAO;CAE1D,OAAO,IAAI,WAAW,OAAO,KAAK,QAAQ,UAAU,QAAQ,cAAc,MAAM,KAAA;AACjF"}
|
|
1
|
+
{"version":3,"file":"watchGroup.js","names":[],"sources":["../../../../git/src/watching/watchGroup.ts"],"sourcesContent":["import type { UnifiedDisposable } from '@gitlens/utils/disposable.js';\nimport { some } from '@gitlens/utils/iterable.js';\nimport { isDescendant, joinPaths, normalizePath, relative } from '@gitlens/utils/path.js';\nimport { FileType } from '../context.js';\nimport type { GitDir, RepositoryChange } from '../models/repository.js';\nimport { getWorktreeAdminId, isIgnoredWorktreeEntry, parseWorktreeAdminPath } from '../utils/repository.utils.js';\nimport { allWatchedRepositoryChanges, classifyGitDirChange } from './classifyChange.js';\nimport type { GitConfigSections, GitConfigSectionsChange } from './configSections.js';\nimport { diffGitConfigSections, parseGitConfigBytes } from './configSections.js';\nimport type { GitDirPoller, GitDirProbe } from './gitDirPoller.js';\nimport { GitDirProbeTarget } from './gitDirPoller.js';\nimport type {\n\tFileWatcher,\n\tFileWatcherOptions,\n\tFileWatcherReliability,\n\tFileWatchEvent,\n\tFileWatchingProvider,\n} from './provider.js';\nimport {\n\tdotGitGlobCombined,\n\tdotGitGlobCommon,\n\tdotGitGlobRoot,\n\tgetGitDirRefProbes,\n\tgetIgnoredWorktreeFolderExcludes,\n\tgitDirCommonProbes,\n\tgitDirExcludes,\n\tgitDirProbesByEmittedPath,\n\tgitDirRootProbes,\n\tshouldIgnoreRepoPath,\n} from './watcherPatterns.js';\n\n/**\n * How long a read of the shared `.git/config`, or of the worktrees' admin entries, may take before it counts as failed.\n * Reads of each run one at a time, so one that never settles, as on a hung network or WSL mount, would otherwise hold\n * back every later report.\n */\nconst readTimeoutMs = 5000;\n\n/**\n * How many removed admin entries are remembered. Each watcher reports a removal once for each file it watched in the\n * entry, and two watchers see the common dir beside a main checkout, so its reports outlive any single one of them\n */\nconst removedWorktreeIdsLimit = 64;\n\n/**\n * How long after an admin entry's `gitdir` couldn't be read it is read once more. A watcher can report the entry before\n * git wrote its `gitdir`, and then miss the write itself (a new directory's files go unseen until it is watched)\n */\nconst worktreeRetryDelayMs = 250;\n\nfunction noop(): void {}\n\n/**\n * Hooks that the WatchGroup fires when events are interpreted.\n * These are raw, un-debounced events — the session handles debouncing.\n */\nexport interface WatchGroupHooks {\n\t/**\n\t * `ref` is the full ref name (or ref directory) or pseudo-ref (`HEAD`, `ORIG_HEAD`) whose file changed, with a\n\t * trailing `.lock` stripped; `false` when config changed without moving refs, and `undefined` when ref movement\n\t * is unknown. `overflow` marks the every-kind rescan of a watcher that dropped events, which no single write can\n\t * account for. `configBranches`, with a `config` change, are the local branches (full ref names) whose\n\t * `branch.<name>` sections are all that changed in the shared `.git/config`; without it, the config change may be\n\t * anywhere. `movedWorktree`, with a `worktreeHead` change, is the admin id (the `<id>` of `worktrees/<id>`) of the\n\t * linked worktree whose `HEAD` file changed, or whose admin entry was created or removed; without it, any linked\n\t * worktree's HEAD may have moved.\n\t */\n\treadonly onRepoChanged: (\n\t\trepoPath: string,\n\t\tchanges: RepositoryChange[],\n\t\tref?: string | false,\n\t\toverflow?: boolean,\n\t\tconfigBranches?: ReadonlySet<string>,\n\t\tmovedWorktree?: string,\n\t) => void;\n\treadonly onFetchHeadChanged?: (repoPath: string) => void;\n\treadonly onIgnoresChanged?: (repoPath: string) => void;\n\t/** The refs whose loose files a poll stats for this session, read at each poll */\n\treadonly getProbeRefs?: () => Iterable<string>;\n\t/** A watcher this session hears through went `unwatchable`, or stopped being it (see {@link WatchGroup.isUnwatchable}) */\n\treadonly onUnwatchableChanged?: (repoPath: string) => void;\n}\n\n/**\n * Tracks one session's connection to a WatchGroup.\n * Each session has its own root watcher but shares the common watcher.\n */\ninterface SessionEntry {\n\treadonly repoPath: string;\n\treadonly gitDirPath: string;\n\treadonly rootWatcher: FileWatcher;\n\t/** True when the root watcher is on the common dir itself, so it already sees every common file */\n\treadonly coversCommon: boolean;\n\t/** For a linked session, its `<n>` in `<common>/worktrees/<n>`; otherwise `undefined` */\n\treadonly worktreeId: string | undefined;\n\treadonly hooks: WatchGroupHooks;\n\treliability: FileWatcherReliability;\n\t/** Polls in place of (or beside) the root watcher while it isn't `reliable` */\n\ttarget?: GitDirProbeTarget;\n}\n\n/**\n * Manages filesystem watchers for a single physical `.git` directory,\n * shared across all worktrees that reference it.\n *\n * Structure:\n * - 1 common watcher: config, refs/**, info/exclude, etc. Delivers to linked sessions only; a\n * session rooted at the common dir hears the same files from its own combined root watcher.\n * - N root watchers: one per worktree (index, HEAD, *_HEAD, etc.)\n *\n * For a standard (non-worktree) repo, the common and root directories\n * are the same, but we still create separate watchers for clean separation.\n *\n * Given a `readFile`, the group keeps the shared `.git/config` as it last read it, section by section. A report of\n * that file (or its lock), from whichever watcher, is read and compared with it once, and every session hears what\n * changed: only some branches' `branch.<name>` sections (`config`, confined to them), anything else (`config` and\n * `remotes`, unconfined), or nothing at all, when an earlier report's read already delivered the change. Reads run\n * one at a time, so each compares with the one before it and none is skipped. The first read, taken as the group\n * starts, is the baseline and delivers nothing; a report arriving before it completes may describe a change it\n * already holds, so it is delivered unconfined. A read that fails or doesn't settle within a few seconds, or a file\n * git couldn't parse, is unconfined too.\n *\n * Given a `readFile`, a `readDirectory` (a directory's entries with their types, only the directories counting as\n * admin entries) and the folders whose worktrees the host has core ignore (a tool's throwaway worktrees, which no\n * host shows), the group reports no change of an ignored worktree's admin entry\n * (`<common>/worktrees/<id>`) to any session. Only registered folders count, since a user may keep real worktrees\n * anywhere, `.git` included. It lists the entries and reads each one's `gitdir` once as it starts, and again after a\n * watcher dropped events; a report arriving meanwhile is told at once, and decided once the listing settles, so what\n * is known of its entry catches up. From then on it reads an entry only when its `gitdir` may be new (the entry was\n * created, or its `gitdir` written, or it was removed before), so a real worktree's HEAD moves are told at once,\n * unread. Of two reads of one entry, the later decides both reports. An entry it doesn't know whose `gitdir` can't be\n * read (a watcher can report one before git writes it, and miss the write) is read once more a moment later, its\n * reports held until then, and told if it still can't be. Only the entry's directory or its `gitdir` going is a\n * removal; a deleted `HEAD` (a watcher may report git's lock file renamed over it as a delete) or `locked` is told as\n * the entry is known. Removing an entry deletes the `gitdir` a read needs, so a removal is told from what the entry was\n * known to be (before a read that couldn't read it, if one is waiting to read it again), and an entry it never knew is\n * told as real. Any other report of a removed entry but a delete is read, and one that can't be read is the removal's\n * own (a watcher may report the entry's directory changed beside each file it deletes), unless it creates the entry\n * again. A report of the `worktrees` directory itself (a coalesced\n * removal, a parent directory change, a poll, which sees nothing finer) lists it again: it is told to every session\n * when a real entry was added or removed since the last listing, and to none when only ignored ones were. Git removes\n * the directory with its last entry, so a directory that isn't there is an empty listing, as is a removal of it that\n * can't be listed. Since a listing (or a worktree moved into or out of a folder) changes what every session shows, it\n * is told to all of them; the other watcher's report of the same change then finds nothing left to tell. Where only a\n * poll watches the common dir, it sees just the `worktrees` directory, so an entry removed and added again under the\n * same id between two polls, or an entry's HEAD or lock changed in place, goes untold.\n *\n * Given the folders, the watchers over the common dir leave each one unwatched, since a tool's checkout there would\n * otherwise have every directory of it watched; one that shares a top-level directory with what the `.git` watch reads\n * stays watched.\n */\nexport class WatchGroup implements UnifiedDisposable {\n\tprivate readonly _sessions = new Map<string, SessionEntry>();\n\tprivate _commonWatcher: FileWatcher | undefined;\n\tprivate _commonReliability: FileWatcherReliability = 'reliable';\n\tprivate _commonTarget: GitDirProbeTarget | undefined;\n\tprivate _disposed = false;\n\n\t/** The shared `.git/config`, by section, as the last read that could parse it found it */\n\tprivate _config: GitConfigSections | undefined;\n\t/** The baseline read is in flight */\n\tprivate _configBaselining = false;\n\tprivate _configReading = false;\n\tprivate _configRereadQueued = false;\n\n\t/**\n\t * Settles once the latest baseline of the admin entries was taken; `undefined` when the group can't tell an\n\t * ignored worktree's, so every report is told at once\n\t */\n\tprivate _worktreesBaseline: Promise<void> | undefined;\n\t/** A baseline is pending, so a report waits for it */\n\tprivate _worktreesBaselining = false;\n\tprivate _worktreesRebaselineQueued = false;\n\t/** Set by the first baseline; while empty, nothing is ignored and every report is told at once */\n\tprivate _ignoredWorktreeRoots: readonly string[] = [];\n\t/** Listings run one at a time, so each compares with the one before it */\n\tprivate _worktreesQueue: Promise<void> = Promise.resolve();\n\t/** The `worktrees` directory's reports waiting on the queued listing; `undefined` while none is queued */\n\tprivate _worktreesRescanQueued:\n\t\t| {\n\t\t\t\treadonly delivers: (() => void)[];\n\t\t\t\t/** One of them is a removal of the directory */\n\t\t\t\tremoval: boolean;\n\t\t }\n\t\t| undefined;\n\t/** The admin entries the last listing found */\n\tprivate _listedWorktreeIds: ReadonlySet<string> = new Set();\n\t/** Admin entries known to exist, by id: whether each is an ignored worktree's */\n\tprivate readonly _worktreeIds = new Map<string, boolean>();\n\t/** What removed admin entries were, by id, oldest first */\n\tprivate readonly _removedWorktreeIds = new Map<string, boolean>();\n\t/**\n\t * Each id's latest `gitdir` read, settling with what it found and what the id was known to be before it; only it\n\t * may update what is known of the id. A removal of the entry drops it\n\t */\n\tprivate readonly _worktreeReads = new Map<\n\t\tstring,\n\t\tPromise<[ignored: boolean | undefined, previous: boolean | undefined]>\n\t>();\n\t/** Admin entries whose `gitdir` couldn't be read, by id, waiting to be read once more */\n\tprivate readonly _worktreeRetries = new Map<\n\t\tstring,\n\t\t{\n\t\t\treadonly timer: ReturnType<typeof setTimeout>;\n\t\t\t/** The reports waiting on it, told unless the entry turns out to be an ignored worktree's */\n\t\t\treadonly delivers: (() => void)[];\n\t\t\t/**\n\t\t\t * What the entry was known to be before its `gitdir` couldn't be read, so a move or a removal is still told\n\t\t\t * as it was\n\t\t\t */\n\t\t\tprevious: boolean | undefined;\n\t\t\t/**\n\t\t\t * Settles with whether the entry is an ignored worktree's; `undefined` when it still can't tell, or it was\n\t\t\t * removed\n\t\t\t */\n\t\t\treadonly decided: Promise<boolean | undefined>;\n\t\t\treadonly resolve: (ignored: boolean | undefined) => void;\n\t\t}\n\t>();\n\t/** The `.git` excludes of a watcher over the common git dir, with the ignored worktrees' folders it may leave out */\n\tprivate readonly _commonGitDirExcludes: readonly string[];\n\n\tconstructor(\n\t\treadonly commonGitDir: string,\n\t\tprivate readonly provider: FileWatchingProvider,\n\t\t/** When given, a watcher that reports it can't be trusted is polled; otherwise none is asked */\n\t\tprivate readonly poller?: GitDirPoller,\n\t\t/**\n\t\t * When given, reports of the shared `.git/config` are classified by what changed in it, and admin entries are\n\t\t * read to tell an ignored worktree's (see above)\n\t\t */\n\t\tprivate readonly readFile?: (path: string) => Promise<Uint8Array>,\n\t\t/**\n\t\t * Returns a directory's entries with their types; with `readFile`, the admin entries are listed, only the\n\t\t * directories counting (see above)\n\t\t */\n\t\tprivate readonly readDirectory?: (path: string) => Promise<readonly (readonly [string, number])[]>,\n\t\t/** The absolute, normalized folders whose worktrees are ignored; none reads no admin entry */\n\t\tignoredWorktreeRoots?: Promise<readonly string[]>,\n\t\t/** The folders whose worktrees are ignored, relative to the common git dir */\n\t\tignoredWorktreeFolders?: readonly string[],\n\t) {\n\t\tconst folders = getIgnoredWorktreeFolderExcludes(ignoredWorktreeFolders);\n\t\tthis._commonGitDirExcludes = folders.length ? [...gitDirExcludes, ...folders] : gitDirExcludes;\n\t\tif (readFile != null) {\n\t\t\tvoid this.readConfigBaseline();\n\t\t}\n\t\tif (readFile != null && readDirectory != null && ignoredWorktreeRoots != null) {\n\t\t\tthis.queueWorktreesBaseline(async () => {\n\t\t\t\tconst roots = await this.withTimeout(() => Promise.resolve(ignoredWorktreeRoots));\n\t\t\t\tif (this._disposed || !Array.isArray(roots) || !roots.length) return;\n\n\t\t\t\tthis._ignoredWorktreeRoots = roots;\n\t\t\t\tawait this.listWorktrees('baseline');\n\t\t\t});\n\t\t}\n\t}\n\n\t[Symbol.dispose](): void {\n\t\tthis.dispose();\n\t}\n\n\t/** Dispose the entire group (common watcher + all root watchers). */\n\tdispose(): void {\n\t\tif (this._disposed) return;\n\n\t\tthis._disposed = true;\n\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tentry.rootWatcher.dispose();\n\t\t\tthis.stopPolling(entry);\n\t\t}\n\t\tthis._sessions.clear();\n\n\t\tthis.disposeCommonWatcher();\n\n\t\tfor (const retry of this._worktreeRetries.values()) {\n\t\t\tclearTimeout(retry.timer);\n\t\t\tretry.resolve(undefined);\n\t\t}\n\t\tthis._worktreeRetries.clear();\n\t}\n\n\tget sessions(): ReadonlyMap<string, SessionEntry> {\n\t\treturn this._sessions;\n\t}\n\n\t/** True when a watcher the session hears through — its root watcher, or a linked session's common one — can't watch */\n\tisUnwatchable(repoPath: string): boolean {\n\t\tconst entry = this._sessions.get(repoPath);\n\t\tif (entry == null) return false;\n\n\t\treturn (\n\t\t\tentry.reliability === 'unwatchable' || (!entry.coversCommon && this._commonReliability === 'unwatchable')\n\t\t);\n\t}\n\n\t/** Add a session to this group. Creates the root watcher for the session's gitDir. */\n\taddSession(repoPath: string, gitDir: GitDir, hooks: WatchGroupHooks): void {\n\t\tif (this._disposed) return;\n\t\tif (this._sessions.has(repoPath)) return; // Already tracked\n\n\t\t// Determine the glob pattern for the root watcher\n\t\tconst isStandard = gitDir.commonUri == null;\n\t\tconst rootPattern = isStandard ? dotGitGlobCombined : dotGitGlobRoot;\n\n\t\t// The watcher can report its reliability before `createWatcher` returns, so before the entry exists\n\t\tlet entry: SessionEntry | undefined;\n\t\tlet initialReliability: FileWatcherReliability = 'reliable';\n\n\t\tconst rootWatcher = this.provider.createWatcher(\n\t\t\tgitDir.uri.fsPath,\n\t\t\trootPattern,\n\t\t\t(event: FileWatchEvent) => {\n\t\t\t\tconst e = this._sessions.get(repoPath);\n\t\t\t\tif (e != null) {\n\t\t\t\t\tif (event.reason !== 'overflow') {\n\t\t\t\t\t\te.target?.forget(event.path);\n\t\t\t\t\t}\n\t\t\t\t\tthis.onRootEvent(event, e);\n\t\t\t\t}\n\t\t\t},\n\t\t\tthis.getWatcherOptions(gitDir.uri.fsPath, state => {\n\t\t\t\tif (entry == null) {\n\t\t\t\t\tinitialReliability = state;\n\t\t\t\t} else if (this._sessions.get(repoPath) === entry) {\n\t\t\t\t\tthis.setRootReliability(entry, state);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\tconst entryGitDirPath = gitDir.uri.fsPath;\n\t\tentry = {\n\t\t\trepoPath: repoPath,\n\t\t\tgitDirPath: entryGitDirPath,\n\t\t\trootWatcher: rootWatcher,\n\t\t\tcoversCommon: isStandard,\n\t\t\tworktreeId: isStandard ? undefined : this.getWorktreeId(entryGitDirPath),\n\t\t\thooks: hooks,\n\t\t\treliability: 'reliable',\n\t\t};\n\n\t\tthis._sessions.set(repoPath, entry);\n\t\tif (initialReliability !== 'reliable') {\n\t\t\tthis.setRootReliability(entry, initialReliability, true);\n\t\t}\n\n\t\t// Start the common watcher if this is a worktree repo and we haven't yet.\n\t\t// Standard repos don't need a separate common watcher because their root\n\t\t// watcher uses dotGitGlobCombined which already covers all patterns.\n\t\tif (!isStandard) {\n\t\t\tthis.ensureCommonWatcher();\n\t\t}\n\t}\n\n\t/** Remove a session from this group. Disposes its root watcher. */\n\tremoveSession(repoPath: string): void {\n\t\tconst entry = this._sessions.get(repoPath);\n\t\tif (entry == null) return;\n\n\t\tentry.rootWatcher.dispose();\n\t\tthis.stopPolling(entry);\n\t\tthis._sessions.delete(repoPath);\n\n\t\t// Once no linked session is left, dispose the common watcher — it delivers to linked sessions only\n\t\tif (this._commonWatcher != null && !some(this._sessions.values(), e => !e.coversCommon)) {\n\t\t\tthis.disposeCommonWatcher();\n\t\t}\n\t}\n\n\tprivate getWorktreeId(gitDirPath: string): string | undefined {\n\t\treturn getWorktreeAdminId(gitDirPath, this.commonGitDir);\n\t}\n\n\tprivate ensureCommonWatcher(): void {\n\t\tif (this._commonWatcher != null || this._disposed) return;\n\n\t\t// The watcher can report its reliability before `createWatcher` returns\n\t\tlet watcher: FileWatcher | undefined;\n\t\tlet initialReliability: FileWatcherReliability = 'reliable';\n\t\tconst options = this.getWatcherOptions(this.commonGitDir, state => {\n\t\t\tif (watcher == null) {\n\t\t\t\tinitialReliability = state;\n\t\t\t} else if (this._commonWatcher === watcher) {\n\t\t\t\tthis.setCommonReliability(state);\n\t\t\t}\n\t\t});\n\n\t\twatcher = this.provider.createWatcher(\n\t\t\tthis.commonGitDir,\n\t\t\tdotGitGlobCommon,\n\t\t\t(event: FileWatchEvent) => {\n\t\t\t\tif (event.reason !== 'overflow') {\n\t\t\t\t\tthis._commonTarget?.forget(event.path);\n\t\t\t\t}\n\t\t\t\tthis.onCommonEvent(event);\n\t\t\t},\n\t\t\toptions,\n\t\t);\n\t\tthis._commonWatcher = watcher;\n\t\tif (initialReliability !== 'reliable') {\n\t\t\tthis.setCommonReliability(initialReliability, true);\n\t\t}\n\t}\n\n\tprivate disposeCommonWatcher(): void {\n\t\tthis._commonWatcher?.dispose();\n\t\tthis._commonWatcher = undefined;\n\t\tthis._commonReliability = 'reliable';\n\t\tif (this._commonTarget != null) {\n\t\t\tthis.poller?.delete(this._commonTarget);\n\t\t\tthis._commonTarget = undefined;\n\t\t}\n\t}\n\n\t/** Hosts that didn't opt into polling get exactly the options they always had */\n\tprivate getWatcherOptions(\n\t\tbasePath: string,\n\t\tonDidChangeReliability: (state: FileWatcherReliability) => void,\n\t): FileWatcherOptions {\n\t\tconst excludes = this.getExcludes(basePath);\n\t\treturn this.poller != null\n\t\t\t? { excludes: excludes, onDidChangeReliability: onDidChangeReliability }\n\t\t\t: { excludes: excludes };\n\t}\n\n\t/**\n\t * The ignored worktrees' folders join the `.git` excludes of a watcher over the common git dir: a tool that keeps its\n\t * throwaway checkouts inside the git dir would otherwise have each one's every directory watched, and every file it\n\t * writes reported. Every other watcher sits on a linked worktree's admin entry, which holds none of them\n\t */\n\tprivate getExcludes(basePath: string): readonly string[] {\n\t\tif (this._commonGitDirExcludes === gitDirExcludes) return gitDirExcludes;\n\n\t\treturn normalizePath(basePath) === normalizePath(this.commonGitDir)\n\t\t\t? this._commonGitDirExcludes\n\t\t\t: gitDirExcludes;\n\t}\n\n\tprivate setRootReliability(entry: SessionEntry, state: FileWatcherReliability, initial?: boolean): void {\n\t\tconst previous = entry.reliability;\n\t\tif (previous === state || this.poller == null) return;\n\n\t\tentry.reliability = state;\n\t\tif (state === 'reliable') {\n\t\t\tthis.stopPolling(entry);\n\t\t} else if (entry.target == null) {\n\t\t\tconst target = new GitDirProbeTarget(\n\t\t\t\tentry.gitDirPath,\n\t\t\t\tthis.poller,\n\t\t\t\t() => this.getRootProbes(entry),\n\t\t\t\tgitDirProbesByEmittedPath,\n\t\t\t\t(event, probe) => {\n\t\t\t\t\tif (entry.target !== target) return;\n\n\t\t\t\t\tthis.onRootEvent(event, entry);\n\t\t\t\t\tif (probe.path === 'logs/HEAD' && !entry.coversCommon) {\n\t\t\t\t\t\tthis.onLinkedHeadMoved();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\tentry.target = target;\n\t\t\tthis.poller.add(target);\n\t\t}\n\n\t\tif ((state === 'unwatchable') === (previous === 'unwatchable')) return;\n\n\t\t// The watch went down or came back: whatever changed meanwhile went unseen\n\t\tif (!initial) {\n\t\t\tthis.deliverOverflow(entry);\n\t\t\tif (entry.coversCommon) {\n\t\t\t\tthis.rebaselineWorktrees();\n\t\t\t}\n\t\t}\n\t\tentry.hooks.onUnwatchableChanged?.(entry.repoPath);\n\t}\n\n\tprivate setCommonReliability(state: FileWatcherReliability, initial?: boolean): void {\n\t\tconst previous = this._commonReliability;\n\t\tif (previous === state || this.poller == null) return;\n\n\t\tthis._commonReliability = state;\n\t\tif (state === 'reliable') {\n\t\t\tif (this._commonTarget != null) {\n\t\t\t\tthis.poller.delete(this._commonTarget);\n\t\t\t\tthis._commonTarget = undefined;\n\t\t\t}\n\t\t} else if (this._commonTarget == null) {\n\t\t\tconst target = new GitDirProbeTarget(\n\t\t\t\tthis.commonGitDir,\n\t\t\t\tthis.poller,\n\t\t\t\t() => this.getCommonProbes(),\n\t\t\t\tgitDirProbesByEmittedPath,\n\t\t\t\tevent => {\n\t\t\t\t\tif (this._commonTarget === target) {\n\t\t\t\t\t\tthis.onCommonEvent(event);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\tthis._commonTarget = target;\n\t\t\tthis.poller.add(target);\n\t\t}\n\n\t\tif ((state === 'unwatchable') === (previous === 'unwatchable')) return;\n\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (entry.coversCommon) continue;\n\n\t\t\tif (!initial) {\n\t\t\t\tthis.deliverOverflow(entry);\n\t\t\t}\n\t\t\tentry.hooks.onUnwatchableChanged?.(entry.repoPath);\n\t\t}\n\t\tif (!initial) {\n\t\t\tthis.rebaselineWorktrees();\n\t\t}\n\t}\n\n\tprivate stopPolling(entry: SessionEntry): void {\n\t\tif (entry.target == null) return;\n\n\t\tthis.poller?.delete(entry.target);\n\t\tentry.target = undefined;\n\t}\n\n\t/**\n\t * A session rooted at the common dir polls the common files too, with the refs of every session in the group: its\n\t * combined watcher would hear them all. While the common dir is polled too, the poller stats each shared file once\n\t * for both, and each keeps its own readings, so what one watcher reported is held back from its own sessions only\n\t */\n\tprivate getRootProbes(entry: SessionEntry): readonly GitDirProbe[] {\n\t\tif (!entry.coversCommon) return gitDirRootProbes;\n\n\t\tconst refs = new Set<string>();\n\t\tfor (const e of this._sessions.values()) {\n\t\t\tfor (const ref of e.hooks.getProbeRefs?.() ?? []) {\n\t\t\t\trefs.add(ref);\n\t\t\t}\n\t\t}\n\t\treturn [...gitDirRootProbes, ...gitDirCommonProbes, ...getGitDirRefProbes(refs)];\n\t}\n\n\t/**\n\t * A linked worktree's `logs/HEAD` moved — a commit or reset there, on a branch a polled session rooted at the common\n\t * dir may not probe — so each such session hears a `heads` change its combined watcher would have heard\n\t */\n\tprivate onLinkedHeadMoved(): void {\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (!entry.coversCommon || entry.target == null) continue;\n\n\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['heads']);\n\t\t}\n\t}\n\n\t/** The common files, with the refs of every linked session (the only ones the common watcher delivers to) */\n\tprivate getCommonProbes(): GitDirProbe[] {\n\t\tconst refs = new Set<string>();\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (entry.coversCommon) continue;\n\n\t\t\tfor (const ref of entry.hooks.getProbeRefs?.() ?? []) {\n\t\t\t\trefs.add(ref);\n\t\t\t}\n\t\t}\n\t\treturn [...gitDirCommonProbes, ...getGitDirRefProbes(refs)];\n\t}\n\n\tprivate onCommonEvent(event: FileWatchEvent): void {\n\t\tif (event.reason === 'overflow') {\n\t\t\tfor (const entry of this._sessions.values()) {\n\t\t\t\tif (entry.coversCommon) continue;\n\n\t\t\t\tthis.deliverOverflow(entry);\n\t\t\t}\n\t\t\tthis.rebaselineWorktrees();\n\t\t\treturn;\n\t\t}\n\n\t\t// Compute relative path from common git dir\n\t\tif (!isDescendant(event.path, this.commonGitDir)) return;\n\n\t\tconst relativePath = relative(this.commonGitDir, event.path);\n\t\tif (shouldIgnoreRepoPath(relativePath)) return;\n\n\t\tif (this.readFile != null && isConfigFile(relativePath)) {\n\t\t\tthis.onConfigReported();\n\t\t\treturn;\n\t\t}\n\n\t\tconst isFetchHead = relativePath === 'FETCH_HEAD';\n\t\tconst isExclude = relativePath === 'info/exclude';\n\t\tconst changes = isFetchHead\n\t\t\t? undefined\n\t\t\t: withWorktreeEntryHead(classifyGitDirChange(relativePath), relativePath, event.reason);\n\t\tif (changes == null && !isFetchHead && !isExclude) return;\n\n\t\tconst ref = changes != null ? getChangedRef(relativePath) : undefined;\n\n\t\t// `worktrees/<n>/HEAD`: the owner hears its own HEAD from its root watcher. Its `locked` and `gitdir` aren't in\n\t\t// the root glob, so the owner hears those only from here\n\t\tconst ownerId = changes != null ? getMovedWorktreeId(relativePath) : undefined;\n\t\tconst movedWorktree = getReportedWorktreeId(relativePath, changes);\n\n\t\tif (changes != null && this.isWorktreesReport(changes)) {\n\t\t\tconst sessions = [...this._sessions.values()].filter(\n\t\t\t\te => !e.coversCommon && (ownerId == null || e.worktreeId !== ownerId),\n\t\t\t);\n\t\t\tthis.onWorktreesReported(relativePath, event.reason, () => {\n\t\t\t\tfor (const entry of sessions) {\n\t\t\t\t\tif (this._disposed || this._sessions.get(entry.repoPath) !== entry) continue;\n\n\t\t\t\t\tdeliverRepoChanged(entry, changes, ref, movedWorktree);\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\t// A session rooted at the common dir sees every common file (hooks included) through its own\n\t\t\t// combined root watcher, so delivering here too would duplicate it\n\t\t\tif (entry.coversCommon) continue;\n\n\t\t\tif (isFetchHead) {\n\t\t\t\t// FETCH_HEAD lives in the main .git dir; each worktree updates its last-fetched state\n\t\t\t\tentry.hooks.onFetchHeadChanged?.(entry.repoPath);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (changes != null && (ownerId == null || entry.worktreeId !== ownerId)) {\n\t\t\t\tdeliverRepoChanged(entry, changes, ref, movedWorktree);\n\t\t\t}\n\n\t\t\tif (isExclude) {\n\t\t\t\tentry.hooks.onIgnoresChanged?.(entry.repoPath);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate deliverOverflow(entry: SessionEntry): void {\n\t\t// Every kind, no ref (ref kinds stay unnamed). Never `'unknown'` — the cache would unregister the path\n\t\tentry.hooks.onRepoChanged(entry.repoPath, [...allWatchedRepositoryChanges], undefined, true);\n\t\tentry.hooks.onFetchHeadChanged?.(entry.repoPath);\n\t\tentry.hooks.onIgnoresChanged?.(entry.repoPath);\n\t}\n\n\tprivate onRootEvent(event: FileWatchEvent, entry: SessionEntry): void {\n\t\tif (event.reason === 'overflow') {\n\t\t\tthis.deliverOverflow(entry);\n\t\t\tif (entry.coversCommon) {\n\t\t\t\tthis.rebaselineWorktrees();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (!isDescendant(event.path, entry.gitDirPath)) return;\n\n\t\tconst relativePath = relative(entry.gitDirPath, event.path);\n\t\tif (shouldIgnoreRepoPath(relativePath)) return;\n\n\t\t// Check for FETCH_HEAD before interpretation\n\t\tif (relativePath === 'FETCH_HEAD') {\n\t\t\tentry.hooks.onFetchHeadChanged?.(entry.repoPath);\n\t\t\treturn;\n\t\t}\n\n\t\t// A linked worktree's git dir isn't the common one, so no file there is the shared config\n\t\tif (entry.coversCommon && this.readFile != null && isConfigFile(relativePath)) {\n\t\t\tthis.onConfigReported();\n\t\t\treturn;\n\t\t}\n\n\t\tconst changes = withWorktreeEntryHead(classifyGitDirChange(relativePath), relativePath, event.reason);\n\t\t// A linked worktree's git dir isn't the common one, so no path there is a worktree's admin entry\n\t\tconst movedWorktree = entry.coversCommon ? getReportedWorktreeId(relativePath, changes) : undefined;\n\t\tif (changes != null && entry.coversCommon && this.isWorktreesReport(changes)) {\n\t\t\tthis.onWorktreesReported(relativePath, event.reason, () => {\n\t\t\t\tif (this._disposed || this._sessions.get(entry.repoPath) !== entry) return;\n\n\t\t\t\tdeliverRepoChanged(entry, changes, getChangedRef(relativePath), movedWorktree);\n\t\t\t});\n\t\t} else if (changes != null) {\n\t\t\tdeliverRepoChanged(entry, changes, getChangedRef(relativePath), movedWorktree);\n\t\t}\n\n\t\tif (relativePath === 'info/exclude') {\n\t\t\tentry.hooks.onIgnoresChanged?.(entry.repoPath);\n\t\t}\n\t}\n\n\t/** A report of the `worktrees` directory, an admin entry or a file in it, once the group may tell them apart */\n\tprivate isWorktreesReport(changes: readonly RepositoryChange[]): boolean {\n\t\treturn (\n\t\t\tthis._worktreesBaseline != null &&\n\t\t\tchanges.includes('worktrees') &&\n\t\t\tchanges.every(c => c === 'worktrees' || c === 'worktreeHead')\n\t\t);\n\t}\n\n\t/** `deliver` tells the sessions the report reaches of it, should the report concern them (see above) */\n\tprivate onWorktreesReported(relativePath: string, reason: FileWatchEvent['reason'], deliver: () => void): void {\n\t\tif (this._worktreesBaselining && this._worktreesBaseline != null) {\n\t\t\t// The baseline may have read the entry before the change reported, so the report is told; it is still decided\n\t\t\t// once the baseline settles, so what is known of the entry catches up with it\n\t\t\tdeliver();\n\t\t\tvoid this._worktreesBaseline.then(() => this.decideWorktreesReport(relativePath, reason, noop));\n\t\t\treturn;\n\t\t}\n\n\t\tthis.decideWorktreesReport(relativePath, reason, deliver);\n\t}\n\n\tprivate decideWorktreesReport(relativePath: string, reason: FileWatchEvent['reason'], deliver: () => void): void {\n\t\tif (this._disposed) return;\n\t\tif (!this._ignoredWorktreeRoots.length) {\n\t\t\tdeliver();\n\t\t\treturn;\n\t\t}\n\n\t\tif (relativePath === 'worktrees') {\n\t\t\tthis.queueWorktreesRescan(reason, deliver);\n\t\t\treturn;\n\t\t}\n\n\t\tconst entry = parseWorktreeAdminPath(relativePath);\n\t\tif (entry == null) {\n\t\t\tdeliver();\n\t\t\treturn;\n\t\t}\n\n\t\tconst { id, file } = entry;\n\n\t\t// Only the entry or its `gitdir` going is a removal: an unlock deletes `locked` from an entry that stays, and a\n\t\t// watcher may report git's lock file renamed over `HEAD` as `HEAD` deleted and created again\n\t\tif (reason === 'delete' && (file == null || file === 'gitdir')) {\n\t\t\tif (this.forgetWorktreeId(id) !== true) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// What a removed entry was decides the removal's other reports. Any other report of its id is read: one that finds\n\t\t// the entry is of an entry created again, which may be another worktree's. One that can't is the removal's own\n\t\t// unless it creates the entry, since a watcher may report the entry's directory changed beside each file the\n\t\t// removal deletes\n\t\tconst removed = this._worktreeIds.has(id) ? undefined : this._removedWorktreeIds.get(id);\n\t\tconst known = this._worktreeIds.get(id) ?? (reason === 'delete' ? removed : undefined);\n\t\t// Only a new entry or a written `gitdir` can name another worktree; anything else is told as the id is known\n\t\tif (known != null && file !== 'gitdir' && !(file == null && reason === 'create')) {\n\t\t\tif (!known) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst retry = removed == null || reason === 'create';\n\t\tvoid this.readWorktreeId(id, retry).then(([ignored, previous]) => {\n\t\t\tif (this._disposed) return;\n\n\t\t\tif (ignored == null) {\n\t\t\t\tif (retry) {\n\t\t\t\t\tvoid this.waitForWorktreeRetry(id, deliver);\n\t\t\t\t} else if (removed === false) {\n\t\t\t\t\tdeliver();\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Moved into or out of an ignored folder: every session's list gained or lost it\n\t\t\tif (previous != null && ignored !== previous) {\n\t\t\t\tthis.deliverWorktreesChange();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!ignored) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Reads the entry's `gitdir`: whether it names an ignored worktree (`undefined` when it can't be read), and what the\n\t * id was known to be when this read replaced it. Reads of one id can settle out of order (a slow one from before the\n\t * worktree moved out of the folder), so only the latest updates what is known of it; an earlier one settles with\n\t * what the latest finds, without what the id was, since the latest tells a move itself, or once the entry was removed\n\t * since, with what the removal found it was. One that can't read the entry forgets what it was known to be, since git\n\t * may be writing its `gitdir` again, and reads it once more a moment later, unless `retry` is false (it then leaves\n\t * what is known as it was); one that can settles that read, if pending.\n\t */\n\tprivate readWorktreeId(\n\t\tid: string,\n\t\tretry: boolean = true,\n\t): Promise<[ignored: boolean | undefined, previous: boolean | undefined]> {\n\t\tconst read: Promise<[ignored: boolean | undefined, previous: boolean | undefined]> = this.readIgnoredWorktree(\n\t\t\tid,\n\t\t).then(ignored => {\n\t\t\tconst latest = this._worktreeReads.get(id);\n\t\t\tif (latest !== read) {\n\t\t\t\tif (latest == null) return [this._removedWorktreeIds.get(id), undefined];\n\n\t\t\t\treturn latest.then(([found]): [boolean | undefined, undefined] => {\n\t\t\t\t\t// A later read that couldn't read the entry may not read it again, but this one's report may be of\n\t\t\t\t\t// the entry created again, unless it was removed since\n\t\t\t\t\tif (found == null && retry && this._worktreeReads.has(id)) {\n\t\t\t\t\t\tthis.scheduleWorktreeRetry(id, undefined);\n\t\t\t\t\t}\n\t\t\t\t\treturn [found, undefined];\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst previous = this._worktreeIds.get(id);\n\t\t\tif (ignored == null) {\n\t\t\t\tif (!retry) return [undefined, previous];\n\n\t\t\t\tthis._removedWorktreeIds.delete(id);\n\t\t\t\tthis._worktreeIds.delete(id);\n\t\t\t\tthis.scheduleWorktreeRetry(id, previous);\n\t\t\t\treturn [undefined, previous];\n\t\t\t}\n\n\t\t\tthis._removedWorktreeIds.delete(id);\n\t\t\tthis._worktreeIds.set(id, ignored);\n\t\t\tthis.settleWorktreeRetry(id, ignored);\n\t\t\treturn [ignored, previous];\n\t\t});\n\t\tthis._worktreeReads.set(id, read);\n\t\treturn read;\n\t}\n\n\t/** Reads the entry once more a moment later, unless that is already pending; `previous` is what it was known to be */\n\tprivate scheduleWorktreeRetry(id: string, previous: boolean | undefined): void {\n\t\tif (this._disposed) return;\n\n\t\tconst pending = this._worktreeRetries.get(id);\n\t\tif (pending != null) {\n\t\t\tpending.previous ??= previous;\n\t\t\treturn;\n\t\t}\n\n\t\tlet resolve!: (ignored: boolean | undefined) => void;\n\t\tconst decided = new Promise<boolean | undefined>(r => {\n\t\t\tresolve = r;\n\t\t});\n\t\tconst timer = setTimeout(() => {\n\t\t\tvoid this.readWorktreeId(id).then(([ignored]) => {\n\t\t\t\t// A removal, or a later read that could read the entry, may have settled it meanwhile\n\t\t\t\tif (this._worktreeRetries.get(id)?.decided === decided) {\n\t\t\t\t\tthis.settleWorktreeRetry(id, ignored);\n\t\t\t\t}\n\t\t\t});\n\t\t}, worktreeRetryDelayMs);\n\t\tthis._worktreeRetries.set(id, {\n\t\t\ttimer: timer,\n\t\t\tdelivers: [],\n\t\t\tprevious: previous,\n\t\t\tdecided: decided,\n\t\t\tresolve: resolve,\n\t\t});\n\t}\n\n\t/**\n\t * A report whose read couldn't read the entry waits on the entry's next read, and `deliver` is told then, unless that\n\t * read finds an ignored worktree's; one still unreadable is told. Both watchers report each change of an entry, so\n\t * the reports of one id wait on one read. Resolves with what it found, as {@link settleWorktreeRetry} does\n\t */\n\tprivate waitForWorktreeRetry(id: string, deliver?: () => void): Promise<boolean | undefined> {\n\t\t// A later read may already have found what the entry is\n\t\tconst known = this._worktreeIds.get(id);\n\t\tif (known != null) {\n\t\t\tif (!known) {\n\t\t\t\tdeliver?.();\n\t\t\t}\n\t\t\treturn Promise.resolve(known);\n\t\t}\n\n\t\t// None is pending only when the entry was removed since, and the removal is told itself\n\t\tconst retry = this._worktreeRetries.get(id);\n\t\tif (retry == null) return Promise.resolve(undefined);\n\n\t\tif (deliver != null) {\n\t\t\tretry.delivers.push(deliver);\n\t\t}\n\t\treturn retry.decided;\n\t}\n\n\t/**\n\t * Tells the reports waiting on the id's retry what the entry turned out to be: nothing when an ignored worktree's,\n\t * every session when it moved into or out of an ignored folder, and the reports' own sessions otherwise, `ignored`\n\t * being `undefined` when it still couldn't be read\n\t */\n\tprivate settleWorktreeRetry(id: string, ignored: boolean | undefined): void {\n\t\tconst pending = this._worktreeRetries.get(id);\n\t\tif (pending == null) return;\n\n\t\tthis._worktreeRetries.delete(id);\n\t\tclearTimeout(pending.timer);\n\t\t// Settled before any session is told: a listing waits on it, and a hook that throws would otherwise hold back\n\t\t// every later listing for good\n\t\tpending.resolve(ignored);\n\t\tif (ignored != null && pending.previous != null && ignored !== pending.previous) {\n\t\t\tthis.deliverWorktreesChange();\n\t\t} else if (ignored !== true) {\n\t\t\tfor (const deliver of pending.delivers) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Takes `id` as removed, remembering what it was for the removal's other reports; returns that, or `undefined` when\n\t * the id was never known\n\t */\n\tprivate forgetWorktreeId(id: string): boolean | undefined {\n\t\t// A read still in flight read the entry before it went, and would bring the removed id back as known\n\t\tthis._worktreeReads.delete(id);\n\n\t\tlet ignored = this._worktreeIds.get(id);\n\t\t// The reports waiting to read the entry again are dropped: the removal is told for what the id was, which only\n\t\t// the retry still knows once a read couldn't read the entry\n\t\tconst retry = this._worktreeRetries.get(id);\n\t\tif (retry != null) {\n\t\t\tthis._worktreeRetries.delete(id);\n\t\t\tclearTimeout(retry.timer);\n\t\t\tretry.resolve(undefined);\n\t\t\tignored ??= retry.previous;\n\t\t}\n\n\t\tif (ignored == null) return this._removedWorktreeIds.get(id);\n\n\t\tthis._worktreeIds.delete(id);\n\t\tthis._removedWorktreeIds.delete(id);\n\t\tthis._removedWorktreeIds.set(id, ignored);\n\t\tif (this._removedWorktreeIds.size > removedWorktreeIdsLimit) {\n\t\t\tconst [oldest] = this._removedWorktreeIds.keys();\n\t\t\tthis._removedWorktreeIds.delete(oldest);\n\t\t}\n\t\treturn ignored;\n\t}\n\n\t/** Whether the entry's `gitdir` names an ignored worktree, or `undefined` when it can't be read. Never rejects */\n\tprivate async readIgnoredWorktree(id: string): Promise<boolean | undefined> {\n\t\tconst adminDir = joinPaths(this.commonGitDir, 'worktrees', id);\n\t\tconst content = await this.readWithTimeout(joinPaths(adminDir, 'gitdir'));\n\t\treturn isIgnoredWorktreeEntry(adminDir, content, this._ignoredWorktreeRoots);\n\t}\n\n\tprivate queueWorktreesBaseline(take: () => Promise<void>): void {\n\t\tthis._worktreesBaselining = true;\n\t\tconst baseline: Promise<void> = this._worktreesQueue\n\t\t\t.then(take)\n\t\t\t.catch(() => {})\n\t\t\t.finally(() => {\n\t\t\t\tif (this._worktreesBaseline === baseline) {\n\t\t\t\t\tthis._worktreesBaselining = false;\n\t\t\t\t}\n\t\t\t});\n\t\tthis._worktreesBaseline = baseline;\n\t\tthis._worktreesQueue = baseline;\n\t}\n\n\t/** A watcher of the `worktrees` directory dropped events: whatever changed meanwhile went unseen */\n\tprivate rebaselineWorktrees(): void {\n\t\tif (this._worktreesBaseline == null || this._worktreesRebaselineQueued || this._disposed) return;\n\t\t// The first baseline found no folder to ignore, and none is asked for again, so there is nothing to retake\n\t\tif (!this._worktreesBaselining && !this._ignoredWorktreeRoots.length) return;\n\n\t\tthis._worktreesRebaselineQueued = true;\n\t\tthis.queueWorktreesBaseline(async () => {\n\t\t\tthis._worktreesRebaselineQueued = false;\n\t\t\tif (this._disposed || !this._ignoredWorktreeRoots.length) return;\n\n\t\t\tawait this.listWorktrees('rebaseline');\n\t\t});\n\t}\n\n\t/** The watchers' reports of the directory pile onto one queued listing, which tells them apart */\n\tprivate queueWorktreesRescan(reason: FileWatchEvent['reason'], deliver: () => void): void {\n\t\tconst queued = this._worktreesRescanQueued;\n\t\tif (queued != null) {\n\t\t\tqueued.delivers.push(deliver);\n\t\t\tqueued.removal ||= reason === 'delete';\n\t\t\treturn;\n\t\t}\n\n\t\tconst rescan = { delivers: [deliver], removal: reason === 'delete' };\n\t\tthis._worktreesRescanQueued = rescan;\n\t\tthis._worktreesQueue = this._worktreesQueue\n\t\t\t.then(() => {\n\t\t\t\tthis._worktreesRescanQueued = undefined;\n\t\t\t\treturn this.listWorktrees('rescan', rescan.delivers, rescan.removal);\n\t\t\t})\n\t\t\t.catch(() => {});\n\t}\n\n\t/**\n\t * Lists the admin entries and compares them with the last listing. A baseline (or a rebaseline, after a watcher\n\t * dropped events) reads every entry; a rescan only those it doesn't know, reading one it can't read once more a\n\t * moment later. Git removes the directory with its last entry, so a directory that isn't there is an empty listing,\n\t * whatever the reports said of it (a poll sees its removal as a change). A listing that fails otherwise is a\n\t * baseline's empty directory, and a rescan's too when one of its reports (`delivers`) removed the directory. For any\n\t * other rescan, it is a change it can't rule out, told to the reports' own sessions\n\t */\n\tprivate async listWorktrees(\n\t\tmode: 'baseline' | 'rebaseline' | 'rescan',\n\t\tdelivers?: readonly (() => void)[],\n\t\tremoval?: boolean,\n\t): Promise<void> {\n\t\tconst readDirectory = this.readDirectory;\n\t\tif (readDirectory == null) return;\n\n\t\tconst entries = await this.withTimeout(() =>\n\t\t\treadDirectory(joinPaths(this.commonGitDir, 'worktrees')).catch((ex: unknown) => {\n\t\t\t\tif (isNotFound(ex)) return [];\n\n\t\t\t\tthrow ex;\n\t\t\t}),\n\t\t);\n\t\tif (this._disposed) return;\n\n\t\t// An admin entry is a directory, so a stray file such as `.DS_Store` is none\n\t\tconst names = entries?.filter(([, type]) => type & FileType.Directory).map(([name]) => name);\n\n\t\tif (names == null && mode === 'rescan' && !removal) {\n\t\t\tfor (const deliver of delivers ?? []) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst listing = new Set(names);\n\t\tconst previous = this._listedWorktreeIds;\n\t\tthis._listedWorktreeIds = listing;\n\n\t\tlet changed = false;\n\t\tif (mode !== 'baseline') {\n\t\t\t// An entry known only from its own reports since the last listing may be gone too\n\t\t\tfor (const id of new Set([...previous, ...this._worktreeIds.keys()])) {\n\t\t\t\tif (listing.has(id)) continue;\n\n\t\t\t\tif (this.forgetWorktreeId(id) !== true) {\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst reads = await Promise.all(\n\t\t\t[...listing]\n\t\t\t\t.filter(id => mode !== 'rescan' || (!previous.has(id) && !this._worktreeIds.has(id)))\n\t\t\t\t.map(async id => {\n\t\t\t\t\tconst [ignored, known] = await this.readWorktreeId(id);\n\t\t\t\t\tif (ignored != null || mode !== 'rescan' || this._disposed) return [id, [ignored, known]] as const;\n\n\t\t\t\t\t// An entry listed before its `gitdir` is written won't be listed as new again\n\t\t\t\t\treturn [id, [await this.waitForWorktreeRetry(id), undefined]] as const;\n\t\t\t\t}),\n\t\t);\n\t\tif (this._disposed || mode === 'baseline') return;\n\n\t\tconst read = new Map(reads);\n\t\tfor (const id of listing) {\n\t\t\tconst result = read.get(id);\n\t\t\tif (!previous.has(id)) {\n\t\t\t\t// An entry whose `gitdir` still can't be read counts as real\n\t\t\t\tif ((result != null ? result[0] : this._worktreeIds.get(id)) !== true) {\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t} else if (result?.[0] != null && result[1] != null && result[0] !== result[1]) {\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t}\n\n\t\tif (changed) {\n\t\t\tthis.deliverWorktreesChange();\n\t\t}\n\t}\n\n\tprivate deliverWorktreesChange(): void {\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['worktrees', 'worktreeHead'], undefined);\n\t\t}\n\t}\n\n\tprivate onConfigReported(): void {\n\t\t// The baseline may already hold the change reported, which comparing with it would lose\n\t\tif (this._configBaselining) {\n\t\t\tthis.deliverConfigChange(undefined);\n\t\t\treturn;\n\t\t}\n\t\tif (this._configReading) {\n\t\t\tthis._configRereadQueued = true;\n\t\t\treturn;\n\t\t}\n\n\t\tvoid this.readConfigChanges();\n\t}\n\n\tprivate async readConfigBaseline(): Promise<void> {\n\t\tthis._configBaselining = true;\n\t\tthis._configReading = true;\n\t\ttry {\n\t\t\tconst config = await this.readConfig();\n\t\t\tif (this._disposed) return;\n\n\t\t\tthis._config = config;\n\t\t} finally {\n\t\t\tthis._configBaselining = false;\n\t\t\tthis._configReading = false;\n\t\t}\n\t}\n\n\t/** Reads and compares until no report came in during the last read: it may describe a change the read missed */\n\tprivate async readConfigChanges(): Promise<void> {\n\t\tthis._configReading = true;\n\t\ttry {\n\t\t\tdo {\n\t\t\t\tthis._configRereadQueued = false;\n\t\t\t\tconst config = await this.readConfig();\n\t\t\t\tif (this._disposed) return;\n\n\t\t\t\tconst previous = this._config;\n\t\t\t\tif (config == null || previous == null) {\n\t\t\t\t\t// Unreadable now, or never readable before: the change may be anywhere. A failed read keeps the last\n\t\t\t\t\t// snapshot, so the next read still compares with what every session was told\n\t\t\t\t\tthis._config ??= config;\n\t\t\t\t\tthis.deliverConfigChange(undefined);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tthis._config = config;\n\t\t\t\tconst change = diffGitConfigSections(previous, config);\n\t\t\t\tif (change != null) {\n\t\t\t\t\tthis.deliverConfigChange(change);\n\t\t\t\t}\n\t\t\t} while (this._configRereadQueued);\n\t\t} finally {\n\t\t\tthis._configReading = false;\n\t\t}\n\t}\n\n\t/** `undefined` when the file couldn't be read or parsed, or the read didn't settle in time */\n\tprivate async readConfig(): Promise<GitConfigSections | undefined> {\n\t\tconst data = await this.readWithTimeout(joinPaths(this.commonGitDir, 'config'));\n\t\ttry {\n\t\t\treturn data != null ? parseGitConfigBytes(data) : undefined;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/** `undefined` when the file couldn't be read, or the read didn't settle in time */\n\tprivate readWithTimeout(path: string): Promise<Uint8Array | undefined> {\n\t\tconst readFile = this.readFile;\n\t\tif (readFile == null) return Promise.resolve(undefined);\n\n\t\treturn this.withTimeout(() => readFile(path));\n\t}\n\n\t/** `undefined` when `read` rejects, or doesn't settle in time */\n\tprivate async withTimeout<T>(read: () => Promise<T>): Promise<T | undefined> {\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\ttry {\n\t\t\treturn await Promise.race([\n\t\t\t\tread(),\n\t\t\t\tnew Promise<undefined>(resolve => {\n\t\t\t\t\ttimer = setTimeout(resolve, readTimeoutMs, undefined);\n\t\t\t\t}),\n\t\t\t]);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t}\n\n\t/**\n\t * Tells every session of a change to the shared `.git/config`: confined to some branches' sections, or (`undefined`,\n\t * or a change outside them) anywhere, which may have changed a remote's settings too. Either way no ref moved\n\t */\n\tprivate deliverConfigChange(change: GitConfigSectionsChange | undefined): void {\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (change?.confined) {\n\t\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['config'], false, false, change.branches);\n\t\t\t} else {\n\t\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['config', 'remotes'], false);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * `changes` with `worktreeHead` for a report that can stand for an entry's HEAD created or deleted with it: the\n * `worktrees` directory, an entry created or deleted, or its `gitdir` deleted. A watcher may coalesce the subtree a\n * removal deletes into one report of its parent, so no report of the HEAD comes. An entry's directory merely changed\n * stays `worktrees` alone: a watcher may report it beside each file in it, a lock's `locked` included\n */\nfunction withWorktreeEntryHead(\n\tchanges: RepositoryChange[] | undefined,\n\trelativePath: string,\n\treason: FileWatchEvent['reason'],\n): RepositoryChange[] | undefined {\n\tif (changes?.length !== 1 || changes[0] !== 'worktrees') return changes;\n\tif (relativePath === 'worktrees') return ['worktrees', 'worktreeHead'];\n\n\tconst idEnd = relativePath.indexOf('/', 10);\n\tif (idEnd === -1) return reason === 'create' || reason === 'delete' ? ['worktrees', 'worktreeHead'] : changes;\n\n\treturn reason === 'delete' && relativePath.substring(idEnd + 1) === 'gitdir'\n\t\t? ['worktrees', 'worktreeHead']\n\t\t: changes;\n}\n\n/** The admin id of the linked worktree whose `HEAD` file `relativePath` (relative to the common git dir) is */\nfunction getMovedWorktreeId(relativePath: string): string | undefined {\n\tconst entry = parseWorktreeAdminPath(relativePath);\n\treturn entry?.file === 'HEAD' ? entry.id : undefined;\n}\n\n/**\n * The admin id of the linked worktree a `worktreeHead` among `changes` is for: the entry `relativePath` (relative to the\n * common git dir) is, or is a file of\n */\nfunction getReportedWorktreeId(\n\trelativePath: string,\n\tchanges: readonly RepositoryChange[] | undefined,\n): string | undefined {\n\treturn changes?.includes('worktreeHead') ? parseWorktreeAdminPath(relativePath)?.id : undefined;\n}\n\n/** Tells `entry` of `changes`, naming the linked worktree whose HEAD moved only when the report knows it */\nfunction deliverRepoChanged(\n\tentry: SessionEntry,\n\tchanges: RepositoryChange[],\n\tref: string | false | undefined,\n\tmovedWorktree: string | undefined,\n): void {\n\tif (movedWorktree != null) {\n\t\tentry.hooks.onRepoChanged(entry.repoPath, changes, ref, undefined, undefined, movedWorktree);\n\t} else {\n\t\tentry.hooks.onRepoChanged(entry.repoPath, changes, ref);\n\t}\n}\n\n/** The path doesn't exist: Node's error, or the one VS Code's file system raises */\nexport function isNotFound(ex: unknown): boolean {\n\tconst code = (ex as { code?: unknown } | undefined)?.code;\n\treturn code === 'ENOENT' || code === 'FileNotFound';\n}\n\n/** The shared `.git/config` (or the lock git writes it through), relative to the common git dir */\nfunction isConfigFile(relativePath: string): boolean {\n\treturn relativePath === 'config' || relativePath === 'config.lock';\n}\n\n/**\n * The ref a `.git`-relative path names: a loose ref (or ref directory) under `refs/`, or the `HEAD`/`ORIG_HEAD`\n * pseudo-refs. A lock file names the ref it locks; the only ones classification lets through are the pseudo-refs' and\n * `refs/stash.lock`.\n */\nfunction getChangedRef(relativePath: string): string | false | undefined {\n\tconst ref = relativePath.endsWith('.lock') ? relativePath.substring(0, relativePath.length - 5) : relativePath;\n\t// Remote config still invalidates remote and branch caches, but doesn't itself move any ref.\n\tif (ref === 'config' || ref === 'config.worktree') return false;\n\n\treturn ref.startsWith('refs/') || ref === 'HEAD' || ref === 'ORIG_HEAD' ? ref : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,MAAM,gBAAgB;;;;;AAMtB,MAAM,0BAA0B;;;;;AAMhC,MAAM,uBAAuB;AAE7B,SAAS,OAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqGvB,IAAa,aAAb,MAAqD;CAwE1C;CACQ;CAEA;CAKA;CAKA;CApFlB,4BAA6B,IAAI,IAA0B;CAC3D;CACA,qBAAqD;CACrD;CACA,YAAoB;;CAGpB;;CAEA,oBAA4B;CAC5B,iBAAyB;CACzB,sBAA8B;;;;;CAM9B;;CA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AChE,IAAI,iBAAiB,aAAa,OAAO,CAAC,aAAa,cAAc;CAErE,MAAM,QAAQ,aAAa,QAAQ,KAAK,EAAE;CAC1C,IAAI,UAAU,IAAI,OAAO,WAAW,YAAY,WAAW,WAAW,CAAC,aAAa,cAAc,IAAI;CAEtG,OAAO,WAAW,YAAY,aAAa,UAAU,QAAQ,CAAC,MAAM,WACjE,CAAC,aAAa,cAAc,IAC5B;AACJ;;AAGA,SAAS,mBAAmB,cAA0C;CACrE,MAAM,QAAQ,uBAAuB,YAAY;CACjD,OAAO,OAAO,SAAS,SAAS,MAAM,KAAK,KAAA;AAC5C;;;;;AAMA,SAAS,sBACR,cACA,SACqB;CACrB,OAAO,SAAS,SAAS,cAAc,IAAI,uBAAuB,YAAY,CAAC,EAAE,KAAK,KAAA;AACvF;;AAGA,SAAS,mBACR,OACA,SACA,KACA,eACO;CACP,IAAI,iBAAiB,MACpB,MAAM,MAAM,cAAc,MAAM,UAAU,SAAS,KAAK,KAAA,GAAW,KAAA,GAAW,aAAa;MAE3F,MAAM,MAAM,cAAc,MAAM,UAAU,SAAS,GAAG;AAExD;;AAGA,SAAgB,WAAW,IAAsB;CAChD,MAAM,OAAQ,IAAuC;CACrD,OAAO,SAAS,YAAY,SAAS;AACtC;;AAGA,SAAS,aAAa,cAA+B;CACpD,OAAO,iBAAiB,YAAY,iBAAiB;AACtD;;;;;;AAOA,SAAS,cAAc,cAAkD;CACxE,MAAM,MAAM,aAAa,SAAS,OAAO,IAAI,aAAa,UAAU,GAAG,aAAa,SAAS,CAAC,IAAI;CAElG,IAAI,QAAQ,YAAY,QAAQ,mBAAmB,OAAO;CAE1D,OAAO,IAAI,WAAW,OAAO,KAAK,QAAQ,UAAU,QAAQ,cAAc,MAAM,KAAA;AACjF"}
|
|
@@ -141,6 +141,18 @@ export declare class RepositoryWatchService implements UnifiedDisposable {
|
|
|
141
141
|
repoPath: string;
|
|
142
142
|
mode: 'events' | 'poll';
|
|
143
143
|
}>;
|
|
144
|
+
private readonly _onDidChangeRepoWatched;
|
|
145
|
+
/**
|
|
146
|
+
* Fires as a repository's `.git` directory starts being watched (its session's first repo subscriber connected it
|
|
147
|
+
* to its watch group) and as it stops (its last one left, or its session was disposed); see {@link isRepoWatched}.
|
|
148
|
+
* `repoPath` is the session's key ({@link getRepositoryKey}). Never fires as the service itself is disposed, nor as
|
|
149
|
+
* the session suspends or resumes: a suspended session still reports what it held once it resumes, so there is
|
|
150
|
+
* nothing to hand off, and {@link isRepoWatched} answers `false` meanwhile without announcing it.
|
|
151
|
+
*/
|
|
152
|
+
get onDidChangeRepoWatched(): Event<{
|
|
153
|
+
repoPath: string;
|
|
154
|
+
watched: boolean;
|
|
155
|
+
}>;
|
|
144
156
|
private readonly defaultRepoDelayMs?;
|
|
145
157
|
private readonly defaultWorkingTreeDelayMs?;
|
|
146
158
|
private readonly defaultRepoMaxWaitMs?;
|
|
@@ -184,11 +196,22 @@ export declare class RepositoryWatchService implements UnifiedDisposable {
|
|
|
184
196
|
* Core announced one of its own writes for `repoPath`; the session watching it fires the announcement in place of
|
|
185
197
|
* the write's own `.git` events (see {@link RepositoryWatchSession.noteSelfWrite}); `refs` are the full ref names it
|
|
186
198
|
* moved, when it knows them, and `options.configConfinedToRefs` confines its `config` change to the sections of the
|
|
187
|
-
* local branches among them (see `GitServiceHooks.repository.onChanged`).
|
|
199
|
+
* local branches among them (see `GitServiceHooks.repository.onChanged`); `options.movedWorktrees` confines its
|
|
200
|
+
* `worktreeHead` change to those linked worktrees (see `AnnouncedRepositoryChanges.movedWorktrees`). A path no session
|
|
201
|
+
* watches is ignored.
|
|
188
202
|
*/
|
|
189
203
|
noteSelfWrite(repoPath: string, changes: readonly RepositoryChange[], refs?: readonly string[], options?: {
|
|
190
204
|
readonly configConfinedToRefs?: boolean;
|
|
205
|
+
readonly movedWorktrees?: readonly string[];
|
|
191
206
|
}): void;
|
|
207
|
+
/**
|
|
208
|
+
* Whether `repoPath`'s `.git` directory is watched: its session has a repo subscriber, so it is connected to its
|
|
209
|
+
* watch group (natively, or polled in place of a watcher that can't be trusted). A session with only working-tree
|
|
210
|
+
* subscribers, or none, doesn't count, nor does a suspended one: it holds what its watcher hears until it resumes,
|
|
211
|
+
* and the poller doesn't poll meanwhile, so a read is served stale. Suspending or resuming announces nothing (see
|
|
212
|
+
* {@link onDidChangeRepoWatched}).
|
|
213
|
+
*/
|
|
214
|
+
isRepoWatched(repoPath: string): boolean;
|
|
192
215
|
/** Get an existing session by repo path */
|
|
193
216
|
getSession(repoPath: string): RepositoryWatchSession | undefined;
|
|
194
217
|
/**
|
|
@@ -212,6 +235,9 @@ export declare class RepositoryWatchService implements UnifiedDisposable {
|
|
|
212
235
|
private maybeDisposeWatchGroup;
|
|
213
236
|
private connectToWatchGroup;
|
|
214
237
|
private disconnectFromWatchGroup;
|
|
238
|
+
private isConnected;
|
|
239
|
+
/** Announces that `record` was just connected (`watched`) or disconnected, once that is what it is */
|
|
240
|
+
private fireRepoWatchedIfConnected;
|
|
215
241
|
private computeWatchMode;
|
|
216
242
|
private updateWatchMode;
|
|
217
243
|
private startWorkingTreeWatcher;
|
|
@@ -55,6 +55,17 @@ var RepositoryWatchService = class {
|
|
|
55
55
|
get onDidChangeWatchMode() {
|
|
56
56
|
return this._onDidChangeWatchMode.event;
|
|
57
57
|
}
|
|
58
|
+
_onDidChangeRepoWatched = new Emitter();
|
|
59
|
+
/**
|
|
60
|
+
* Fires as a repository's `.git` directory starts being watched (its session's first repo subscriber connected it
|
|
61
|
+
* to its watch group) and as it stops (its last one left, or its session was disposed); see {@link isRepoWatched}.
|
|
62
|
+
* `repoPath` is the session's key ({@link getRepositoryKey}). Never fires as the service itself is disposed, nor as
|
|
63
|
+
* the session suspends or resumes: a suspended session still reports what it held once it resumes, so there is
|
|
64
|
+
* nothing to hand off, and {@link isRepoWatched} answers `false` meanwhile without announcing it.
|
|
65
|
+
*/
|
|
66
|
+
get onDidChangeRepoWatched() {
|
|
67
|
+
return this._onDidChangeRepoWatched.event;
|
|
68
|
+
}
|
|
58
69
|
defaultRepoDelayMs;
|
|
59
70
|
defaultWorkingTreeDelayMs;
|
|
60
71
|
defaultRepoMaxWaitMs;
|
|
@@ -108,6 +119,7 @@ var RepositoryWatchService = class {
|
|
|
108
119
|
this._onDidChangeWorkingTree.dispose();
|
|
109
120
|
this._onDidChangeFetchHead.dispose();
|
|
110
121
|
this._onDidChangeWatchMode.dispose();
|
|
122
|
+
this._onDidChangeRepoWatched.dispose();
|
|
111
123
|
}
|
|
112
124
|
/**
|
|
113
125
|
* Start watching a repository. Reference-counted:
|
|
@@ -195,12 +207,25 @@ var RepositoryWatchService = class {
|
|
|
195
207
|
* Core announced one of its own writes for `repoPath`; the session watching it fires the announcement in place of
|
|
196
208
|
* the write's own `.git` events (see {@link RepositoryWatchSession.noteSelfWrite}); `refs` are the full ref names it
|
|
197
209
|
* moved, when it knows them, and `options.configConfinedToRefs` confines its `config` change to the sections of the
|
|
198
|
-
* local branches among them (see `GitServiceHooks.repository.onChanged`).
|
|
210
|
+
* local branches among them (see `GitServiceHooks.repository.onChanged`); `options.movedWorktrees` confines its
|
|
211
|
+
* `worktreeHead` change to those linked worktrees (see `AnnouncedRepositoryChanges.movedWorktrees`). A path no session
|
|
212
|
+
* watches is ignored.
|
|
199
213
|
*/
|
|
200
214
|
noteSelfWrite(repoPath, changes, refs, options) {
|
|
201
215
|
if (this._disposed) return;
|
|
202
216
|
this.sessionMap.get(getRepositoryKey(repoPath))?.session.noteSelfWrite(changes, refs, options);
|
|
203
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Whether `repoPath`'s `.git` directory is watched: its session has a repo subscriber, so it is connected to its
|
|
220
|
+
* watch group (natively, or polled in place of a watcher that can't be trusted). A session with only working-tree
|
|
221
|
+
* subscribers, or none, doesn't count, nor does a suspended one: it holds what its watcher hears until it resumes,
|
|
222
|
+
* and the poller doesn't poll meanwhile, so a read is served stale. Suspending or resuming announces nothing (see
|
|
223
|
+
* {@link onDidChangeRepoWatched}).
|
|
224
|
+
*/
|
|
225
|
+
isRepoWatched(repoPath) {
|
|
226
|
+
const record = this.sessionMap.get(getRepositoryKey(repoPath));
|
|
227
|
+
return record != null && this.isConnected(record) && !record.session.suspended;
|
|
228
|
+
}
|
|
204
229
|
/** Get an existing session by repo path */
|
|
205
230
|
getSession(repoPath) {
|
|
206
231
|
return this.sessionMap.get(getRepositoryKey(repoPath))?.session;
|
|
@@ -266,10 +291,11 @@ var RepositoryWatchService = class {
|
|
|
266
291
|
connectToWatchGroup(record) {
|
|
267
292
|
const { session, gitDir, watchHooks } = record;
|
|
268
293
|
const commonGitDir = (gitDir.commonUri ?? gitDir.uri).fsPath;
|
|
269
|
-
this.getOrCreateWatchGroup(commonGitDir, session.repoPath)
|
|
270
|
-
|
|
294
|
+
const group = this.getOrCreateWatchGroup(commonGitDir, session.repoPath);
|
|
295
|
+
const hooks = {
|
|
296
|
+
onRepoChanged: (_repoPath, changes, ref, overflow, configBranches, movedWorktree) => {
|
|
271
297
|
if (overflow) session.pushUnfencedRepoChanges(changes);
|
|
272
|
-
else session.pushRepoChanges(changes, ref, configBranches);
|
|
298
|
+
else session.pushRepoChanges(changes, ref, configBranches, movedWorktree);
|
|
273
299
|
if (this.poller != null && (changes.includes("index") || changes.includes("head")) && this.wtWatchers.get(session.repoPath)?.reliability === "unwatchable") session.pushWorkingTreeChanges([], true);
|
|
274
300
|
},
|
|
275
301
|
onFetchHeadChanged: (repoPath) => {
|
|
@@ -286,17 +312,33 @@ var RepositoryWatchService = class {
|
|
|
286
312
|
return refs;
|
|
287
313
|
},
|
|
288
314
|
onUnwatchableChanged: () => this.updateWatchMode(record)
|
|
289
|
-
}
|
|
315
|
+
};
|
|
316
|
+
const wasConnected = group.sessions.has(session.repoPath);
|
|
317
|
+
group.addSession(session.repoPath, gitDir, hooks);
|
|
290
318
|
this.updateWatchMode(record);
|
|
319
|
+
if (!wasConnected) this.fireRepoWatchedIfConnected(record, true);
|
|
291
320
|
}
|
|
292
321
|
disconnectFromWatchGroup(record) {
|
|
293
322
|
const { session, gitDir } = record;
|
|
294
323
|
const commonGitDir = (gitDir.commonUri ?? gitDir.uri).fsPath;
|
|
295
324
|
const group = this.watchGroups.get(commonGitDir);
|
|
296
325
|
if (group == null) return;
|
|
326
|
+
const wasConnected = group.sessions.has(session.repoPath);
|
|
297
327
|
group.removeSession(session.repoPath);
|
|
298
328
|
this.maybeDisposeWatchGroup(commonGitDir);
|
|
299
329
|
this.updateWatchMode(record);
|
|
330
|
+
if (wasConnected) this.fireRepoWatchedIfConnected(record, false);
|
|
331
|
+
}
|
|
332
|
+
isConnected(record) {
|
|
333
|
+
return this.watchGroups.get((record.gitDir.commonUri ?? record.gitDir.uri).fsPath)?.sessions.has(record.session.repoPath) ?? false;
|
|
334
|
+
}
|
|
335
|
+
/** Announces that `record` was just connected (`watched`) or disconnected, once that is what it is */
|
|
336
|
+
fireRepoWatchedIfConnected(record, watched) {
|
|
337
|
+
if (this._disposed || this.isConnected(record) !== watched) return;
|
|
338
|
+
this._onDidChangeRepoWatched.fire({
|
|
339
|
+
repoPath: record.session.repoPath,
|
|
340
|
+
watched
|
|
341
|
+
});
|
|
300
342
|
}
|
|
301
343
|
computeWatchMode(record) {
|
|
302
344
|
const repoPath = record.session.repoPath;
|
|
@@ -332,18 +374,19 @@ var RepositoryWatchService = class {
|
|
|
332
374
|
let buffered = filter != null ? [] : void 0;
|
|
333
375
|
let bufferIncomplete = false;
|
|
334
376
|
const revalidated = filter?.revalidate();
|
|
335
|
-
if (filter != null)
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
377
|
+
if (filter != null) {
|
|
378
|
+
const replay = () => {
|
|
379
|
+
const pending = buffered;
|
|
380
|
+
const incomplete = bufferIncomplete;
|
|
381
|
+
filterReady = true;
|
|
382
|
+
buffered = void 0;
|
|
383
|
+
bufferIncomplete = false;
|
|
384
|
+
if (!pending?.length) return;
|
|
385
|
+
const paths = filterWorkingTreePaths(pending, repoPath, filter);
|
|
386
|
+
if (paths.length > 0 || incomplete) session.pushWorkingTreeChanges(paths, incomplete);
|
|
387
|
+
};
|
|
388
|
+
filter.ready().then(replay, replay).catch(() => {});
|
|
389
|
+
}
|
|
347
390
|
const onIgnoreRulesChanged = (refreshFilter) => {
|
|
348
391
|
if (refreshFilter && filter != null) filter.refresh();
|
|
349
392
|
if (entry != null) this.scheduleIgnoredDirectoriesRefresh(entry);
|