@gitkraken/core-gitlens 0.33.0 → 0.35.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.
Files changed (113) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/dist/git/cache.d.ts +31 -0
  3. package/dist/git/cache.js +101 -30
  4. package/dist/git/cache.js.map +1 -1
  5. package/dist/git/context.d.ts +3 -1
  6. package/dist/git/context.js.map +1 -1
  7. package/dist/git/errors.d.ts +3 -1
  8. package/dist/git/errors.js +4 -1
  9. package/dist/git/errors.js.map +1 -1
  10. package/dist/git/models/pullRequest.d.ts +90 -1
  11. package/dist/git/models/pullRequest.js +18 -2
  12. package/dist/git/models/pullRequest.js.map +1 -1
  13. package/dist/git/providers/shared/remotes.js +2 -0
  14. package/dist/git/providers/shared/remotes.js.map +1 -1
  15. package/dist/git/utils/pullRequest.utils.d.ts +72 -1
  16. package/dist/git/utils/pullRequest.utils.js +99 -1
  17. package/dist/git/utils/pullRequest.utils.js.map +1 -1
  18. package/dist/git/utils/repository.utils.d.ts +6 -0
  19. package/dist/git/utils/repository.utils.js +14 -2
  20. package/dist/git/utils/repository.utils.js.map +1 -1
  21. package/dist/git/watching/gitDirPoller.d.ts +10 -1
  22. package/dist/git/watching/gitDirPoller.js +9 -3
  23. package/dist/git/watching/gitDirPoller.js.map +1 -1
  24. package/dist/git/watching/unwatchedCacheValidator.d.ts +144 -0
  25. package/dist/git/watching/unwatchedCacheValidator.js +884 -0
  26. package/dist/git/watching/unwatchedCacheValidator.js.map +1 -0
  27. package/dist/git/watching/watchGroup.d.ts +2 -0
  28. package/dist/git/watching/watchGroup.js +4 -8
  29. package/dist/git/watching/watchGroup.js.map +1 -1
  30. package/dist/git/watching/watchService.d.ts +23 -0
  31. package/dist/git/watching/watchService.js +42 -2
  32. package/dist/git/watching/watchService.js.map +1 -1
  33. package/dist/git/watching/watchSession.d.ts +2 -0
  34. package/dist/git/watching/watchSession.js +3 -2
  35. package/dist/git/watching/watchSession.js.map +1 -1
  36. package/dist/git-cli/cliGitProvider.js +1 -1
  37. package/dist/git-cli/cliGitProvider.js.map +1 -1
  38. package/dist/git-cli/exec/commandClassifier.d.ts +31 -1
  39. package/dist/git-cli/exec/commandClassifier.js +67 -16
  40. package/dist/git-cli/exec/commandClassifier.js.map +1 -1
  41. package/dist/git-cli/exec/git.d.ts +46 -2
  42. package/dist/git-cli/exec/git.js +80 -7
  43. package/dist/git-cli/exec/git.js.map +1 -1
  44. package/dist/git-cli/exec/gitDirResolver.d.ts +11 -0
  45. package/dist/git-cli/exec/gitDirResolver.js +34 -1
  46. package/dist/git-cli/exec/gitDirResolver.js.map +1 -1
  47. package/dist/git-cli/exec/gitQueue.js +2 -28
  48. package/dist/git-cli/exec/gitQueue.js.map +1 -1
  49. package/dist/git-cli/providers/branches.d.ts +1 -0
  50. package/dist/git-cli/providers/branches.js +6 -0
  51. package/dist/git-cli/providers/branches.js.map +1 -1
  52. package/dist/git-cli/providers/config.d.ts +13 -1
  53. package/dist/git-cli/providers/config.js +48 -14
  54. package/dist/git-cli/providers/config.js.map +1 -1
  55. package/dist/git-cli/providers/pausedOperations.d.ts +1 -0
  56. package/dist/git-cli/providers/pausedOperations.js +4 -0
  57. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  58. package/dist/git-cli/providers/revision.js +2 -0
  59. package/dist/git-cli/providers/revision.js.map +1 -1
  60. package/dist/git-cli/providers/worktrees.js +2 -0
  61. package/dist/git-cli/providers/worktrees.js.map +1 -1
  62. package/dist/git-cli/service.d.ts +25 -1
  63. package/dist/git-cli/service.js +45 -0
  64. package/dist/git-cli/service.js.map +1 -1
  65. package/dist/plus/ai/errors.d.ts +8 -2
  66. package/dist/plus/ai/errors.js +15 -3
  67. package/dist/plus/ai/errors.js.map +1 -1
  68. package/dist/plus/git-github/api/config.d.ts +11 -0
  69. package/dist/plus/git-github/api/config.js.map +1 -1
  70. package/dist/plus/git-github/api/github.d.ts +82 -1
  71. package/dist/plus/git-github/api/github.js +304 -7
  72. package/dist/plus/git-github/api/github.js.map +1 -1
  73. package/dist/plus/git-github/models.d.ts +61 -1
  74. package/dist/plus/git-github/models.js +49 -3
  75. package/dist/plus/git-github/models.js.map +1 -1
  76. package/dist/plus/integrations/context.d.ts +12 -0
  77. package/dist/plus/integrations/fieldPresence.d.ts +16 -1
  78. package/dist/plus/integrations/fieldPresence.js +37 -10
  79. package/dist/plus/integrations/fieldPresence.js.map +1 -1
  80. package/dist/plus/integrations/integrationService.d.ts +12 -0
  81. package/dist/plus/integrations/integrationService.js +4 -0
  82. package/dist/plus/integrations/integrationService.js.map +1 -1
  83. package/dist/plus/integrations/manager.d.ts +38 -0
  84. package/dist/plus/integrations/models/gitHostIntegration.d.ts +41 -1
  85. package/dist/plus/integrations/models/gitHostIntegration.js +51 -0
  86. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  87. package/dist/plus/integrations/models/integration.d.ts +23 -2
  88. package/dist/plus/integrations/models/integration.js.map +1 -1
  89. package/dist/plus/integrations/providers/github/github.js +2 -1
  90. package/dist/plus/integrations/providers/github/github.js.map +1 -1
  91. package/dist/plus/integrations/providers/github.d.ts +21 -1
  92. package/dist/plus/integrations/providers/github.js +71 -6
  93. package/dist/plus/integrations/providers/github.js.map +1 -1
  94. package/dist/plus/integrations/reads/context.d.ts +7 -0
  95. package/dist/plus/integrations/reads/drains.d.ts +1 -1
  96. package/dist/plus/integrations/reads/drains.js +2 -1
  97. package/dist/plus/integrations/reads/drains.js.map +1 -1
  98. package/dist/plus/integrations/reads/etag.js +13 -0
  99. package/dist/plus/integrations/reads/etag.js.map +1 -1
  100. package/dist/plus/integrations/reads/pullRequestBatch.d.ts +6 -2
  101. package/dist/plus/integrations/reads/pullRequestBatch.js +9 -2
  102. package/dist/plus/integrations/reads/pullRequestBatch.js.map +1 -1
  103. package/dist/plus/integrations/reads/pullRequestBranches.d.ts +2 -0
  104. package/dist/plus/integrations/reads/pullRequestBranches.js +3 -1
  105. package/dist/plus/integrations/reads/pullRequestBranches.js.map +1 -1
  106. package/dist/plus/integrations/reads/pullRequests.d.ts +2 -0
  107. package/dist/plus/integrations/reads/pullRequests.js +2 -1
  108. package/dist/plus/integrations/reads/pullRequests.js.map +1 -1
  109. package/dist/plus/integrations/reads/searchPullRequests.d.ts +2 -0
  110. package/dist/plus/integrations/reads/searchPullRequests.js +2 -1
  111. package/dist/plus/integrations/reads/searchPullRequests.js.map +1 -1
  112. package/docs/integrations.md +77 -15
  113. package/package.json +1 -1
