@gitkraken/core-gitlens 0.37.1 → 0.38.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 +60 -1
- package/dist/git/cache.d.ts +128 -8
- package/dist/git/cache.js +425 -46
- package/dist/git/cache.js.map +1 -1
- package/dist/git/features.d.ts +1 -1
- package/dist/git/features.js +3 -0
- package/dist/git/features.js.map +1 -1
- package/dist/git/providers/branches.d.ts +42 -1
- package/dist/git/providers/diff.d.ts +17 -0
- package/dist/git/providers/provider.d.ts +7 -0
- package/dist/git/providers/shared/remotes.js +8 -4
- package/dist/git/providers/shared/remotes.js.map +1 -1
- package/dist/git/remotes/matcher.js +2 -2
- package/dist/git/remotes/matcher.js.map +1 -1
- package/dist/git/repositoryService.d.ts +16 -1
- package/dist/git/repositoryService.js +51 -3
- package/dist/git/repositoryService.js.map +1 -1
- package/dist/git/run.types.d.ts +1 -0
- package/dist/git/service.js +6 -2
- package/dist/git/service.js.map +1 -1
- package/dist/git/utils/fileStatus.utils.d.ts +5 -0
- package/dist/git/utils/fileStatus.utils.js +18 -1
- package/dist/git/utils/fileStatus.utils.js.map +1 -1
- package/dist/git/watching/changeEvent.d.ts +13 -3
- package/dist/git/watching/changeEvent.js +15 -4
- package/dist/git/watching/changeEvent.js.map +1 -1
- package/dist/git/watching/changeOrdinal.d.ts +9 -0
- package/dist/git/watching/changeOrdinal.js +14 -0
- package/dist/git/watching/changeOrdinal.js.map +1 -0
- package/dist/git/watching/unwatchedCacheValidator.d.ts +38 -5
- package/dist/git/watching/unwatchedCacheValidator.js +180 -36
- package/dist/git/watching/unwatchedCacheValidator.js.map +1 -1
- package/dist/git/watching/watchGroup.d.ts +63 -14
- package/dist/git/watching/watchGroup.js +213 -74
- package/dist/git/watching/watchGroup.js.map +1 -1
- package/dist/git/watching/watchService.js +4 -3
- package/dist/git/watching/watchService.js.map +1 -1
- package/dist/git/watching/watchSession.d.ts +10 -2
- package/dist/git/watching/watchSession.js +18 -4
- package/dist/git/watching/watchSession.js.map +1 -1
- package/dist/git/watching/watcherPatterns.d.ts +18 -4
- package/dist/git/watching/watcherPatterns.js +39 -8
- package/dist/git/watching/watcherPatterns.js.map +1 -1
- package/dist/git/watching/worktreeSummary.d.ts +23 -12
- package/dist/git/watching/worktreeSummary.js +164 -41
- package/dist/git/watching/worktreeSummary.js.map +1 -1
- package/dist/git-cli/cliGitProvider.d.ts +1 -0
- package/dist/git-cli/cliGitProvider.js +11 -2
- package/dist/git-cli/cliGitProvider.js.map +1 -1
- package/dist/git-cli/exec/git.d.ts +7 -2
- package/dist/git-cli/exec/git.js +46 -10
- package/dist/git-cli/exec/git.js.map +1 -1
- package/dist/git-cli/exec/headState.d.ts +24 -0
- package/dist/git-cli/exec/headState.js +46 -6
- package/dist/git-cli/exec/headState.js.map +1 -1
- package/dist/git-cli/parsers/logParser.js +6 -3
- package/dist/git-cli/parsers/logParser.js.map +1 -1
- package/dist/git-cli/providers/branches.d.ts +135 -10
- package/dist/git-cli/providers/branches.js +622 -80
- package/dist/git-cli/providers/branches.js.map +1 -1
- package/dist/git-cli/providers/commits.d.ts +16 -0
- package/dist/git-cli/providers/commits.js +80 -28
- package/dist/git-cli/providers/commits.js.map +1 -1
- package/dist/git-cli/providers/config.d.ts +10 -0
- package/dist/git-cli/providers/config.js +50 -12
- package/dist/git-cli/providers/config.js.map +1 -1
- package/dist/git-cli/providers/contributors.js +11 -7
- package/dist/git-cli/providers/contributors.js.map +1 -1
- package/dist/git-cli/providers/diff.d.ts +12 -0
- package/dist/git-cli/providers/diff.js +107 -15
- package/dist/git-cli/providers/diff.js.map +1 -1
- package/dist/git-cli/providers/graph.js +32 -25
- package/dist/git-cli/providers/graph.js.map +1 -1
- package/dist/git-cli/providers/operations.d.ts +37 -3
- package/dist/git-cli/providers/operations.js +124 -46
- package/dist/git-cli/providers/operations.js.map +1 -1
- package/dist/git-cli/providers/patch.js +1 -1
- package/dist/git-cli/providers/patch.js.map +1 -1
- package/dist/git-cli/providers/refs.d.ts +1 -1
- package/dist/git-cli/providers/refs.js +10 -11
- package/dist/git-cli/providers/refs.js.map +1 -1
- package/dist/git-cli/providers/status.d.ts +4 -5
- package/dist/git-cli/providers/status.js +36 -33
- package/dist/git-cli/providers/status.js.map +1 -1
- package/dist/git-cli/providers/tags.d.ts +8 -0
- package/dist/git-cli/providers/tags.js +53 -34
- package/dist/git-cli/providers/tags.js.map +1 -1
- package/dist/git-cli/service.d.ts +15 -0
- package/dist/git-cli/service.js +19 -1
- package/dist/git-cli/service.js.map +1 -1
- package/dist/plus/git-github/providers/github/diff.d.ts +1 -0
- package/dist/plus/git-github/providers/github/diff.js +6 -1
- package/dist/plus/git-github/providers/github/diff.js.map +1 -1
- package/dist/plus/integrations/integrationService.js +9 -0
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/providers/issueSorts.d.ts +1 -0
- package/dist/plus/integrations/providers/jira-server.js +1 -1
- package/dist/plus/integrations/providers/jira-server.js.map +1 -1
- package/dist/plus/integrations/providers/jira.d.ts +38 -6
- package/dist/plus/integrations/providers/jira.js +111 -69
- package/dist/plus/integrations/providers/jira.js.map +1 -1
- package/dist/plus/integrations/providers/linear.d.ts +31 -3
- package/dist/plus/integrations/providers/linear.js +77 -18
- package/dist/plus/integrations/providers/linear.js.map +1 -1
- package/dist/plus/integrations/providers/utils/discoveryCache.d.ts +41 -4
- package/dist/plus/integrations/providers/utils/discoveryCache.js +50 -11
- package/dist/plus/integrations/providers/utils/discoveryCache.js.map +1 -1
- package/dist/plus/integrations/reads/drains.d.ts +1 -0
- package/dist/utils/env/node/exec.d.ts +5 -4
- package/dist/utils/env/node/exec.js +52 -9
- package/dist/utils/env/node/exec.js.map +1 -1
- package/dist/utils/holdOffMap.d.ts +23 -0
- package/dist/utils/holdOffMap.js +43 -0
- package/dist/utils/holdOffMap.js.map +1 -0
- package/dist/utils/promiseCache.d.ts +15 -2
- package/dist/utils/promiseCache.js +34 -4
- package/dist/utils/promiseCache.js.map +1 -1
- package/package.json +1 -1
package/dist/git/cache.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { exhaustiveArray } from "../utils/array.js";
|
|
2
2
|
import { CancellationError, raceWithSignal } from "../utils/cancellation.js";
|
|
3
|
+
import { Logger as _logger } from "../utils/logger.js";
|
|
3
4
|
import { debug } from "../utils/decorators/log.js";
|
|
4
5
|
import { invalidateMemoized } from "../utils/decorators/memoize.js";
|
|
5
6
|
import { Emitter } from "../utils/event.js";
|
|
@@ -9,6 +10,7 @@ import { PromiseCache, PromiseMap, RepoPromiseCacheMap } from "../utils/promiseC
|
|
|
9
10
|
import { parseBranchMetadataGkConfigKey, setBranchMetadataValue } from "./utils/branch.utils.js";
|
|
10
11
|
import { createReference } from "./utils/reference.utils.js";
|
|
11
12
|
import { getCommonRepositoryPath, getRepositoryOrWorktreePath, getWorktreeAdminId } from "./utils/repository.utils.js";
|
|
13
|
+
import { nextChangeOrdinal } from "./watching/changeOrdinal.js";
|
|
12
14
|
import __decorate from "../_virtual/@oxc-project+runtime/helpers/esm/decorate.js";
|
|
13
15
|
//#region ../git/src/cache.ts
|
|
14
16
|
const uriScopedCachedGitTypes = [
|
|
@@ -19,6 +21,24 @@ const uriScopedCachedGitTypes = [
|
|
|
19
21
|
function areUriScopedCachedGitTypes(types) {
|
|
20
22
|
return types.every((t) => uriScopedCachedGitTypes.includes(t));
|
|
21
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* The cache types whose change leaves `gitResults` valid. Its runs read refs, objects and config, never the index or a
|
|
26
|
+
* working tree, so an index or file change (`blame`, `diff`, `fileLog`, `tracking`) keeps them; it is shared by every
|
|
27
|
+
* worktree of a repository, so clearing it on those would drop every worktree's results on each `git add`.
|
|
28
|
+
* A fetch that moves a ref reports that ref's change; `lastFetched` alone means only `FETCH_HEAD` was written, and a
|
|
29
|
+
* run that names `FETCH_HEAD` is never cached.
|
|
30
|
+
*/
|
|
31
|
+
const typesKeepingGitResults = /* @__PURE__ */ new Set([
|
|
32
|
+
"blame",
|
|
33
|
+
"diff",
|
|
34
|
+
"fileLog",
|
|
35
|
+
"gitignore",
|
|
36
|
+
"gkConfig",
|
|
37
|
+
"lastFetched",
|
|
38
|
+
"providers",
|
|
39
|
+
"tracking",
|
|
40
|
+
"worktreeList"
|
|
41
|
+
]);
|
|
22
42
|
/** Whether a reset of these types makes in-flight git runs stale (none or empty meaning every type) */
|
|
23
43
|
function resetDropsPendingRuns(types) {
|
|
24
44
|
return !types?.length || types.some((t) => t !== "worktreeList" && t !== "providers");
|
|
@@ -36,7 +56,19 @@ const baseBranchNameTTL = 3e5;
|
|
|
36
56
|
const maxCachedBlameLines = 5e3;
|
|
37
57
|
/** Per drop-stamped cache, paths whose last drop is tracked; the oldest beyond this folds into the all-paths floor */
|
|
38
58
|
const dropsTracked = 128;
|
|
39
|
-
|
|
59
|
+
/** Repositories whose shared evictions are tracked (see {@link sharedCacheSources}); the oldest beyond this are forgotten */
|
|
60
|
+
const sharedEvictionsTracked = 128;
|
|
61
|
+
/**
|
|
62
|
+
* How long a read waits for the host to register its checkout (see {@link Cache.setRepoPathRegistrar}) before going
|
|
63
|
+
* ahead unregistered, so a registrar that never settles delays each checkout's first reads once rather than holding
|
|
64
|
+
* them for good
|
|
65
|
+
*/
|
|
66
|
+
const registrationWaitMs = 1e4;
|
|
67
|
+
const dropStampedCacheKeys = exhaustiveArray()([
|
|
68
|
+
"currentBranchReference",
|
|
69
|
+
"currentUser",
|
|
70
|
+
"defaultBranchName"
|
|
71
|
+
]);
|
|
40
72
|
async function shouldEvictBlameCacheEntry(progressive) {
|
|
41
73
|
if (progressive == null) return false;
|
|
42
74
|
try {
|
|
@@ -89,6 +121,58 @@ const sharedCacheKeys = new Set(exhaustiveArray()([
|
|
|
89
121
|
"tags",
|
|
90
122
|
"worktrees"
|
|
91
123
|
]));
|
|
124
|
+
function isSharedCacheKey(key) {
|
|
125
|
+
return sharedCacheKeys.has(key);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* What each shared cache's entries are read from, which decides whether a watcher's report of a change may skip evicting
|
|
129
|
+
* it once an eviction after the change already did (see {@link Cache.applyRepositoryChanges}): `[]` for git alone, the
|
|
130
|
+
* caches an entry is built from, or `undefined` where that isn't known. A cache built from a checkout's own cache (one
|
|
131
|
+
* no shared eviction drops whole), from one not known, or from such a cache in turn, is evicted by every report.
|
|
132
|
+
*/
|
|
133
|
+
const sharedCacheSources = {
|
|
134
|
+
aheadOfBaseConfigListing: void 0,
|
|
135
|
+
baseBranchName: void 0,
|
|
136
|
+
branchMergedStatus: void 0,
|
|
137
|
+
branchMetadataMap: ["gkConfigMap"],
|
|
138
|
+
branchOverviews: void 0,
|
|
139
|
+
branches: [
|
|
140
|
+
"sharedBranches",
|
|
141
|
+
"currentBranchReference",
|
|
142
|
+
"branchMetadataMap"
|
|
143
|
+
],
|
|
144
|
+
configKeys: void 0,
|
|
145
|
+
configPatterns: void 0,
|
|
146
|
+
contributors: void 0,
|
|
147
|
+
contributorsLite: void 0,
|
|
148
|
+
contributorsStats: void 0,
|
|
149
|
+
defaultBranchName: [],
|
|
150
|
+
emptyTreeSha: void 0,
|
|
151
|
+
gitResults: [],
|
|
152
|
+
gkConfigMap: void 0,
|
|
153
|
+
ignoreConfigListing: void 0,
|
|
154
|
+
initialCommitSha: void 0,
|
|
155
|
+
lastFetched: void 0,
|
|
156
|
+
logShas: void 0,
|
|
157
|
+
mergeTargets: void 0,
|
|
158
|
+
refs: [],
|
|
159
|
+
refTips: ["refs"],
|
|
160
|
+
remotes: void 0,
|
|
161
|
+
sharedBranches: [
|
|
162
|
+
"refs",
|
|
163
|
+
"branchMetadataMap",
|
|
164
|
+
"remotes"
|
|
165
|
+
],
|
|
166
|
+
stashes: ["currentUser"],
|
|
167
|
+
tags: ["refs"],
|
|
168
|
+
worktrees: ["branches"]
|
|
169
|
+
};
|
|
170
|
+
/** The shared caches that say which branch is checked out in which worktree (see `Cache.evictBranchPlacement`) */
|
|
171
|
+
const placementCacheKeys = [
|
|
172
|
+
"refs",
|
|
173
|
+
"sharedBranches",
|
|
174
|
+
"branches"
|
|
175
|
+
];
|
|
92
176
|
function createEmptyCaches() {
|
|
93
177
|
return {
|
|
94
178
|
aheadOfBaseConfigKey: void 0,
|
|
@@ -160,6 +244,8 @@ var Cache = class Cache {
|
|
|
160
244
|
_mergeTargetCheckoutGeneration = 0;
|
|
161
245
|
/** Each merge target answer's entry as `mergeTargets` stored it, so dropping a stale answer can't drop its successor */
|
|
162
246
|
_mergeTargetStored = /* @__PURE__ */ new WeakMap();
|
|
247
|
+
/** Each worktree's mapped entry of a shared read, to the shared entry it was mapped from */
|
|
248
|
+
_mappedFrom = /* @__PURE__ */ new WeakMap();
|
|
163
249
|
/** Advanced each time a drop-stamped cache's entries are dropped (see {@link getDropStamp}) */
|
|
164
250
|
_drops = 0;
|
|
165
251
|
/**
|
|
@@ -174,6 +260,10 @@ var Cache = class Cache {
|
|
|
174
260
|
currentUser: {
|
|
175
261
|
byPath: /* @__PURE__ */ new Map(),
|
|
176
262
|
all: 0
|
|
263
|
+
},
|
|
264
|
+
defaultBranchName: {
|
|
265
|
+
byPath: /* @__PURE__ */ new Map(),
|
|
266
|
+
all: 0
|
|
177
267
|
}
|
|
178
268
|
};
|
|
179
269
|
/**
|
|
@@ -194,6 +284,20 @@ var Cache = class Cache {
|
|
|
194
284
|
*/
|
|
195
285
|
_worktreeAdminIds = /* @__PURE__ */ new Map();
|
|
196
286
|
/**
|
|
287
|
+
* Per common path, oldest first, the change ordinal (see `nextChangeOrdinal`) taken when each shared cache was last
|
|
288
|
+
* evicted whole for the repository with nothing read before left to serve or join (see {@link sharedCacheSources}),
|
|
289
|
+
* and when the ref listing, the shared branch list and every checkout's branch list were last so evicted together
|
|
290
|
+
* (`'branchPlacement'`, see {@link evictBranchPlacement})
|
|
291
|
+
*/
|
|
292
|
+
_sharedEvictions = /* @__PURE__ */ new Map();
|
|
293
|
+
/**
|
|
294
|
+
* Linked worktrees whose HEAD a report moved without clearing the repository's base branch names, with the branch
|
|
295
|
+
* the ref listing cached then placed there (`undefined` when none was). The next listing that places another branch
|
|
296
|
+
* there drops that branch's cached base, which its first checkout may have just given it (see
|
|
297
|
+
* {@link dropBasesOwedOnCheckout})
|
|
298
|
+
*/
|
|
299
|
+
_basesOwedOnCheckout = /* @__PURE__ */ new Map();
|
|
300
|
+
/**
|
|
197
301
|
* Per-commonPath snapshot of the subset of `.git/gk/config` that derived caches depend on — merge-relevant keys
|
|
198
302
|
* ({@link branchOverviewGkConfigKeysRegex}) and branch metadata keys ({@link parseBranchMetadataGkConfigKey}) —
|
|
199
303
|
* used by {@link reconcileGkConfigMap} to diff a watcher `'gkConfig'` event down to only the keys that actually
|
|
@@ -225,6 +329,13 @@ var Cache = class Cache {
|
|
|
225
329
|
_readValidator;
|
|
226
330
|
/** What the read validator reports among {@link getResourceUsage}'s */
|
|
227
331
|
_readValidatorUsage;
|
|
332
|
+
/** Asked to register a checkout before its first read (see {@link setRepoPathRegistrar}) */
|
|
333
|
+
_repoPathRegistrar;
|
|
334
|
+
/**
|
|
335
|
+
* Registrations still in flight, by checkout. `wait` is what a read waits on, `undefined` while the registrar runs
|
|
336
|
+
* synchronously (so its own reads go ahead) and once the wait timed out
|
|
337
|
+
*/
|
|
338
|
+
_registrations = /* @__PURE__ */ new Map();
|
|
228
339
|
[Symbol.dispose]() {
|
|
229
340
|
this.dispose();
|
|
230
341
|
}
|
|
@@ -232,6 +343,7 @@ var Cache = class Cache {
|
|
|
232
343
|
this.reset();
|
|
233
344
|
this._readValidator = void 0;
|
|
234
345
|
this._readValidatorUsage = void 0;
|
|
346
|
+
this._repoPathRegistrar = void 0;
|
|
235
347
|
this._onDidChangeMergeTargets.dispose();
|
|
236
348
|
}
|
|
237
349
|
/**
|
|
@@ -250,6 +362,79 @@ var Cache = class Cache {
|
|
|
250
362
|
this._readValidator = validator;
|
|
251
363
|
this._readValidatorUsage = validator != null ? getResourceUsage : void 0;
|
|
252
364
|
}
|
|
365
|
+
/** Whether a read validator is set (see {@link setReadValidator}), so the host keeps the caches it covers current */
|
|
366
|
+
get readsAreValidated() {
|
|
367
|
+
return this._readValidator != null;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Registers what registers a checkout (see {@link registerRepoPath}) before its first read through the service's
|
|
371
|
+
* per-repository sub-providers, since a checkout read before it is registered keeps its own copy of what its
|
|
372
|
+
* repository's checkouts share, which its registration then throws away. Asked by {@link ensureRegistered}, one ask
|
|
373
|
+
* at a time per checkout, until the checkout is registered. It registers the checkout itself, then answers a
|
|
374
|
+
* promise that settles once it did; it answers `undefined`, cheaply and synchronously, for a path it declines (one
|
|
375
|
+
* it doesn't know or trust), and is asked again at that path's next read. Its own reads of the checkout's git dir
|
|
376
|
+
* (`config.getGitDir`, `getRepositoryInfo`) go ahead without waiting on it, as does every read it makes before its
|
|
377
|
+
* first `await`; any other read it makes of that checkout through the service waits on it. `undefined` removes it.
|
|
378
|
+
* Kept across {@link reset}: it is host wiring, not cached state.
|
|
379
|
+
*/
|
|
380
|
+
setRepoPathRegistrar(registrar) {
|
|
381
|
+
this._repoPathRegistrar = registrar;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Asks the registrar (see {@link setRepoPathRegistrar}) to register `repoPath` unless it is registered: `undefined`
|
|
385
|
+
* when there is nothing to wait for (no registrar, a path already registered or declined), or a promise, never
|
|
386
|
+
* rejecting, to read after. Concurrent calls for one path share one ask. A registrar that fails is logged and the
|
|
387
|
+
* read goes ahead unregistered; one that is slow is waited on for a while, after which reads go ahead and the path
|
|
388
|
+
* isn't asked again until it settles.
|
|
389
|
+
*/
|
|
390
|
+
ensureRegistered(repoPath) {
|
|
391
|
+
const registrar = this._repoPathRegistrar;
|
|
392
|
+
if (registrar == null || this._commonPathRegistry.has(repoPath)) return void 0;
|
|
393
|
+
const inFlight = this._registrations.get(repoPath);
|
|
394
|
+
if (inFlight != null) return inFlight.wait;
|
|
395
|
+
const registration = {
|
|
396
|
+
wait: void 0,
|
|
397
|
+
release: () => {},
|
|
398
|
+
timer: void 0
|
|
399
|
+
};
|
|
400
|
+
this._registrations.set(repoPath, registration);
|
|
401
|
+
const forget = () => {
|
|
402
|
+
if (this._registrations.get(repoPath) === registration) this._registrations.delete(repoPath);
|
|
403
|
+
};
|
|
404
|
+
let pending;
|
|
405
|
+
try {
|
|
406
|
+
pending = registrar(repoPath);
|
|
407
|
+
} catch (ex) {
|
|
408
|
+
_logger.warn(`Cache: registering '${repoPath}' failed: ${String(ex)}`);
|
|
409
|
+
}
|
|
410
|
+
if (pending == null) {
|
|
411
|
+
forget();
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
registration.wait = new Promise((resolve) => {
|
|
415
|
+
registration.release = resolve;
|
|
416
|
+
});
|
|
417
|
+
const timer = setTimeout(() => {
|
|
418
|
+
registration.timer = void 0;
|
|
419
|
+
registration.wait = void 0;
|
|
420
|
+
registration.release();
|
|
421
|
+
}, registrationWaitMs);
|
|
422
|
+
if (typeof timer !== "number") timer.unref();
|
|
423
|
+
registration.timer = timer;
|
|
424
|
+
const settle = () => {
|
|
425
|
+
if (registration.timer != null) {
|
|
426
|
+
clearTimeout(registration.timer);
|
|
427
|
+
registration.timer = void 0;
|
|
428
|
+
}
|
|
429
|
+
registration.release();
|
|
430
|
+
forget();
|
|
431
|
+
};
|
|
432
|
+
Promise.resolve(pending).then(settle, (ex) => {
|
|
433
|
+
_logger.warn(`Cache: registering '${repoPath}' failed: ${String(ex)}`);
|
|
434
|
+
settle();
|
|
435
|
+
});
|
|
436
|
+
return registration.wait;
|
|
437
|
+
}
|
|
253
438
|
/**
|
|
254
439
|
* Runs the read validator (see {@link setReadValidator}) for a read of one of its caches made without the wrappers
|
|
255
440
|
* here: `undefined` when the read can go ahead at once, or a promise (that never rejects) to read after
|
|
@@ -278,7 +463,10 @@ var Cache = class Cache {
|
|
|
278
463
|
usage["cache.mergeTargetsEvictedOnCheckout.entries.count"] = this._mergeTargetsEvictedOnCheckout.size;
|
|
279
464
|
usage["cache.currentBranchDroppedAt.entries.count"] = this._droppedAt.currentBranchReference.byPath.size;
|
|
280
465
|
usage["cache.currentUserDroppedAt.entries.count"] = this._droppedAt.currentUser.byPath.size;
|
|
466
|
+
usage["cache.defaultBranchNameDroppedAt.entries.count"] = this._droppedAt.defaultBranchName.byPath.size;
|
|
281
467
|
usage["cache.seededWorktrees.entries.count"] = this._seededWorktrees.size;
|
|
468
|
+
usage["cache.sharedEvictions.entries.count"] = this._sharedEvictions.size;
|
|
469
|
+
usage["cache.basesOwedOnCheckout.entries.count"] = this._basesOwedOnCheckout.size;
|
|
282
470
|
if (this._readValidatorUsage != null) Object.assign(usage, this._readValidatorUsage());
|
|
283
471
|
return usage;
|
|
284
472
|
}
|
|
@@ -395,6 +583,7 @@ var Cache = class Cache {
|
|
|
395
583
|
if (reported.has(path)) continue;
|
|
396
584
|
this.untrackSeededWorktree(path);
|
|
397
585
|
this.dropCurrentBranch(path);
|
|
586
|
+
this._basesOwedOnCheckout.delete(path);
|
|
398
587
|
}
|
|
399
588
|
for (const path of reported) this.trackSeededWorktree(path, commonPath);
|
|
400
589
|
}
|
|
@@ -410,7 +599,10 @@ var Cache = class Cache {
|
|
|
410
599
|
for (const path of this._seededWorktreesByCommonPath.get(commonPath) ?? []) paths.add(path);
|
|
411
600
|
paths.delete(repoPath);
|
|
412
601
|
paths.delete(commonPath);
|
|
413
|
-
for (const path of paths)
|
|
602
|
+
for (const path of paths) {
|
|
603
|
+
this.oweBaseOnCheckout(path, commonPath);
|
|
604
|
+
this.dropCurrentBranch(path);
|
|
605
|
+
}
|
|
414
606
|
}
|
|
415
607
|
/**
|
|
416
608
|
* A `'worktreeHead'` report naming, by admin id, the linked worktrees whose HEAD moved: each registered one but
|
|
@@ -424,12 +616,84 @@ var Cache = class Cache {
|
|
|
424
616
|
if (id == null || !ids.has(id)) continue;
|
|
425
617
|
found.add(id);
|
|
426
618
|
if (path === repoPath) continue;
|
|
427
|
-
this.
|
|
428
|
-
this._caches.branches?.delete(path);
|
|
429
|
-
this._caches.gitResults?.delete(path);
|
|
619
|
+
this.applyLinkedWorktreeChanges(path, ["head"], inFlight);
|
|
430
620
|
}
|
|
431
621
|
if (found.size < ids.size) this.dropLinkedCurrentBranches(repoPath, true);
|
|
432
622
|
}
|
|
623
|
+
/**
|
|
624
|
+
* Clears what `changes` can have made stale in the linked worktree at `repoPath`'s own entries and status clock,
|
|
625
|
+
* leaving the shared (commonPath-keyed) ones alone, for a change that can't have moved what they hold. `inFlight` is
|
|
626
|
+
* as {@link applyRepositoryChanges}
|
|
627
|
+
*/
|
|
628
|
+
applyLinkedWorktreeChanges(repoPath, changes, inFlight) {
|
|
629
|
+
const changesSet = new Set(changes);
|
|
630
|
+
if (changesSet.has("head")) this.oweBaseOnCheckout(repoPath, this.getCommonPath(repoPath));
|
|
631
|
+
this.applyRepositoryChanges(repoPath, changesSet, inFlight, { worktreeOnly: true });
|
|
632
|
+
if (!changesSet.has("head")) return;
|
|
633
|
+
this._caches.branches?.delete(repoPath);
|
|
634
|
+
this._caches.gitResults?.delete(repoPath);
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Notes that `worktreePath`'s HEAD moved, with the branch the cached ref listing of `commonPath` placed there, unless
|
|
638
|
+
* a move not yet seen by a listing was noted already (see {@link _basesOwedOnCheckout})
|
|
639
|
+
*/
|
|
640
|
+
oweBaseOnCheckout(worktreePath, commonPath) {
|
|
641
|
+
if (this._basesOwedOnCheckout.has(worktreePath)) return;
|
|
642
|
+
let branch;
|
|
643
|
+
for (const record of this._caches.refs?.getSettled(commonPath)?.value ?? []) if (record.worktreePath && record.name.startsWith("refs/heads/")) {
|
|
644
|
+
if (normalizePath(record.worktreePath) === worktreePath) {
|
|
645
|
+
branch = record.name.substring(11);
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
this._basesOwedOnCheckout.set(worktreePath, branch);
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Drops the cached base of each branch that `records`, a listing of `commonPath` started at drop stamp `at` (see
|
|
653
|
+
* {@link getDropStamp}), places in a worktree owing one, when it isn't the branch placed there before its HEAD moved.
|
|
654
|
+
* Only one branch per moved worktree is read again, where clearing every base would read one per worktree
|
|
655
|
+
*/
|
|
656
|
+
dropBasesOwedOnCheckout(commonPath, records, at) {
|
|
657
|
+
if (!this._basesOwedOnCheckout.size) return;
|
|
658
|
+
for (const record of records) {
|
|
659
|
+
if (!record.worktreePath || !record.name.startsWith("refs/heads/")) continue;
|
|
660
|
+
const path = normalizePath(record.worktreePath);
|
|
661
|
+
if (!this._basesOwedOnCheckout.has(path)) continue;
|
|
662
|
+
if (this.isDroppedSince("currentBranchReference", path, at)) continue;
|
|
663
|
+
const branch = record.name.substring(11);
|
|
664
|
+
if (this._basesOwedOnCheckout.get(path) !== branch) this.deleteBaseBranchName(commonPath, branch);
|
|
665
|
+
this._basesOwedOnCheckout.delete(path);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Whether `movedWorktrees` names no linked worktree but `repoPath`, whose own `'head'` reports its HEAD moving. An
|
|
670
|
+
* empty set names none known, which may be any
|
|
671
|
+
*/
|
|
672
|
+
movedOnlyItself(repoPath, movedWorktrees) {
|
|
673
|
+
if (!movedWorktrees?.size) return false;
|
|
674
|
+
const id = this._worktreeAdminIds.get(repoPath);
|
|
675
|
+
return [...movedWorktrees].every((m) => m === id);
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Drops what says which branch is checked out in which worktree, for every worktree of `repoPath`'s repository: the
|
|
679
|
+
* ref listing, the shared branch list built from it, and each worktree's list mapped from that. Hard-deleted even
|
|
680
|
+
* when reads in flight would otherwise be shared, as one that listed the refs before the HEAD moved must not answer
|
|
681
|
+
* a read issued after it.
|
|
682
|
+
*
|
|
683
|
+
* A report stamped `observedAt` (see {@link applyRepositoryChanges}) skips it once all three were dropped together
|
|
684
|
+
* after that, with nothing read before left to serve or join: each holder rebuilt since was built from a ref listing
|
|
685
|
+
* started after the change was observed, so it already places the branches as the change left them.
|
|
686
|
+
*/
|
|
687
|
+
evictBranchPlacement(repoPath, observedAt) {
|
|
688
|
+
if (observedAt != null) {
|
|
689
|
+
const evictedAt = this._sharedEvictions.get(this.getCommonPath(repoPath))?.get("branchPlacement");
|
|
690
|
+
if (evictedAt != null && evictedAt > observedAt) return;
|
|
691
|
+
}
|
|
692
|
+
const cleared = /* @__PURE__ */ new Set();
|
|
693
|
+
for (const key of placementCacheKeys) if (this._caches[key] == null) cleared.add(key);
|
|
694
|
+
else this.evictShared(key, repoPath, "evict", cleared);
|
|
695
|
+
this.recordSharedEvictions(repoPath, cleared);
|
|
696
|
+
}
|
|
433
697
|
/** Drops what a `'branch'` eviction of `worktreePath` drops of its current branch, and nothing shared */
|
|
434
698
|
dropCurrentBranch(worktreePath) {
|
|
435
699
|
this.onDropped(worktreePath, ["currentBranchReference"]);
|
|
@@ -445,12 +709,16 @@ var Cache = class Cache {
|
|
|
445
709
|
getDropStamp(key, repoPath) {
|
|
446
710
|
if (key == null || repoPath == null) return this._drops;
|
|
447
711
|
const droppedAt = this._droppedAt[key];
|
|
448
|
-
return Math.max(droppedAt.all, droppedAt.byPath.get(repoPath) ?? 0);
|
|
712
|
+
return Math.max(droppedAt.all, droppedAt.byPath.get(this.getDropStampedPath(key, repoPath)) ?? 0);
|
|
449
713
|
}
|
|
450
714
|
/** Whether `key`'s entry for `repoPath` was dropped after `stamp` was taken by {@link getDropStamp} */
|
|
451
715
|
isDroppedSince(key, repoPath, stamp) {
|
|
452
716
|
const droppedAt = this._droppedAt[key];
|
|
453
|
-
return stamp < droppedAt.all || stamp < (droppedAt.byPath.get(repoPath) ?? 0);
|
|
717
|
+
return stamp < droppedAt.all || stamp < (droppedAt.byPath.get(this.getDropStampedPath(key, repoPath)) ?? 0);
|
|
718
|
+
}
|
|
719
|
+
/** The path `key`'s drops for `repoPath` are stamped by: its common path for a shared cache */
|
|
720
|
+
getDropStampedPath(key, repoPath) {
|
|
721
|
+
return isSharedCacheKey(key) ? this.getCommonPath(repoPath) : repoPath;
|
|
454
722
|
}
|
|
455
723
|
/** Stamps a drop of `keys`' entries for `repoPath`, or for every path when `undefined` */
|
|
456
724
|
onDropped(repoPath, keys = dropStampedCacheKeys) {
|
|
@@ -463,8 +731,9 @@ var Cache = class Cache {
|
|
|
463
731
|
droppedAt.byPath.clear();
|
|
464
732
|
continue;
|
|
465
733
|
}
|
|
466
|
-
|
|
467
|
-
droppedAt.byPath.
|
|
734
|
+
const path = this.getDropStampedPath(key, repoPath);
|
|
735
|
+
droppedAt.byPath.delete(path);
|
|
736
|
+
droppedAt.byPath.set(path, this._drops);
|
|
468
737
|
if (droppedAt.byPath.size > dropsTracked) {
|
|
469
738
|
const [oldestPath, oldestAt] = droppedAt.byPath.entries().next().value;
|
|
470
739
|
droppedAt.byPath.delete(oldestPath);
|
|
@@ -630,8 +899,11 @@ var Cache = class Cache {
|
|
|
630
899
|
evictCaches(repoPath, ...types) {
|
|
631
900
|
this.clearCachesCore("evict", repoPath, types);
|
|
632
901
|
}
|
|
633
|
-
/**
|
|
634
|
-
|
|
902
|
+
/**
|
|
903
|
+
* `worktreeOnly` leaves the shared (commonPath-keyed) entries alone, and `observedAt` skips those an eviction after
|
|
904
|
+
* it already dropped (see {@link applyRepositoryChanges})
|
|
905
|
+
*/
|
|
906
|
+
clearCachesCore(inFlight, repoPath, types, worktreeOnly = false, observedAt) {
|
|
635
907
|
const keysToClear = /* @__PURE__ */ new Set();
|
|
636
908
|
if (!types.length) {
|
|
637
909
|
for (const key of Object.keys(this._caches)) keysToClear.add(key);
|
|
@@ -726,21 +998,27 @@ var Cache = class Cache {
|
|
|
726
998
|
keysToClear.add("trackedPaths");
|
|
727
999
|
}
|
|
728
1000
|
if (types.includes("worktrees") || types.includes("worktreeList")) keysToClear.add("worktrees");
|
|
729
|
-
if (types.some((t) => t
|
|
1001
|
+
if (types.some((t) => !typesKeepingGitResults.has(t))) keysToClear.add("gitResults");
|
|
730
1002
|
}
|
|
731
|
-
this.onDropped(repoPath, dropStampedCacheKeys.filter((k) => keysToClear.has(k)));
|
|
1003
|
+
this.onDropped(repoPath, dropStampedCacheKeys.filter((k) => keysToClear.has(k) && !(worktreeOnly && isSharedCacheKey(k))));
|
|
1004
|
+
if (repoPath == null) this._sharedEvictions.clear();
|
|
1005
|
+
const cleared = /* @__PURE__ */ new Set();
|
|
732
1006
|
for (const key of keysToClear) {
|
|
733
1007
|
const cache = this._caches[key];
|
|
734
|
-
if (cache == null)
|
|
1008
|
+
if (cache == null) {
|
|
1009
|
+
if (repoPath != null && !worktreeOnly && isSharedCacheKey(key)) cleared.add(key);
|
|
1010
|
+
continue;
|
|
1011
|
+
}
|
|
735
1012
|
if (repoPath == null || key === "superprojects") cache.clear();
|
|
736
1013
|
else if (key === "aheadOfBaseConfigKey" && !worktreeOnly && (!types.length || types.includes("config"))) this.evictShared(key, repoPath, "evict");
|
|
737
|
-
else if (
|
|
738
|
-
if (!worktreeOnly) {
|
|
1014
|
+
else if (isSharedCacheKey(key)) {
|
|
1015
|
+
if (!worktreeOnly && (observedAt == null || !this.isSharedEvictedSince(key, repoPath, observedAt))) {
|
|
739
1016
|
const hardEvict = key === "aheadOfBaseConfigListing" || key === "ignoreConfigListing" || key === "gitResults" && (types.includes("config") || types.includes("branch"));
|
|
740
|
-
this.evictShared(key, repoPath, hardEvict ? "evict" : inFlight);
|
|
1017
|
+
this.evictShared(key, repoPath, hardEvict ? "evict" : inFlight, cleared);
|
|
741
1018
|
}
|
|
742
1019
|
} else cache.delete(repoPath);
|
|
743
1020
|
}
|
|
1021
|
+
if (repoPath != null && cleared.size) this.recordSharedEvictions(repoPath, cleared);
|
|
744
1022
|
if (types.includes("branch") && !types.includes("branches")) {
|
|
745
1023
|
if (repoPath == null) this._caches.branches?.clear();
|
|
746
1024
|
else this._caches.branches?.delete(repoPath);
|
|
@@ -757,25 +1035,70 @@ var Cache = class Cache {
|
|
|
757
1035
|
*
|
|
758
1036
|
* When `inFlight` is `'evict'`, always hard-deletes regardless of `invalidate` support — a new caller
|
|
759
1037
|
* must never join a read that started before this eviction (see {@link evictCaches}).
|
|
1038
|
+
*
|
|
1039
|
+
* A shared `key` left with nothing read before to serve or join is added to `cleared`, for the caller to record
|
|
1040
|
+
* with the rest of its eviction; without `cleared`, it is recorded alone (see {@link recordSharedEvictions}).
|
|
760
1041
|
*/
|
|
761
|
-
evictShared(key, repoPath, inFlight = "share") {
|
|
1042
|
+
evictShared(key, repoPath, inFlight = "share", cleared) {
|
|
762
1043
|
const cache = this._caches[key];
|
|
763
1044
|
if (cache == null) return;
|
|
764
1045
|
const commonPath = this.getCommonPath(repoPath);
|
|
1046
|
+
const paths = [commonPath, ...this.getWorktreePaths(commonPath).filter((p) => p !== commonPath)];
|
|
765
1047
|
const invalidate = inFlight === "share" ? cache.invalidate : void 0;
|
|
1048
|
+
if (typeof invalidate === "function") for (const path of paths) invalidate.call(cache, path);
|
|
1049
|
+
else for (const path of paths) cache.delete(path);
|
|
1050
|
+
if (!isSharedCacheKey(key)) return;
|
|
766
1051
|
if (typeof invalidate === "function") {
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
1052
|
+
const has = cache.has;
|
|
1053
|
+
if (typeof has !== "function" || paths.some((p) => has.call(cache, p))) return;
|
|
1054
|
+
}
|
|
1055
|
+
if (cleared != null) cleared.add(key);
|
|
1056
|
+
else this.recordSharedEvictions(repoPath, /* @__PURE__ */ new Set([key]));
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Records that the shared caches in `cleared` were just evicted whole for `repoPath`'s repository, leaving nothing
|
|
1060
|
+
* read before to serve or join: each read from git alone, and each built from others only when all of them are
|
|
1061
|
+
* recorded here too (see {@link sharedCacheSources}). With every one of {@link placementCacheKeys} among them, also
|
|
1062
|
+
* records where each branch is checked out as evicted (see {@link evictBranchPlacement})
|
|
1063
|
+
*/
|
|
1064
|
+
recordSharedEvictions(repoPath, cleared) {
|
|
1065
|
+
const recorded = /* @__PURE__ */ new Set();
|
|
1066
|
+
let added = true;
|
|
1067
|
+
while (added) {
|
|
1068
|
+
added = false;
|
|
1069
|
+
for (const key of cleared) {
|
|
1070
|
+
if (recorded.has(key)) continue;
|
|
1071
|
+
const sources = sharedCacheSources[key];
|
|
1072
|
+
if (sources == null || !sources.every((s) => recorded.has(s))) continue;
|
|
1073
|
+
recorded.add(key);
|
|
1074
|
+
added = true;
|
|
777
1075
|
}
|
|
778
1076
|
}
|
|
1077
|
+
const placement = placementCacheKeys.every((k) => cleared.has(k));
|
|
1078
|
+
if (!recorded.size && !placement) return;
|
|
1079
|
+
const commonPath = this.getCommonPath(repoPath);
|
|
1080
|
+
const evictions = this._sharedEvictions.get(commonPath) ?? /* @__PURE__ */ new Map();
|
|
1081
|
+
this._sharedEvictions.delete(commonPath);
|
|
1082
|
+
this._sharedEvictions.set(commonPath, evictions);
|
|
1083
|
+
if (this._sharedEvictions.size > sharedEvictionsTracked) this._sharedEvictions.delete(this._sharedEvictions.keys().next().value);
|
|
1084
|
+
const at = nextChangeOrdinal();
|
|
1085
|
+
for (const key of recorded) if (isSharedCacheKey(key)) evictions.set(key, at);
|
|
1086
|
+
if (placement) evictions.set("branchPlacement", at);
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Whether `key`, and every cache it is built from, was evicted whole for `repoPath`'s repository after `observedAt`,
|
|
1090
|
+
* with nothing read before left to serve or join: all they hold since was read after a change observed then
|
|
1091
|
+
*/
|
|
1092
|
+
isSharedEvictedSince(key, repoPath, observedAt) {
|
|
1093
|
+
const evictions = this._sharedEvictions.get(this.getCommonPath(repoPath));
|
|
1094
|
+
if (evictions == null) return false;
|
|
1095
|
+
const isEvictedSince = (k) => {
|
|
1096
|
+
if (!isSharedCacheKey(k)) return false;
|
|
1097
|
+
const sources = sharedCacheSources[k];
|
|
1098
|
+
const at = evictions.get(k);
|
|
1099
|
+
return sources != null && at != null && at > observedAt && sources.every(isEvictedSince);
|
|
1100
|
+
};
|
|
1101
|
+
return isEvictedSince(key);
|
|
779
1102
|
}
|
|
780
1103
|
/**
|
|
781
1104
|
* Monotonic per-worktree counter, advanced whenever anything that can change `git status` output is
|
|
@@ -859,6 +1182,8 @@ var Cache = class Cache {
|
|
|
859
1182
|
const previousCommonPath = this._commonPathRegistry.get(normalizedPath);
|
|
860
1183
|
if (previousCommonPath != null && previousCommonPath !== commonPath) this.unregisterRepoPath(normalizedPath);
|
|
861
1184
|
if (previousCommonPath !== commonPath) {
|
|
1185
|
+
this._sharedEvictions.delete(commonPath);
|
|
1186
|
+
this._sharedEvictions.delete(normalizedPath);
|
|
862
1187
|
this._caches.aheadOfBaseConfigKey?.delete(normalizedPath);
|
|
863
1188
|
if (normalizedPath === commonPath) {
|
|
864
1189
|
this._caches.aheadOfBaseConfigListing?.delete(commonPath);
|
|
@@ -919,10 +1244,12 @@ var Cache = class Cache {
|
|
|
919
1244
|
unregisterRepoPath(repoPath) {
|
|
920
1245
|
this.incrementStatusGeneration(repoPath);
|
|
921
1246
|
this._closeGenerations.set(repoPath, (this._closeGenerations.get(repoPath) ?? 0) + 1);
|
|
922
|
-
this.onDropped(repoPath);
|
|
923
1247
|
const commonPath = this._commonPathRegistry.get(repoPath) ?? repoPath;
|
|
1248
|
+
this._sharedEvictions.delete(commonPath);
|
|
1249
|
+
this._sharedEvictions.delete(repoPath);
|
|
924
1250
|
const worktrees = this._worktreesByCommonPath.get(commonPath);
|
|
925
1251
|
const isLastWorktree = worktrees == null || worktrees.size <= 1;
|
|
1252
|
+
this.onDropped(repoPath, dropStampedCacheKeys.filter((k) => isLastWorktree || !isSharedCacheKey(k)));
|
|
926
1253
|
for (const key of Object.keys(this._caches)) {
|
|
927
1254
|
const cache = this._caches[key];
|
|
928
1255
|
if (cache == null) continue;
|
|
@@ -952,10 +1279,12 @@ var Cache = class Cache {
|
|
|
952
1279
|
for (const path of [...this._seededWorktreesByCommonPath.get(commonPath) ?? []]) {
|
|
953
1280
|
this.untrackSeededWorktree(path);
|
|
954
1281
|
this.dropCurrentBranch(path);
|
|
1282
|
+
this._basesOwedOnCheckout.delete(path);
|
|
955
1283
|
}
|
|
956
1284
|
}
|
|
957
1285
|
this.untrackSeededWorktree(repoPath);
|
|
958
1286
|
this._worktreeAdminIds.delete(repoPath);
|
|
1287
|
+
this._basesOwedOnCheckout.delete(repoPath);
|
|
959
1288
|
this._commonPathRegistry.delete(repoPath);
|
|
960
1289
|
if (worktrees != null) {
|
|
961
1290
|
worktrees.delete(repoPath);
|
|
@@ -972,13 +1301,24 @@ var Cache = class Cache {
|
|
|
972
1301
|
this._seededWorktrees.clear();
|
|
973
1302
|
this._seededWorktreesByCommonPath.clear();
|
|
974
1303
|
this._worktreeAdminIds.clear();
|
|
1304
|
+
this._sharedEvictions.clear();
|
|
1305
|
+
this._basesOwedOnCheckout.clear();
|
|
975
1306
|
this._gkConfigReconciler = void 0;
|
|
1307
|
+
for (const registration of this._registrations.values()) {
|
|
1308
|
+
if (registration.timer != null) {
|
|
1309
|
+
clearTimeout(registration.timer);
|
|
1310
|
+
registration.timer = void 0;
|
|
1311
|
+
}
|
|
1312
|
+
registration.wait = void 0;
|
|
1313
|
+
registration.release();
|
|
1314
|
+
}
|
|
1315
|
+
this._registrations.clear();
|
|
976
1316
|
this._caches = createEmptyCaches();
|
|
977
1317
|
this.onDropped(void 0);
|
|
978
1318
|
}
|
|
979
1319
|
/**
|
|
980
1320
|
* Applies a watcher-observed change, sharing reads still in flight (see {@link applyRepositoryChanges}).
|
|
981
|
-
* `options.movedWorktrees`
|
|
1321
|
+
* `options.movedWorktrees` and `options.observedAt` are the event's `movedWorktrees` and `observedAt`.
|
|
982
1322
|
*/
|
|
983
1323
|
onRepositoryChanged(repoPath, changes, options) {
|
|
984
1324
|
const changesSet = new Set(changes);
|
|
@@ -986,7 +1326,10 @@ var Cache = class Cache {
|
|
|
986
1326
|
this.unregisterRepoPath(repoPath);
|
|
987
1327
|
return;
|
|
988
1328
|
}
|
|
989
|
-
this.applyRepositoryChanges(repoPath, changesSet, "share", {
|
|
1329
|
+
this.applyRepositoryChanges(repoPath, changesSet, "share", {
|
|
1330
|
+
movedWorktrees: options?.movedWorktrees,
|
|
1331
|
+
observedAt: options?.observedAt
|
|
1332
|
+
});
|
|
990
1333
|
}
|
|
991
1334
|
/**
|
|
992
1335
|
* Clears what `changes` can have made stale for `repoPath`, advances its status clock, and reconciles a
|
|
@@ -1004,8 +1347,17 @@ var Cache = class Cache {
|
|
|
1004
1347
|
*
|
|
1005
1348
|
* `options.movedWorktrees` names, by admin id (the `<id>` of `.git/worktrees/<id>`), the linked worktrees whose HEAD
|
|
1006
1349
|
* moved, which are all that a `'worktreeHead'` among `changes` reports: each registered one is cleared as for its
|
|
1007
|
-
* own `'head'` change, and no other registered worktree with an admin id of its own is touched. Without it,
|
|
1008
|
-
* linked worktree's HEAD may have moved, so each one but `repoPath` loses its current branch.
|
|
1350
|
+
* own `'head'` change, and no other registered worktree with an admin id of its own is touched. Without it, or empty
|
|
1351
|
+
* (no worktree known), any linked worktree's HEAD may have moved, so each one but `repoPath` loses its current branch.
|
|
1352
|
+
*
|
|
1353
|
+
* Unless `options.worktreeOnly`, a `'worktreeHead'`, announced or not, also drops which branch is checked out in which
|
|
1354
|
+
* worktree for every worktree of the repository, unless `options.movedWorktrees` names no worktree but `repoPath`, or
|
|
1355
|
+
* `options.observedAt` finds it already dropped since (see {@link evictBranchPlacement}).
|
|
1356
|
+
*
|
|
1357
|
+
* `options.observedAt` is the change ordinal (see `nextChangeOrdinal`) taken when the watcher observed the newest of
|
|
1358
|
+
* `changes`. Each checkout of a repository reports a change to what they share, so the shared entries that an eviction
|
|
1359
|
+
* after it already dropped whole, leaving nothing read before to serve or join, are kept: what they hold since was
|
|
1360
|
+
* read after the change. Only those shared entries are kept; everything else is cleared as without it.
|
|
1009
1361
|
*/
|
|
1010
1362
|
applyRepositoryChanges(repoPath, changes, inFlight, options) {
|
|
1011
1363
|
const worktreeOnly = options?.worktreeOnly ?? false;
|
|
@@ -1048,12 +1400,15 @@ var Cache = class Cache {
|
|
|
1048
1400
|
if (hasAny("tags")) types.add("tags");
|
|
1049
1401
|
if (hasAny("worktreeHead")) {
|
|
1050
1402
|
types.add("worktrees");
|
|
1051
|
-
if (!worktreeOnly
|
|
1052
|
-
if (options?.
|
|
1053
|
-
|
|
1403
|
+
if (!worktreeOnly) {
|
|
1404
|
+
if (!options?.announced) {
|
|
1405
|
+
if (options?.movedWorktrees?.size) this.applyLinkedHeadsMoved(repoPath, options.movedWorktrees, inFlight);
|
|
1406
|
+
else this.dropLinkedCurrentBranches(repoPath);
|
|
1407
|
+
}
|
|
1408
|
+
if (!this.movedOnlyItself(repoPath, options?.movedWorktrees)) this.evictBranchPlacement(repoPath, options?.observedAt);
|
|
1054
1409
|
}
|
|
1055
1410
|
} else if (hasAny("worktrees")) types.add("worktreeList");
|
|
1056
|
-
if (types.size) this.clearCachesCore(inFlight, repoPath, [...types], worktreeOnly);
|
|
1411
|
+
if (types.size) this.clearCachesCore(inFlight, repoPath, [...types], worktreeOnly, options?.observedAt);
|
|
1057
1412
|
return [...types];
|
|
1058
1413
|
}
|
|
1059
1414
|
/**
|
|
@@ -1576,9 +1931,10 @@ var Cache = class Cache {
|
|
|
1576
1931
|
/** Clears the cached default branch for one `remote` key (the networked lookup or its `:local` variant). */
|
|
1577
1932
|
deleteDefaultBranchName(repoPath, remote) {
|
|
1578
1933
|
this._caches.defaultBranchName?.delete(this.getCommonPath(repoPath), remote);
|
|
1934
|
+
this.onDropped(repoPath, ["defaultBranchName"]);
|
|
1579
1935
|
}
|
|
1580
|
-
getInitialCommitSha(repoPath, factory) {
|
|
1581
|
-
return this.readValidated(repoPath, () => this.getSharedSimple(this.initialCommitSha, repoPath, factory));
|
|
1936
|
+
getInitialCommitSha(repoPath, factory, cancellation) {
|
|
1937
|
+
return this.readValidated(repoPath, () => this.getSharedSimple(this.initialCommitSha, repoPath, factory, cancellation));
|
|
1582
1938
|
}
|
|
1583
1939
|
/** A rejected factory is never cached (`PromiseMap` evicts on rejection) — a failed read retries next time. */
|
|
1584
1940
|
getEmptyTreeSha(repoPath, factory) {
|
|
@@ -1606,7 +1962,10 @@ var Cache = class Cache {
|
|
|
1606
1962
|
const worktreePath = normalizePath(record.worktreePath);
|
|
1607
1963
|
if (worktreePath !== commonPath && !this._commonPathRegistry.has(worktreePath)) unregistered.add(worktreePath);
|
|
1608
1964
|
}
|
|
1609
|
-
if (!cacheable.invalidated && !signal?.aborted && this.getCloseGeneration(commonPath) === closeGeneration)
|
|
1965
|
+
if (!cacheable.invalidated && !signal?.aborted && this.getCloseGeneration(commonPath) === closeGeneration) {
|
|
1966
|
+
this.replaceSeededWorktrees(commonPath, unregistered);
|
|
1967
|
+
this.dropBasesOwedOnCheckout(commonPath, records, read.at);
|
|
1968
|
+
}
|
|
1610
1969
|
return records;
|
|
1611
1970
|
}, cancellation);
|
|
1612
1971
|
}
|
|
@@ -1631,6 +1990,14 @@ var Cache = class Cache {
|
|
|
1631
1990
|
values: data.values.map((t) => t.withRepoPath(newRepoPath))
|
|
1632
1991
|
}), cancellation));
|
|
1633
1992
|
}
|
|
1993
|
+
/**
|
|
1994
|
+
* The tag list shared by `repoPath`'s worktrees, as the common path holds it, without keeping a copy for
|
|
1995
|
+
* `repoPath`. A caller maps the tags it needs with {@link GitTag.withRepoPath}; {@link getTags} keeps a mapped copy
|
|
1996
|
+
* per worktree.
|
|
1997
|
+
*/
|
|
1998
|
+
getSharedTags(repoPath, factory, cancellation) {
|
|
1999
|
+
return this.readValidated(repoPath, () => this.getSharedEntry(this.tags, repoPath, factory, cancellation));
|
|
2000
|
+
}
|
|
1634
2001
|
async getWorktrees(repoPath, factory, options, cancellation) {
|
|
1635
2002
|
return this.readValidated(repoPath, () => {
|
|
1636
2003
|
if (options?.force) {
|
|
@@ -1640,9 +2007,13 @@ var Cache = class Cache {
|
|
|
1640
2007
|
return this.getSharedOrCreate(this.worktrees, repoPath, factory, (data, newRepoPath) => data.map((w) => w.withRepoPath(newRepoPath)), cancellation);
|
|
1641
2008
|
});
|
|
1642
2009
|
}
|
|
1643
|
-
|
|
2010
|
+
/**
|
|
2011
|
+
* The entry shared by `repoPath`'s worktrees, as the common path holds it. A caller maps what it needs for
|
|
2012
|
+
* `repoPath`; {@link getSharedOrCreate} keeps a mapped copy per worktree.
|
|
2013
|
+
*/
|
|
2014
|
+
getSharedEntry(cache, repoPath, factory, cancellation) {
|
|
1644
2015
|
const commonPath = this.getCommonPath(repoPath);
|
|
1645
|
-
|
|
2016
|
+
return cache.getOrCreate(commonPath, (cacheable, signal) => {
|
|
1646
2017
|
const p = Promise.resolve(factory(commonPath, cacheable, signal));
|
|
1647
2018
|
p.finally(() => {
|
|
1648
2019
|
if (cacheable.invalidated) for (const worktreePath of this.getWorktreePaths(commonPath)) {
|
|
@@ -1652,12 +2023,18 @@ var Cache = class Cache {
|
|
|
1652
2023
|
}).catch(() => {});
|
|
1653
2024
|
return p;
|
|
1654
2025
|
}, cancellation);
|
|
2026
|
+
}
|
|
2027
|
+
async getSharedOrCreate(cache, repoPath, factory, mapper, cancellation) {
|
|
2028
|
+
const commonPath = this.getCommonPath(repoPath);
|
|
2029
|
+
const sharedPromise = this.getSharedEntry(cache, repoPath, factory, cancellation);
|
|
1655
2030
|
sharedPromise.catch(() => {});
|
|
1656
2031
|
if (commonPath !== repoPath) {
|
|
1657
|
-
|
|
1658
|
-
if (existing != null) return cancellation != null ? raceWithSignal(existing, cancellation) : existing;
|
|
2032
|
+
if (cancellation?.aborted) return sharedPromise;
|
|
1659
2033
|
const rawShared = cache.get(commonPath) ?? sharedPromise;
|
|
2034
|
+
const existing = cache.get(repoPath);
|
|
2035
|
+
if (existing != null && this._mappedFrom.get(existing) === rawShared) return cancellation != null ? raceWithSignal(existing, cancellation) : existing;
|
|
1660
2036
|
const mappedPromise = Promise.resolve(rawShared).then((data) => mapper(data, repoPath));
|
|
2037
|
+
this._mappedFrom.set(mappedPromise, rawShared);
|
|
1661
2038
|
cache.set(repoPath, mappedPromise);
|
|
1662
2039
|
return cancellation != null ? raceWithSignal(mappedPromise, cancellation) : mappedPromise;
|
|
1663
2040
|
}
|
|
@@ -1678,10 +2055,12 @@ var Cache = class Cache {
|
|
|
1678
2055
|
}, options);
|
|
1679
2056
|
sharedPromise.catch(() => {});
|
|
1680
2057
|
if (commonPath !== repoPath) {
|
|
1681
|
-
|
|
1682
|
-
if (existing != null) return cancellation != null ? raceWithSignal(existing, cancellation) : existing;
|
|
2058
|
+
if (cancellation?.aborted) return sharedPromise;
|
|
1683
2059
|
const rawShared = cache.get(commonPath, cacheKey) ?? sharedPromise;
|
|
2060
|
+
const existing = cache.get(repoPath, cacheKey);
|
|
2061
|
+
if (existing != null && this._mappedFrom.get(existing) === rawShared) return cancellation != null ? raceWithSignal(existing, cancellation) : existing;
|
|
1684
2062
|
const mappedPromise = Promise.resolve(rawShared).then((data) => mapper(data, repoPath));
|
|
2063
|
+
this._mappedFrom.set(mappedPromise, rawShared);
|
|
1685
2064
|
cache.set(repoPath, cacheKey, mappedPromise, options);
|
|
1686
2065
|
return cancellation != null ? raceWithSignal(mappedPromise, cancellation) : mappedPromise;
|
|
1687
2066
|
}
|