@@ -0,0 +1,884 @@
1
+ import { raceWithTimeout } from "../../utils/cancellation.js";
2
+ import { joinPaths } from "../../utils/path.js";
3
+ import { isIgnoredWorktreeEntry, parseWorktreeAdminPath } from "../utils/repository.utils.js";
4
+ import { FileType } from "../context.js";
5
+ import { GitDirProbeTarget } from "./gitDirPoller.js";
6
+ import { gitDirCommonProbes, gitDirRootProbes } from "./watcherPatterns.js";
7
+ import { allWatchedRepositoryChanges, classifyGitDirChange } from "./classifyChange.js";
8
+ import { isNotFound } from "./watchGroup.js";
9
+ import "./watchSession.js";
10
+ //#region ../git/src/watching/unwatchedCacheValidator.ts
11
+ /** The reading of a path whose stat failed; never a whole second, so never racy */
12
+ const unreadable = {
13
+ mtime: -1,
14
+ size: -1
15
+ };
16
+ /**
17
+ * A target read within this long of its last validation is served as is: a watched repository's read is as stale, as
18
+ * its watch session debounces what its watcher reports by as much
19
+ */
20
+ const validationWindowMs = 250;
21
+ /**
22
+ * How long a repository whose files can't show its git dir (a bare repository, a submodule) is left before they are
23
+ * looked at again. Any read that resolves its git dir with git makes the lookup unneeded
24
+ */
25
+ const unresolvableRetryMs = 3e4;
26
+ /** Targets kept per kind; one dropped just takes a new baseline */
27
+ const maxTargets = 512;
28
+ /** Polls one validation runs to take the baselines of the directories it finds; the next validation resumes from there */
29
+ const maxDiscoveryPolls = 16;
30
+ /**
31
+ * How long a reading stays racy on a file system whose timestamps tick by whole seconds (or two, as FAT's): a write in
32
+ * the same second as the stat leaves the same mtime. Counted both from the mtime and from when the validator first saw
33
+ * the reading, as a server whose clock runs ahead of ours stamps writes with a second that ends, on our clock, no later
34
+ * than this long after we first saw it
35
+ */
36
+ const racyMtimeWindowMs = 2e3;
37
+ /** Racy candidates whose first sighting is remembered; the oldest is dropped past it, which only extends its raciness */
38
+ const maxRacyReadings = maxTargets * 8;
39
+ /** How long a read waits for a validation before it's served from the cache as is */
40
+ const defaultValidationTimeoutMs = 1e3;
41
+ /** The longest delay `setTimeout` keeps; a longer one (`Infinity` included) fires at once */
42
+ const maxValidationTimeoutMs = 2 ** 31 - 1;
43
+ /**
44
+ * A stat or listing holds one of Node's file-system threads (libuv's pool, 4 by default) until it returns, which on a
45
+ * hung mount is never, as it can't be cancelled. A repository makes one at a time and the validator two, holding no more
46
+ * threads than it's allowed counting those outstanding past the timeout
47
+ */
48
+ const maxFsCallsPerRepo = 1;
49
+ const maxFsCalls = 2;
50
+ const defaultMaxFsThreads = 2;
51
+ const refNamespaces = [
52
+ "refs/heads",
53
+ "refs/remotes",
54
+ "refs/tags"
55
+ ];
56
+ const reftableProbePath = "reftable/tables.list";
57
+ const worktreeHeadRegex = /^worktrees\/([^/]+)\/(?:HEAD|reftable\/tables\.list)$/;
58
+ /**
59
+ * The git dir itself, as the gate of the files in it that git writes by lockfile and rename, or creates and deletes:
60
+ * either moves the directory's mtime, so its reading stands in for theirs, which are read only once it moved. Each
61
+ * gate's files have a probe target of their own, whose readings outlast the validations that skip it; were they left
62
+ * out of a shared target instead, their next reading would be a new baseline, losing what changed meanwhile. What git
63
+ * writes in place (`FETCH_HEAD`, an admin entry's `gitdir`, the rebase and sequencer state `--edit-todo` rewrites) is
64
+ * read every time. This saves stats only while the gate holds still: an index write moves the git dir too, so an
65
+ * active checkout reads as much as ever, and an idle one, as unwatched repositories mostly are, reads just the gate.
66
+ */
67
+ const gitDirGatePath = "";
68
+ const rootGatedPaths = /* @__PURE__ */ new Set([
69
+ "HEAD",
70
+ "ORIG_HEAD",
71
+ "MERGE_HEAD",
72
+ "CHERRY_PICK_HEAD",
73
+ "REVERT_HEAD",
74
+ "REBASE_HEAD"
75
+ ]);
76
+ const commonGatedPaths = /* @__PURE__ */ new Set([
77
+ "packed-refs",
78
+ "config",
79
+ "shallow"
80
+ ]);
81
+ const rootProbes = gitDirRootProbes.filter((p) => p.path !== "index");
82
+ const rootAlwaysProbes = [
83
+ { path: gitDirGatePath },
84
+ ...rootProbes.filter((p) => !rootGatedPaths.has(p.path)),
85
+ { path: reftableProbePath }
86
+ ];
87
+ const rootGatedProbes = rootProbes.filter((p) => rootGatedPaths.has(p.path));
88
+ /**
89
+ * What a worktree's own git dir can report, which is all its validation without a baseline reports: the shared kinds
90
+ * are the common git dir's to report, from a baseline of its own, or by another worktree's watcher that covers it
91
+ */
92
+ const rootReportableChanges = [...new Set([...rootAlwaysProbes, ...rootGatedProbes].flatMap((p) => {
93
+ if (p.path === gitDirGatePath) return [];
94
+ if (p.path === reftableProbePath) return ["head", "heads"];
95
+ return (p.emitAs ?? [p.path]).flatMap((path) => classifyGitDirChange(path) ?? []);
96
+ }))];
97
+ const commonProbes = [
98
+ ...gitDirCommonProbes.filter((p) => p.path !== "info/exclude"),
99
+ { path: reftableProbePath },
100
+ {
101
+ path: "logs/refs/stash",
102
+ emitAs: ["refs/stash"]
103
+ },
104
+ { path: "refs/replace" }
105
+ ];
106
+ const commonAlwaysProbes = [{ path: gitDirGatePath }, ...commonProbes.filter((p) => !commonGatedPaths.has(p.path))];
107
+ const commonGatedProbes = commonProbes.filter((p) => commonGatedPaths.has(p.path));
108
+ /**
109
+ * Keeps the caches that never expire fresh for repositories no `.git` watcher covers: before such a read, stats the
110
+ * files a watcher would have reported (see {@link UnwatchedCacheValidatorOptions.stat}) and applies what moved to the
111
+ * cache as a watcher event would have. Both a worktree's own git dir and the common one are validated while that
112
+ * worktree is unwatched; while another worktree's watcher covers the common one, what moved there clears only the
113
+ * unwatched worktrees' own entries. A repository whose git dir nothing resolved yet is validated once
114
+ * {@link UnwatchedCacheValidatorOptions.resolveGitDir} resolves one; a repository whose files can't show it is looked at
115
+ * again rarely, and one whose resolution failed within the validation window. A read waits at most
116
+ * {@link UnwatchedCacheValidatorOptions.timeoutMs} for a validation (and a resolution before it); one that outlasts it
117
+ * is left to finish on its own, and the reads meanwhile are served as is.
118
+ */
119
+ var UnwatchedCacheValidator = class {
120
+ cache;
121
+ isWatched;
122
+ now;
123
+ timeoutMs;
124
+ resolveGitDir;
125
+ gate;
126
+ /** Since it was created; what {@link getResourceUsage} reports */
127
+ counts = {
128
+ validations: 0,
129
+ validationsApplied: 0,
130
+ waitsTimedOut: 0,
131
+ gitDirLookups: 0
132
+ };
133
+ dirOptions;
134
+ /** Keyed by repo path */
135
+ roots = /* @__PURE__ */ new Map();
136
+ /** Keyed by common path */
137
+ commons = /* @__PURE__ */ new Map();
138
+ /** Keyed by absolute path; the readings that may be racy, with when each was first read */
139
+ racyReadings = /* @__PURE__ */ new Map();
140
+ /**
141
+ * Keyed by repo path; one that found nothing is kept, so the reads meanwhile don't retry it: for the window after a
142
+ * failure, for {@link unresolvableRetryMs} after a git dir the files can't show
143
+ */
144
+ resolutions = /* @__PURE__ */ new Map();
145
+ /** The validation {@link onWatched} ran as a watcher attached, by repo path, which reads wait for while it runs */
146
+ handoffs = /* @__PURE__ */ new Map();
147
+ /** By the repo path of a watched worktree, what moved in its common git dir that its watcher was left to clear */
148
+ deferred = /* @__PURE__ */ new Map();
149
+ constructor(options) {
150
+ this.cache = options.cache;
151
+ this.isWatched = options.isWatched;
152
+ this.now = options.now ?? (() => Date.now());
153
+ this.timeoutMs = Math.min(options.timeoutMs ?? defaultValidationTimeoutMs, maxValidationTimeoutMs);
154
+ this.resolveGitDir = options.resolveGitDir;
155
+ const maxFsThreads = Math.floor(options.maxFsThreads ?? defaultMaxFsThreads);
156
+ this.gate = new FileSystemGate(this.timeoutMs, Number.isNaN(maxFsThreads) ? defaultMaxFsThreads : Math.max(1, maxFsThreads));
157
+ this.dirOptions = {
158
+ gate: this.gate,
159
+ stat: options.stat,
160
+ readDirectory: options.readDirectory,
161
+ readFile: options.readFile,
162
+ getIgnoredWorktreeRoots: options.getIgnoredWorktreeRoots,
163
+ isRacy: (stat, path) => this.isRacy(stat, path)
164
+ };
165
+ }
166
+ /**
167
+ * Whether `stat` of `path` may still show the same file a write in its own second would leave. Only a whole-second
168
+ * mtime can, and only until its second ended: by the mtime's own clock, and by ours since the reading was first
169
+ * seen, whichever comes first
170
+ */
171
+ isRacy(stat, path) {
172
+ const now = this.now();
173
+ if (stat.mtime % 1e3 !== 0 || now - stat.mtime >= racyMtimeWindowMs) {
174
+ this.racyReadings.delete(path);
175
+ return false;
176
+ }
177
+ let reading = this.racyReadings.get(path);
178
+ if (reading == null || reading.mtime !== stat.mtime || reading.size !== stat.size) {
179
+ reading = {
180
+ mtime: stat.mtime,
181
+ size: stat.size,
182
+ firstSeen: now
183
+ };
184
+ this.racyReadings.delete(path);
185
+ this.racyReadings.set(path, reading);
186
+ if (this.racyReadings.size > maxRacyReadings) {
187
+ const oldest = this.racyReadings.keys().next();
188
+ if (!oldest.done) this.racyReadings.delete(oldest.value);
189
+ }
190
+ } else {
191
+ this.racyReadings.delete(path);
192
+ this.racyReadings.set(path, reading);
193
+ if (now < reading.firstSeen) reading.firstSeen = now;
194
+ }
195
+ return now - reading.firstSeen < racyMtimeWindowMs;
196
+ }
197
+ /**
198
+ * Validates what `repoPath`'s reads would be served from, unless a watcher covers it or it was validated within
199
+ * the last 250ms. `undefined` when there's nothing to wait for; otherwise settles once what moved was applied to
200
+ * the cache, or after {@link UnwatchedCacheValidatorOptions.timeoutMs} with the cache as is, whichever is first.
201
+ * Never rejects. A path that can't be read counts as moved as it becomes unreadable and again as it becomes
202
+ * readable; a directory that can't be listed is listed again at the next validation, and what changes deeper inside
203
+ * it goes unseen until it can be.
204
+ */
205
+ validate(repoPath) {
206
+ return this.handoffs.get(repoPath) ?? this.run(repoPath, false);
207
+ }
208
+ /**
209
+ * A watcher attached to `repoPath`, so it reports only what changes from now on: validates now what changed since
210
+ * the last validation, whatever the window, and has `repoPath`'s reads wait for it.
211
+ */
212
+ onWatched(repoPath) {
213
+ const validation = this.run(repoPath, true);
214
+ if (validation == null) return;
215
+ const handoff = validation.finally(() => {
216
+ if (this.handoffs.get(repoPath) === handoff) this.handoffs.delete(repoPath);
217
+ });
218
+ this.handoffs.set(repoPath, handoff);
219
+ }
220
+ /**
221
+ * A watcher left `repoPath`, dropping what it held back unreported. What moved in its common git dir that an
222
+ * unwatched sibling's validation left to it is applied now, since that validation took the shared baseline past it;
223
+ * whatever else it dropped is still ahead of its own baselines.
224
+ */
225
+ onUnwatched(repoPath) {
226
+ const deferred = this.deferred.get(repoPath);
227
+ if (deferred == null) return;
228
+ this.deferred.delete(repoPath);
229
+ this.cache.onRepositoryChanged(deferred.commonPath, deferred.changes);
230
+ if (repoPath !== deferred.commonPath && this.cache.isRegistered(repoPath)) this.cache.applyRepositoryChanges(repoPath, deferred.changes, "share", { worktreeOnly: true });
231
+ }
232
+ run(repoPath, force) {
233
+ if (!force && this.isWatched(repoPath)) return void 0;
234
+ if (this.cache.gitDir.get(repoPath) == null) return force ? void 0 : this.resolveThenValidate(repoPath);
235
+ const waits = this.start(repoPath, force);
236
+ return waits?.length ? this.waitAtMost(waits) : void 0;
237
+ }
238
+ /** Starts validating `repoPath`, or joins the validations in flight; what a read waits for */
239
+ start(repoPath, force) {
240
+ const gitDir = this.cache.gitDir.get(repoPath);
241
+ if (gitDir == null) return void 0;
242
+ const commonPath = this.cache.getCommonPath(repoPath);
243
+ for (const [path, deferred] of this.deferred) if (deferred.commonPath === commonPath && !this.isWatched(path)) this.onUnwatched(path);
244
+ const commonGitDir = (gitDir.commonUri ?? gitDir.uri).fsPath;
245
+ const root = this.getTarget(this.roots, repoPath, "root", gitDir.uri.fsPath, commonPath, commonGitDir);
246
+ const common = this.getTarget(this.commons, commonPath, "common", commonGitDir, commonPath, commonGitDir);
247
+ const waits = [];
248
+ const previous = [];
249
+ const start = (state) => {
250
+ if (state == null) return void 0;
251
+ if (state.running != null) {
252
+ if (!force) {
253
+ if (state.slow !== state.running) waits.push([state, state.running]);
254
+ return;
255
+ }
256
+ previous.push(state.running);
257
+ } else if (!force && state.settledAt != null) {
258
+ const elapsed = this.now() - state.settledAt;
259
+ if (elapsed >= 0 && elapsed < validationWindowMs) return void 0;
260
+ }
261
+ return state;
262
+ };
263
+ const startedRoot = start(root);
264
+ const startedCommon = start(common);
265
+ if (startedRoot != null || startedCommon != null) {
266
+ const job = this.runTargets(repoPath, commonPath, startedRoot, startedCommon, previous);
267
+ if (startedRoot != null) startedRoot.running = job;
268
+ if (startedCommon != null) startedCommon.running = job;
269
+ for (const state of [startedRoot, startedCommon]) if (state != null) waits.push([state, job]);
270
+ }
271
+ return waits;
272
+ }
273
+ /**
274
+ * Resolves the git dir of `repoPath` (through the gate, as one call, keyed by `repoPath` since its common git dir
275
+ * isn't known yet), then validates it as usual within the same wait. That first validation has no baseline.
276
+ */
277
+ resolveThenValidate(repoPath) {
278
+ const resolveGitDir = this.resolveGitDir;
279
+ if (resolveGitDir == null) return void 0;
280
+ let state = this.resolutions.get(repoPath);
281
+ let running = state?.running;
282
+ if (state != null && running != null) {
283
+ if (state.slow === running) return void 0;
284
+ } else {
285
+ if (state?.settledAt != null) {
286
+ const elapsed = this.now() - state.settledAt;
287
+ if (elapsed >= 0 && elapsed < state.retryAfterMs) return void 0;
288
+ }
289
+ state = {
290
+ started: [],
291
+ retryAfterMs: validationWindowMs
292
+ };
293
+ running = this.startResolution(repoPath, resolveGitDir, state);
294
+ }
295
+ return this.waitAtMost([[state, running]]);
296
+ }
297
+ startResolution(repoPath, resolveGitDir, state) {
298
+ let found = false;
299
+ this.counts.gitDirLookups++;
300
+ const running = this.gate.run(repoPath, () => resolveGitDir(repoPath)).catch(() => void 0).then(async (resolved) => {
301
+ found = resolved === true;
302
+ if (resolved === false) state.retryAfterMs = unresolvableRetryMs;
303
+ if (!found || this.isWatched(repoPath)) return;
304
+ const waits = this.start(repoPath, false);
305
+ if (waits == null) return;
306
+ state.started.push(...waits);
307
+ await Promise.all(waits.map(([, validation]) => validation));
308
+ }).finally(() => {
309
+ state.settledAt = this.now();
310
+ state.running = void 0;
311
+ if (found && this.resolutions.get(repoPath) === state) this.resolutions.delete(repoPath);
312
+ });
313
+ state.running = running;
314
+ this.resolutions.delete(repoPath);
315
+ this.resolutions.set(repoPath, state);
316
+ if (this.resolutions.size > maxTargets) {
317
+ const oldest = this.resolutions.keys().next();
318
+ if (!oldest.done) this.resolutions.delete(oldest.value);
319
+ }
320
+ return running;
321
+ }
322
+ /**
323
+ * Settles once `waits`' validations do, or once the timeout elapses, latching those still running as slow (and what
324
+ * they started) so the reads after it don't wait for them again
325
+ */
326
+ waitAtMost(waits) {
327
+ const latch = (state, running) => {
328
+ if (state.running !== running) return;
329
+ state.slow = running;
330
+ for (const [started, startedRunning] of state.started ?? []) latch(started, startedRunning);
331
+ };
332
+ return raceWithTimeout(Promise.all(waits.map(([, running]) => running)), this.timeoutMs).then(() => void 0, () => {
333
+ this.counts.waitsTimedOut++;
334
+ for (const [state, running] of waits) latch(state, running);
335
+ });
336
+ }
337
+ /**
338
+ * What validating has cost, for a host to weigh against watching: counts since the validator was created of the
339
+ * validations run, those that cleared something, the reads served as is after their wait timed out, the git dir
340
+ * lookups, and the file-system calls made; and, as of now, the calls stuck on a hung mount and the git dirs kept
341
+ */
342
+ getResourceUsage() {
343
+ return {
344
+ "unwatchedValidation.validations.count": this.counts.validations,
345
+ "unwatchedValidation.validationsApplied.count": this.counts.validationsApplied,
346
+ "unwatchedValidation.waitsTimedOut.count": this.counts.waitsTimedOut,
347
+ "unwatchedValidation.gitDirLookups.count": this.counts.gitDirLookups,
348
+ "unwatchedValidation.fsCalls.count": this.gate.calls,
349
+ "unwatchedValidation.fsCallsStuck.count": this.gate.stuckCalls,
350
+ "unwatchedValidation.gitDirs.count": this.roots.size + this.commons.size
351
+ };
352
+ }
353
+ /** The repository's other worktrees whose watchers cover its common git dir */
354
+ getCommonWatchers(repoPath, commonPath) {
355
+ const watchers = /* @__PURE__ */ new Set();
356
+ if (commonPath !== repoPath && this.isWatched(commonPath)) watchers.add(commonPath);
357
+ for (const path of this.cache.getWorktreePaths(commonPath)) if (path !== repoPath && this.isWatched(path)) watchers.add(path);
358
+ return [...watchers];
359
+ }
360
+ getTarget(targets, key, kind, basePath, commonPath, commonGitDir) {
361
+ let state = targets.get(key);
362
+ if (state?.dir.basePath === basePath && state.dir.commonPath === commonPath) targets.delete(key);
363
+ else state = {
364
+ dir: new ProbedGitDir(kind, basePath, commonPath, commonGitDir, this.dirOptions),
365
+ runs: 0
366
+ };
367
+ targets.set(key, state);
368
+ if (targets.size > maxTargets) {
369
+ const oldest = targets.keys().next();
370
+ if (!oldest.done) targets.delete(oldest.value);
371
+ }
372
+ return state;
373
+ }
374
+ async runTargets(repoPath, commonPath, root, common, previous) {
375
+ const rootRun = root != null ? ++root.runs : 0;
376
+ const commonRun = common != null ? ++common.runs : 0;
377
+ const watchedAtStart = new Set(this.getCommonWatchers(repoPath, commonPath));
378
+ try {
379
+ if (previous.length) await Promise.all(previous);
380
+ const memo = /* @__PURE__ */ new Map();
381
+ const [rootResult, commonResult] = await Promise.all([root?.dir.validate(memo, repoPath), common?.dir.validate(memo, repoPath)]);
382
+ this.counts.validations++;
383
+ if (rootResult?.changes.size || commonResult?.changes.size) this.counts.validationsApplied++;
384
+ this.apply(repoPath, commonPath, rootResult, commonResult, watchedAtStart);
385
+ } catch {} finally {
386
+ const settledAt = this.now();
387
+ if (root != null) {
388
+ root.settledAt = settledAt;
389
+ if (root.runs === rootRun) root.running = void 0;
390
+ }
391
+ if (common != null) {
392
+ common.settledAt = settledAt;
393
+ if (common.runs === commonRun) common.running = void 0;
394
+ }
395
+ }
396
+ }
397
+ /**
398
+ * Applies what moved to `repoPath`, and what moved in the common git dir to its other unwatched registered worktrees
399
+ * too, as the common watcher would have told each of them. While another worktree's watcher covers the common git
400
+ * dir, it already cleared the shared entries, so only the worktrees' own are. A watcher covers it only if it watched
401
+ * since before the stats began (`watchedAtStart`)
402
+ */
403
+ apply(repoPath, commonPath, root, common, watchedAtStart) {
404
+ const watchers = this.getCommonWatchers(repoPath, commonPath).filter((p) => watchedAtStart.has(p));
405
+ const commonWatched = watchers.length !== 0;
406
+ const changes = new Set(root?.changes);
407
+ if (!commonWatched) for (const change of common?.changes ?? []) changes.add(change);
408
+ if (changes.size) this.cache.onRepositoryChanged(repoPath, changes, { movedWorktrees: changes.has("worktreeHead") ? common?.movedWorktrees : void 0 });
409
+ if (!common?.changes.size) return;
410
+ if (commonWatched) {
411
+ this.cache.applyRepositoryChanges(repoPath, common.changes, "share", { worktreeOnly: true });
412
+ for (const path of watchers) {
413
+ let deferred = this.deferred.get(path);
414
+ if (deferred?.commonPath !== commonPath) {
415
+ deferred = {
416
+ commonPath,
417
+ changes: /* @__PURE__ */ new Set()
418
+ };
419
+ this.deferred.set(path, deferred);
420
+ }
421
+ for (const change of common.changes) deferred.changes.add(change);
422
+ }
423
+ }
424
+ for (const path of this.cache.getWorktreePaths(commonPath)) {
425
+ if (path === repoPath || watchers.includes(path)) continue;
426
+ this.cache.applyRepositoryChanges(path, common.changes, "share", { worktreeOnly: true });
427
+ }
428
+ }
429
+ };
430
+ /**
431
+ * Runs file-system calls at most {@link maxFsCalls} at once, and at most {@link maxFsCallsPerRepo} at once for a key;
432
+ * the calls waiting start in the order they came, skipping those whose key is busy. A call outstanding past the
433
+ * timeout is stuck, as on a hung mount: it stops counting against {@link maxFsCalls}, so other keys' calls go on, but
434
+ * keeps its key busy and holds one of the threads the gate is allowed until it returns
435
+ */
436
+ var FileSystemGate = class {
437
+ timeoutMs;
438
+ maxThreads;
439
+ /** The keys with calls in flight, by how many */
440
+ busy = /* @__PURE__ */ new Map();
441
+ waiting = [];
442
+ active = 0;
443
+ stuck = 0;
444
+ /** The calls made since it was created */
445
+ calls = 0;
446
+ constructor(timeoutMs, maxThreads) {
447
+ this.timeoutMs = timeoutMs;
448
+ this.maxThreads = maxThreads;
449
+ }
450
+ async run(key, call) {
451
+ if (this.canStart(key)) this.acquire(key);
452
+ else await new Promise((resolve) => this.waiting.push({
453
+ key,
454
+ start: resolve
455
+ }));
456
+ this.calls++;
457
+ let stuck = false;
458
+ const timer = setTimeout(() => {
459
+ stuck = true;
460
+ this.active--;
461
+ this.stuck++;
462
+ this.drain();
463
+ }, this.timeoutMs);
464
+ if (typeof timer !== "number") timer.unref();
465
+ try {
466
+ return await call();
467
+ } finally {
468
+ if (stuck) this.stuck--;
469
+ else {
470
+ clearTimeout(timer);
471
+ this.active--;
472
+ }
473
+ this.release(key);
474
+ }
475
+ }
476
+ /** The calls outstanding past the timeout */
477
+ get stuckCalls() {
478
+ return this.stuck;
479
+ }
480
+ hasSlot() {
481
+ return this.active < maxFsCalls && this.active + this.stuck < this.maxThreads;
482
+ }
483
+ canStart(key) {
484
+ return this.hasSlot() && (this.busy.get(key) ?? 0) < maxFsCallsPerRepo;
485
+ }
486
+ acquire(key) {
487
+ this.active++;
488
+ this.busy.set(key, (this.busy.get(key) ?? 0) + 1);
489
+ }
490
+ release(key) {
491
+ const count = (this.busy.get(key) ?? 1) - 1;
492
+ if (count > 0) this.busy.set(key, count);
493
+ else this.busy.delete(key);
494
+ this.drain();
495
+ }
496
+ drain() {
497
+ let i = 0;
498
+ while (i < this.waiting.length && this.hasSlot()) {
499
+ const waiter = this.waiting[i];
500
+ if (!this.canStart(waiter.key)) {
501
+ i++;
502
+ continue;
503
+ }
504
+ this.waiting.splice(i, 1);
505
+ this.acquire(waiter.key);
506
+ waiter.start();
507
+ }
508
+ }
509
+ };
510
+ /**
511
+ * The readings of one git dir: a worktree's own (`root`), or the common one, whose ref directories and worktree admin
512
+ * entries it finds by listing them. A directory is listed only after its reading was recorded, so whatever a listing
513
+ * missed moves the directory again. A path that can't be read counts as moved as it becomes unreadable and again as it
514
+ * becomes readable; a directory that can't be listed keeps what it held and is listed again at the next validation, so
515
+ * what changes deeper inside it goes unseen until it can be. Without a baseline, a worktree's own git dir reports only
516
+ * what its probes can, the common one everything.
517
+ */
518
+ var ProbedGitDir = class {
519
+ kind;
520
+ basePath;
521
+ commonPath;
522
+ gateKey;
523
+ options;
524
+ /** The probes read every time, the gates among them */
525
+ target;
526
+ /** By the path of their gate: the git dir's own, and each admin entry's */
527
+ gated = /* @__PURE__ */ new Map();
528
+ baselined = false;
529
+ /** The directories found under the ref namespaces, which a ref created or deleted in them moves */
530
+ refDirs = /* @__PURE__ */ new Set();
531
+ /** By admin id, whether core ignores the linked worktree, which leaves only its `gitdir` probed */
532
+ worktrees = /* @__PURE__ */ new Map();
533
+ /** The probes that moved during the current validation, by path */
534
+ moved = /* @__PURE__ */ new Map();
535
+ /** The paths of the probes that moved in the last poll */
536
+ movedInPoll = /* @__PURE__ */ new Set();
537
+ /** The gates that moved during the current validation */
538
+ movedGates = /* @__PURE__ */ new Set();
539
+ /** The admin ids found during the current validation */
540
+ foundWorktrees = /* @__PURE__ */ new Set();
541
+ /** The admin ids removed during the current validation, by whether they were ignored */
542
+ removedWorktrees = /* @__PURE__ */ new Map();
543
+ /** The admin ids whose ignored status flipped during the current validation */
544
+ flippedWorktrees = /* @__PURE__ */ new Set();
545
+ /**
546
+ * The directories the next validation lists whether they moved or not: those that couldn't be listed, and those
547
+ * left at {@link maxDiscoveryPolls}
548
+ */
549
+ pendingDirs = /* @__PURE__ */ new Set();
550
+ /** The admin ids left at {@link maxDiscoveryPolls}, whose `gitdir` the next validation reads whether it moved or not */
551
+ pendingEntries = /* @__PURE__ */ new Set();
552
+ /** The common git dir's own `reftable/tables.list`; only while it's there do the admin entries have their own */
553
+ reftablePath;
554
+ /** Whether {@link reftablePath} was there at its last reading */
555
+ reftable = false;
556
+ /** The current validation's */
557
+ memo;
558
+ /** The current validation's repository, whose git dir the cache holds */
559
+ repoPath;
560
+ /** The current validation's, once a worktree needed them */
561
+ ignoredRoots;
562
+ constructor(kind, basePath, commonPath, gateKey, options) {
563
+ this.kind = kind;
564
+ this.basePath = basePath;
565
+ this.commonPath = commonPath;
566
+ this.gateKey = gateKey;
567
+ this.options = options;
568
+ this.reftablePath = kind === "common" ? joinPaths(basePath, reftableProbePath) : void 0;
569
+ this.target = this.createTarget(() => this.getProbes());
570
+ this.addGated(gitDirGatePath, kind === "root" ? rootGatedProbes : commonGatedProbes);
571
+ }
572
+ /**
573
+ * Polls the probes and answers what moved since the last validation; everything it can report when there's no
574
+ * baseline. `memo` holds the stats of the validation it's part of
575
+ */
576
+ async validate(memo, repoPath) {
577
+ this.moved.clear();
578
+ this.movedGates.clear();
579
+ this.foundWorktrees.clear();
580
+ this.removedWorktrees.clear();
581
+ this.flippedWorktrees.clear();
582
+ this.memo = memo;
583
+ this.repoPath = repoPath;
584
+ let failed = false;
585
+ try {
586
+ await this.poll();
587
+ if (this.kind === "common") await this.discover();
588
+ await this.pollGated();
589
+ } catch {
590
+ failed = true;
591
+ } finally {
592
+ this.memo = void 0;
593
+ this.repoPath = void 0;
594
+ this.ignoredRoots = void 0;
595
+ }
596
+ if (failed || !this.baselined) {
597
+ if (failed) {
598
+ this.target = this.createTarget(() => this.getProbes());
599
+ this.gated.clear();
600
+ this.addGated(gitDirGatePath, this.kind === "root" ? rootGatedProbes : commonGatedProbes);
601
+ this.baselined = false;
602
+ this.refDirs.clear();
603
+ this.worktrees.clear();
604
+ this.pendingDirs.clear();
605
+ this.pendingEntries.clear();
606
+ this.reftable = false;
607
+ } else this.baselined = true;
608
+ return {
609
+ changes: new Set(this.kind === "root" ? rootReportableChanges : allWatchedRepositoryChanges),
610
+ movedWorktrees: void 0
611
+ };
612
+ }
613
+ return this.classify();
614
+ }
615
+ createTarget(getProbes) {
616
+ return new GitDirProbeTarget(this.basePath, {
617
+ stat: (path) => this.stat(path),
618
+ invalidate: () => {}
619
+ }, getProbes, /* @__PURE__ */ new Map(), (_event, probe) => {
620
+ if (isGatePath(probe.path)) {
621
+ this.movedGates.add(probe.path);
622
+ return;
623
+ }
624
+ this.moved.set(probe.path, probe);
625
+ this.movedInPoll.add(probe.path);
626
+ }, { isRacy: this.options.isRacy });
627
+ }
628
+ addGated(gatePath, probes) {
629
+ this.gated.set(gatePath, {
630
+ target: this.createTarget(() => probes),
631
+ read: false
632
+ });
633
+ }
634
+ addWorktreeGated(id) {
635
+ this.addGated(`worktrees/${id}`, [{ path: `worktrees/${id}/HEAD` }, { path: `worktrees/${id}/locked` }]);
636
+ }
637
+ async stat(path) {
638
+ let stat = this.memo?.get(path);
639
+ if (stat == null) {
640
+ stat = this.options.gate.run(this.gateKey, () => this.options.stat(path)).catch((ex) => {
641
+ if (isNotFound(ex) || isNotADirectory(ex)) return void 0;
642
+ return unreadable;
643
+ });
644
+ this.memo?.set(path, stat);
645
+ }
646
+ const result = await stat;
647
+ if (path === this.reftablePath && result !== unreadable) this.reftable = result != null;
648
+ return result;
649
+ }
650
+ poll() {
651
+ this.movedInPoll.clear();
652
+ return this.target.poll();
653
+ }
654
+ /** Polls the files of each gate that moved during this validation, and of each never read */
655
+ async pollGated() {
656
+ const due = [...this.gated].filter(([gate, gated]) => !gated.read || this.movedGates.has(gate));
657
+ await Promise.all(due.map(async ([, gated]) => {
658
+ await gated.target.poll();
659
+ gated.read = true;
660
+ }));
661
+ }
662
+ getProbes() {
663
+ if (this.kind === "root") return [...rootAlwaysProbes];
664
+ const probes = [...commonAlwaysProbes];
665
+ for (const path of this.refDirs) probes.push({ path });
666
+ for (const [id, { ignored }] of this.worktrees) {
667
+ probes.push({ path: `worktrees/${id}/gitdir` });
668
+ if (ignored) continue;
669
+ probes.push({ path: `worktrees/${id}` });
670
+ if (this.reftable) probes.push({ path: `worktrees/${id}/${reftableProbePath}` });
671
+ }
672
+ return probes;
673
+ }
674
+ /** The listed directories that moved in the last poll */
675
+ getMovedDirs() {
676
+ return [...this.movedInPoll].filter((p) => p === "worktrees" || refNamespaces.includes(p) || this.refDirs.has(p));
677
+ }
678
+ /** The known admin ids whose `gitdir` moved in the last poll */
679
+ getMovedGitdirs() {
680
+ const ids = [];
681
+ for (const path of this.movedInPoll) {
682
+ const entry = parseWorktreeAdminPath(path);
683
+ if (entry?.file === "gitdir" && this.worktrees.has(entry.id)) ids.push(entry.id);
684
+ }
685
+ return ids;
686
+ }
687
+ /**
688
+ * Lists the directories that moved in the last poll (every one, the first time), and polls again while that finds
689
+ * new ones, so they have readings before the caches are read again: the move of the directory they're in already
690
+ * reported whatever they hold. Reads whether each admin entry new to it, or whose `gitdir` moved, is ignored, once
691
+ * that `gitdir` has a reading. Also lists what an earlier validation left: the directories it couldn't list, and
692
+ * what was still to list or read when it reached {@link maxDiscoveryPolls}.
693
+ */
694
+ async discover() {
695
+ let dirs = this.baselined ? [.../* @__PURE__ */ new Set([...this.pendingDirs, ...this.getMovedDirs()])] : [...refNamespaces, "worktrees"];
696
+ let entries = this.baselined ? [.../* @__PURE__ */ new Set([...this.pendingEntries, ...this.getMovedGitdirs()])] : [];
697
+ this.pendingEntries.clear();
698
+ for (let polls = 0;; polls++) {
699
+ const found = dirs.length ? await this.list(dirs) : {
700
+ dirs: [],
701
+ worktrees: []
702
+ };
703
+ const unignored = entries.length ? await this.readIgnored(entries) : false;
704
+ if (!found.dirs.length && !found.worktrees.length && !unignored) return;
705
+ await this.poll();
706
+ dirs = [...found.dirs, ...this.getMovedDirs()];
707
+ entries = [.../* @__PURE__ */ new Set([...found.worktrees, ...this.getMovedGitdirs()])];
708
+ if (polls === maxDiscoveryPolls) {
709
+ for (const dir of dirs) this.pendingDirs.add(dir);
710
+ for (const id of entries) this.pendingEntries.add(id);
711
+ return;
712
+ }
713
+ }
714
+ }
715
+ /**
716
+ * Lists `dirs`, dropping the directories (or admin entries) no longer in them, and answers what's new. One that
717
+ * can't be listed keeps what it held, and is left for the next validation to list
718
+ */
719
+ async list(dirs) {
720
+ const found = {
721
+ dirs: [],
722
+ worktrees: []
723
+ };
724
+ await Promise.all(dirs.map(async (dir) => {
725
+ const names = await this.readDirectories(dir);
726
+ if (names == null) {
727
+ this.pendingDirs.add(dir);
728
+ return;
729
+ }
730
+ this.pendingDirs.delete(dir);
731
+ if (dir === "worktrees") {
732
+ for (const [id, { ignored }] of this.worktrees) if (!names.includes(id)) {
733
+ this.removedWorktrees.set(id, ignored);
734
+ this.worktrees.delete(id);
735
+ this.gated.delete(`worktrees/${id}`);
736
+ }
737
+ for (const id of names) if (!this.worktrees.has(id)) {
738
+ this.worktrees.set(id, { ignored: false });
739
+ this.addWorktreeGated(id);
740
+ this.foundWorktrees.add(id);
741
+ found.worktrees.push(id);
742
+ }
743
+ return;
744
+ }
745
+ const children = new Set(names.map((name) => `${dir}/${name}`));
746
+ for (const path of this.refDirs) {
747
+ if (path.substring(0, path.lastIndexOf("/")) !== dir || children.has(path)) continue;
748
+ for (const p of this.refDirs) if (p === path || p.startsWith(`${path}/`)) {
749
+ this.refDirs.delete(p);
750
+ this.pendingDirs.delete(p);
751
+ }
752
+ }
753
+ for (const path of children) if (!this.refDirs.has(path)) {
754
+ this.refDirs.add(path);
755
+ found.dirs.push(path);
756
+ }
757
+ }));
758
+ return found;
759
+ }
760
+ /**
761
+ * Reads whether core ignores each of the admin entries `ids`, from their `gitdir`; answers whether one known as
762
+ * ignored no longer is, whose gate the next poll must take a reading of. A read that fails ignores nothing
763
+ */
764
+ async readIgnored(ids) {
765
+ const { readFile, getIgnoredWorktreeRoots } = this.options;
766
+ if (readFile == null || getIgnoredWorktreeRoots == null || this.repoPath == null) return false;
767
+ const repoPath = this.repoPath;
768
+ const roots = await (this.ignoredRoots ??= getIgnoredWorktreeRoots(repoPath).catch(() => []));
769
+ let unignored = false;
770
+ await Promise.all(ids.map(async (id) => {
771
+ let ignored = false;
772
+ if (roots.length) {
773
+ const adminDir = joinPaths(this.basePath, "worktrees", id);
774
+ let gitdir;
775
+ try {
776
+ gitdir = await this.options.gate.run(this.gateKey, () => readFile(joinPaths(adminDir, "gitdir")));
777
+ } catch {}
778
+ ignored = isIgnoredWorktreeEntry(adminDir, gitdir, roots) === true;
779
+ }
780
+ const entry = this.worktrees.get(id);
781
+ if (entry == null || entry.ignored === ignored) return;
782
+ entry.ignored = ignored;
783
+ if (!this.foundWorktrees.has(id)) this.flippedWorktrees.add(id);
784
+ if (ignored) this.gated.delete(`worktrees/${id}`);
785
+ else {
786
+ this.addWorktreeGated(id);
787
+ unignored = true;
788
+ }
789
+ }));
790
+ return unignored;
791
+ }
792
+ /** The names of the directories in `dir`; none when it isn't there, and `undefined` when it couldn't be listed */
793
+ async readDirectories(dir) {
794
+ try {
795
+ return (await this.options.gate.run(this.gateKey, () => this.options.readDirectory(joinPaths(this.basePath, dir)))).filter(([, type]) => (type & FileType.Directory) !== 0).map(([name]) => name);
796
+ } catch (ex) {
797
+ if (isNotFound(ex) || isNotADirectory(ex)) return [];
798
+ return;
799
+ }
800
+ }
801
+ /**
802
+ * The admin ids, not ignored, that the listings of this validation added or removed; none when all were ignored, and
803
+ * `undefined` when the listings changed nothing, so what moved the `worktrees` directory is unknown
804
+ */
805
+ getAddedOrRemovedWorktrees() {
806
+ if (!this.foundWorktrees.size && !this.removedWorktrees.size) return void 0;
807
+ const ids = [];
808
+ for (const id of this.foundWorktrees) {
809
+ const entry = this.worktrees.get(id);
810
+ if (entry != null && !entry.ignored) ids.push(id);
811
+ }
812
+ for (const [id, ignored] of this.removedWorktrees) if (!ignored && !this.foundWorktrees.has(id)) ids.push(id);
813
+ return ids;
814
+ }
815
+ classify() {
816
+ const changes = /* @__PURE__ */ new Set();
817
+ const movedWorktrees = /* @__PURE__ */ new Set();
818
+ let anyWorktreeMoved = false;
819
+ const add = (...kinds) => {
820
+ for (const kind of kinds) changes.add(kind);
821
+ };
822
+ for (const probe of this.moved.values()) {
823
+ if (this.kind === "common") {
824
+ const entry = parseWorktreeAdminPath(probe.path);
825
+ if (entry != null && (this.worktrees.get(entry.id)?.ignored ?? this.removedWorktrees.get(entry.id))) continue;
826
+ }
827
+ for (const path of probe.emitAs ?? [probe.path]) {
828
+ if (path === reftableProbePath) {
829
+ if (this.kind === "root") add("head", "heads");
830
+ else add("heads", "remotes", "tags", "stash");
831
+ continue;
832
+ }
833
+ if (this.kind === "common") {
834
+ if (path === "FETCH_HEAD") {
835
+ add("lastFetched");
836
+ continue;
837
+ }
838
+ if (path === "worktrees") {
839
+ const ids = this.getAddedOrRemovedWorktrees();
840
+ if (ids == null) {
841
+ add("worktrees", "worktreeHead");
842
+ anyWorktreeMoved = true;
843
+ } else if (ids.length) {
844
+ add("worktrees", "worktreeHead");
845
+ for (const id of ids) movedWorktrees.add(id);
846
+ }
847
+ continue;
848
+ }
849
+ const match = worktreeHeadRegex.exec(path);
850
+ if (match != null) {
851
+ add("worktrees", "worktreeHead");
852
+ movedWorktrees.add(match[1]);
853
+ continue;
854
+ }
855
+ }
856
+ const kinds = classifyGitDirChange(path);
857
+ if (kinds != null) add(...kinds);
858
+ }
859
+ }
860
+ for (const id of this.flippedWorktrees) {
861
+ add("worktrees", "worktreeHead");
862
+ movedWorktrees.add(id);
863
+ }
864
+ return {
865
+ changes,
866
+ movedWorktrees: anyWorktreeMoved ? void 0 : movedWorktrees
867
+ };
868
+ }
869
+ };
870
+ /** A gate's own move reports nothing: the git dir itself, or a linked worktree's admin entry */
871
+ function isGatePath(path) {
872
+ if (path === gitDirGatePath) return true;
873
+ const entry = parseWorktreeAdminPath(path);
874
+ return entry != null && entry.file == null;
875
+ }
876
+ /** A component of the path is a file: Node's error, or the one VS Code's file system raises */
877
+ function isNotADirectory(ex) {
878
+ const code = ex?.code;
879
+ return code === "ENOTDIR" || code === "FileNotADirectory";
880
+ }
881
+ //#endregion
882
+ export { UnwatchedCacheValidator };
883
+
884
+ //# sourceMappingURL=unwatchedCacheValidator.js.map