@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
package/CHANGELOG.md CHANGED
@@ -6,6 +6,26 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.35.0] - 2026-11-08
10
+
11
+ ### Changed
12
+
13
+ - **Breaking (plus/git-github, plus/integrations)** — GitHub.com pull request reads no longer select merge-queue data unless the host opts in with `ConfigProvider.getPullRequestReadOptions` (`{ mergeQueue: true }`; `GitHubApiConfig.getPullRequestReadOptions` for a `GitHubApi` built directly), or per read with `mergeQueue` on `listPullRequestsPage`, `searchPullRequestsPage`, `getPullRequestsBatch`, `getPullRequestsForBranches`, `sweepPullRequests` and `sweepClosedPullRequests` (`true` selects it, `false` doesn't, omitted follows the host; the host-cached point reads follow the host alone, and a repo-scoped list or sweep goes through provider-apis, which selects none). Without the selection (`mergeQueue: false`, or neither the read nor the host asking for it), rows carry no `mergeQueue`, `mergeQueueRequired` or `mergeQueueRemoval`, `getPullRequestFieldPresence` answers `mergeQueue: 'not-requested'`, the etag cheap check selects no queue state, and no pull request's etag carries queue state or a removal (so a pull request joining, moving through or leaving a queue, or joining and being removed between two checks, no longer reads as changed), and reads cost what they did before 0.34.0 (the `timelineItems(last: 1)` connection, one rate-limit request per row, is gone: e.g. a 30-row full search page is 1 point instead of 2 and a 25-branch `getPullRequestsForBranches` chunk 10 instead of 13). `getMergeQueueEntriesForBranches`, `enqueuePullRequest` and `dequeuePullRequest` are unaffected. A read with merge-queue data adds a marker to every etag it computes, so an etag stored by a read made the other way compares changed once and is read in full again, as does every 0.34.0 etag once a read selects the data. A read without it computes the etag it did before 0.34.0, so under such a read a held 0.34.0 etag of a pull request that wasn't queued or removed still compares unchanged, and its row keeps the merge-queue fields it was read with until it next changes
14
+
15
+ ## [0.34.0] - 2026-11-08
16
+
17
+ ### Added
18
+
19
+ - Adds `mergeQueue` (`PullRequestMergeQueueEntry`) to pull requests read from GitHub.com, set while a pull request waits in its base branch's merge queue: its `state` (`PullRequestMergeQueueState`), `enqueuedAt`, `estimatedMergeAt` when GitHub gives an estimate (GitHub's time remaining, fixed to a date when the pull request is read, so a held entry counts down; it may be past on an entry held a while), and the queue's `url`. A queued pull request's `state` stays `opened`. Field presence gains a `mergeQueue` group, `fetched` wherever `stack` is and `unavailable` on GitHub Enterprise, which isn't asked for it, and on every other provider; absent `mergeQueue` means not queued only where that group is `fetched`. Adds `isPullRequestInMergeQueue` to tell whether an open pull request is queued. On GitHub.com a queued pull request's batch-read etag also covers its queue state and enqueue time, which GitHub changes without moving the update time, with no `etagIncludes` needed; the cheap check selects them there, and a pull request that isn't queued keeps exactly the etag it had before, under any `etagIncludes` (git, plus/git-github, plus/integrations)
20
+ - Adds `position` (1-based, in enqueue order) to `PullRequestMergeQueueEntry`, and `mergeQueueRequired` and `mergeQueueRemoval` (`PullRequestMergeQueueRemoval`: GitHub's raw `reason` and `removedAt`) to pull requests read from GitHub.com, all under the `mergeQueue` field presence group. `mergeQueueRemoval` is set only while the pull request's latest merge-queue event is a removal that didn't merge it; adds `getPullRequestMergeQueueRemovalKind` to classify its reason (`failed`, `manual`, `other`) and `isPullRequestMergeQueueRemovalCurrent` to tell whether it still describes the pull request (open, not queued, not updated since). The read selects one more connection per pull request (`timelineItems(last: 1)`) against github.com, costing one more rate-limit request per row. On GitHub.com a removed pull request's batch-read etag also covers its removal time, so a pull request that joined and left the queue between two checks reads as changed; any other pull request keeps exactly the etag it had, under any `etagIncludes`. On upgrade, a pull request whose latest merge-queue event is already such a removal gets a new etag once, so a stored etag reads it as changed one time (git, plus/git-github, plus/integrations)
21
+ - Adds `GitHubApi.enqueuePullRequest` and `dequeuePullRequest`, which add a pull request to its merge queue at the expected head and remove it, on GitHub.com only, answering a `PullRequestMergeQueueActionResult`: `queued` (with the new entry), `dequeued`, or `failed` with a `PullRequestMergeQueueActionFailureReason` (`already-queued`, `head-changed`, `not-allowed`, `permission`, `unsupported`, `unknown`) and GitHub's message, for logs. A FORBIDDEN refusal is the account's `permission` and doesn't prompt to re-authenticate. Neither is ever retried. `GitHostIntegration` gains `enqueuePullRequest` and `dequeuePullRequest` beside `mergePullRequest`, answering `unsupported` on every other host; like `mergePullRequest`, it is reachable through neither `index.js` nor `lite.js` (plus/git-github, plus/integrations)
22
+ - Adds per-repository trust: `GitOptions.isTrusted` now takes the path a run targets (`(repoPath: string) => boolean`) so a host serving several repositories can refuse one while the others run. A refused path rejects with `WorkspaceUntrustedError` before any git process starts, for `run` and `stream` alike. The path is the run's `cwd` resolved to an absolute, normalized path (the process's working directory when it has none or an empty one), so a `..` segment can't lead it out of a trusted folder, and, when a run re-scopes itself with `-C`, that target too, even behind a global option that takes a separate value such as `--attr-source`; an absolute `-C` target is asked about alone, since git applies it before reading anything, so the starting directory isn't. A working directory that no longer exists (the process's own was deleted) refuses with `WorkspaceUntrustedError`, and `WorkspaceUntrustedError.path` carries the path the host refused (none for that case). A run that moves its repository another way is asked about where it moves it as well: a leading `--git-dir` (the git dir path itself, so `/repo/.git` for a host that trusts `/repo`) or `--work-tree`, and `GIT_DIR`, `GIT_COMMON_DIR` or `GIT_WORK_TREE` in the run's own `env` (every key spelling one, without regard to case), each resolved against the directory the run ends up in, and one refused path refuses the run. Only an answer of exactly `true` trusts; a predicate that returns anything else refuses, and no predicate trusts every path. The config provider's no-git fallbacks (`getRepositoryInfo`'s empty answer, reading git dirs without git) apply per repository. A trusted bare repository inside a refused folder still resolves as bare, rather than rejecting. A refused path's fallback git dir and its current user aren't kept, and `onGitDirResolveFailed` doesn't fire for it, so once the host trusts the path the next call reads them; a host that starts trusting a path should still reset that repository's caches, since nothing tells core the answer changed. `CliGitProvider` and `createCliGitService` now keep a host's `gitOptions.isTrusted` instead of overwriting it; a `context.workspace.isTrusted` flag still wins and answers for every path, so a single-workspace host such as VS Code behaves as before. Adds `Git.isPathTrusted(repoPath)` (git-cli)
23
+ - Adds `validateUnwatchedCaches` to `createCliGitService`, off by default: before a read of a cache that only a change report, core's own writes or an explicit clear drops in time (branches, current branch and its reference, refs and their tips, tags, remotes, worktrees, stashes, gk config, paused operation, and the best remotes, default and base branch names, merge targets, branch metadata, initial commit and resolved revisions derived from them, commit counts, reachability, branch overviews, contributors, the current user, the ahead-of-base and gitignore config listings, and the git runs core caches, many keyed by ref names), a repository whose `.git` directory nothing watches has the files a watcher would report statted, with its ref directories and worktree admin entries listed, and what moved applied as a watcher event would, at most once per 250ms per repository; a watched repository costs nothing. A repository is validated even when nothing resolved its git dir yet, which is then read from its own files without running git (one only git can answer for, as a bare repository or a submodule, isn't validated until a read resolves it, and its files are looked at again for it only every 30 seconds), and adding, removing or changing a worktree under an `ignoredWorktreeFolders` folder clears nothing. A read waits at most 1000ms for those stats (`validateUnwatchedCaches: { timeoutMs }` changes it) and is then served from the cache as is, its reads not waiting again until that validation settles; the stats run one at a time per repository and two at once overall, and one outstanding past that timeout stops counting against the two, so a hung mount doesn't stop other repositories' validations, while the stats hold no more than all but two of Node's file-system threads (`UV_THREADPOOL_SIZE`, default 4; the validator's `maxFsThreads`), so at the default pool size two hung stats still stop them. A linked worktree's first validation reports only what its own git dir can, leaving the shared entries to the common git dir's. A path that can't be read counts as moved as it becomes unreadable and again once it reads, and a directory that can't be listed (or a ref folder nested too deep for one validation) is listed again at the next validation, so neither clears every cache on each read. Built from `UnwatchedCacheValidator` (`watching/unwatchedCacheValidator.js`), which validates again as a watcher attaches and, as one detaches or at the next validation once it is suspended, applies what moved in a common git dir that a sibling's validation left to it; `RepositoryWatchService.isRepoWatched` and `onDidChangeRepoWatched`, which tell when a repository's `.git` directory starts and stops being watched (a repository whose watch session is suspended counts as unwatched meanwhile, without being announced); `Cache.setReadValidator`, which registers what runs before those reads (and, as its second argument, what it costs, which `Cache.getResourceUsage` reports: `UnwatchedCacheValidator.getResourceUsage` counts the validations run and those that cleared anything, the reads served as is after a timed-out wait, the git dir lookups and file-system calls, the calls stuck on a hung mount and the git dirs kept, under `unwatchedValidation.*`), with `Cache.validateBeforeRead` for a read made without the cache's wrappers; and `ConfigGitSubProvider.resolveGitDirWithoutGit`, which caches a git dir read from a repository's own files, never running git (rejecting when its answer may differ if asked again soon: a read that failed in a way that may pass, as a share that timed out, or a repository closed mid-read). `GitDirProbeTarget` takes an `isRacy` option, under which a reading too recent to trust counts as moved at the next poll, given the path it was read from; the validator trusts a whole-second reading once two seconds passed since it first saw it, so a file system whose clock runs ahead of ours doesn't have every reading counted as moved (git, git-cli)
24
+
25
+ ### Fixed
26
+
27
+ - Fixes `getCommitReachability` keeping the tags a commit is reachable from across a tag created or deleted: a `'tags'` change now clears the reachability cache too, as a branch change does (git)
28
+
9
29
  ## [0.33.0] - 2026-11-06
10
30
 
11
31
  ### Added
@@ -1173,7 +1193,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1173
1193
 
1174
1194
  - Initial release. Bundles `@gitlens/utils`, `@gitlens/git`, `@gitlens/git-cli`, `@gitlens/ai`, and `@gitlens/git-github` into a single core npm package with subpath exports.
1175
1195
 
1176
- [unreleased]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.33.0...HEAD
1196
+ [unreleased]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.35.0...HEAD
1197
+ [0.35.0]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.34.0...gitkraken:releases/core/v0.35.0
1198
+ [0.34.0]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.33.0...gitkraken:releases/core/v0.34.0
1177
1199
  [0.33.0]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.32.0...gitkraken:releases/core/v0.33.0
1178
1200
  [0.32.0]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.31.0...gitkraken:releases/core/v0.32.0
1179
1201
  [0.31.0]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.30.0...gitkraken:releases/core/v0.31.0
@@ -185,8 +185,34 @@ export declare class Cache implements Disposable {
185
185
  * falls back to the coarse clear.
186
186
  */
187
187
  private _gkConfigReconciler;
188
+ /** Run before each read of a cache with no expiry (see {@link setReadValidator}) */
189
+ private _readValidator;
190
+ /** What the read validator reports among {@link getResourceUsage}'s */
191
+ private _readValidatorUsage;
188
192
  [Symbol.dispose](): void;
189
193
  dispose(): void;
194
+ /**
195
+ * Registers what runs before each read of the caches that only a change report, core's own writes or an explicit
196
+ * clear drop in time (the branches, current branch and its reference, refs and their tips, tags, remotes, worktrees,
197
+ * stashes, gk config, paused operation, and what is derived from them: default and base branch names, merge
198
+ * targets, branch metadata, the initial commit, resolved revisions, commit counts, reachability, branch overviews,
199
+ * contributors, the current user, the ahead-of-base and gitignore config listings, and the cached git runs). It
200
+ * answers `undefined` when the read can go ahead at once, or a promise that settles, never rejecting, once it
201
+ * applied whatever changed (as {@link onRepositoryChanged}), after which the read runs. A host that watches only
202
+ * some repositories registers one that checks the others' git dirs (see `UnwatchedCacheValidator`); `undefined`
203
+ * removes it. Kept across {@link reset}: it is host wiring, not cached state. `getResourceUsage` reports what it
204
+ * costs among {@link getResourceUsage}'s.
205
+ */
206
+ setReadValidator(validator: ((repoPath: string) => Promise<void> | undefined) | undefined, getResourceUsage?: () => ResourceUsage): void;
207
+ /**
208
+ * Runs the read validator (see {@link setReadValidator}) for a read of one of its caches made without the wrappers
209
+ * here: `undefined` when the read can go ahead at once, or a promise (that never rejects) to read after
210
+ */
211
+ validateBeforeRead(repoPath: string): Promise<void> | undefined;
212
+ /** Runs `read` once the read validator let `repoPath` be read, at once when it has nothing to wait for */
213
+ private readValidated;
214
+ /** A map read directly by the providers, whose every `getOrCreate` is validated as the cache's own reads are */
215
+ private createValidatedRepoPromiseCacheMap;
190
216
  /** Resource usage retained by instantiated sub-caches and their bookkeeping maps. */
191
217
  getResourceUsage(): ResourceUsage;
192
218
  get aheadOfBaseConfigKey(): PromiseMap<RepoPath, string | undefined>;
@@ -452,9 +478,11 @@ export declare class Cache implements Disposable {
452
478
  * it needs for `repoPath`; {@link getBranches} keeps a mapped copy per worktree.
453
479
  */
454
480
  getSharedBranches(repoPath: string, factory: (commonPath: string, cacheable: CacheController, cancellation?: AbortSignal) => PromiseOrValue<PagedResult<GitBranch>>, cancellation?: AbortSignal): Promise<PagedResult<GitBranch>>;
481
+ private getSharedBranchesCore;
455
482
  /** Whether `result`, from {@link getSharedBranches}, is still the list kept for `repoPath`: not refused, replaced or evicted */
456
483
  isSharedBranchesKept(repoPath: string, result: PagedResult<GitBranch>): boolean;
457
484
  getBranches(repoPath: string, factory: (commonPath: string, cacheable: CacheController, cancellation?: AbortSignal) => PromiseOrValue<PagedResult<GitBranch>>, mapper: (branches: PagedResult<GitBranch>, targetRepoPath: string, commonPath: string, cancellation?: AbortSignal) => PromiseOrValue<PagedResult<GitBranch>>, cancellation?: AbortSignal): Promise<PagedResult<GitBranch>>;
485
+ private getBranchesCore;
458
486
  private static readonly globalConfigKey;
459
487
  /**
460
488
  * Keyed by `repoPath` itself, not its common path: git reads a worktree's own `config.worktree` too, so worktrees
@@ -561,6 +589,7 @@ export declare class Cache implements Disposable {
561
589
  cancellation?: AbortSignal;
562
590
  }): Promise<GitContributorsStats | undefined>;
563
591
  getBaseBranchName(repoPath: string, ref: string, factory: (commonPath: string, cacheable: CacheController, cancellation?: AbortSignal) => PromiseOrValue<string | undefined>, cancellation?: AbortSignal): Promise<string | undefined>;
592
+ private getBaseBranchNameCore;
564
593
  /**
565
594
  * Clears the cached base branch for `ref`. Call from ops that create/rename/delete a branch — the
566
595
  * `'branches'` cascade no longer clears these, since tip movement can't change a branch's base.
@@ -617,6 +646,7 @@ export declare class Cache implements Disposable {
617
646
  * (see {@link CachedMergeTarget}). A checkout evicts only the entries marked `evictOnCheckout`
618
647
  */
619
648
  getMergeTarget(repoPath: string, cacheKey: string, factory: (commonPath: string, cacheable: CacheController, cancellation?: AbortSignal) => PromiseOrValue<CachedMergeTarget>, cancellation?: AbortSignal): Promise<CachedMergeTarget>;
649
+ private getMergeTargetCore;
620
650
  /**
621
651
  * Drops `stale`, an answer {@link getMergeTarget} gave for `cacheKey`, unless it was already replaced: callers that
622
652
  * found the same answer stale then share the one that replaced it rather than each resolving their own
@@ -630,6 +660,7 @@ export declare class Cache implements Disposable {
630
660
  getEmptyTreeSha(repoPath: string, factory: (commonPath: string) => PromiseOrValue<string>): Promise<string>;
631
661
  getLastFetchedTimestamp(repoPath: string, factory: (commonPath: string) => PromiseOrValue<number | undefined>): Promise<number | undefined>;
632
662
  getRefs(repoPath: string, factory: (commonPath: string, cacheable: CacheController, cancellation?: AbortSignal) => PromiseOrValue<RefRecord[]>, cancellation?: AbortSignal): Promise<RefRecord[]>;
663
+ private getRefsCore;
633
664
  getRefTips(repoPath: string, factory: (commonPath: string, cacheable: CacheController, cancellation?: AbortSignal) => PromiseOrValue<GitRefTip[]>, cancellation?: AbortSignal): Promise<GitRefTip[]>;
634
665
  getRemotes(repoPath: string, factory: (commonPath: string, cacheable: CacheController, cancellation?: AbortSignal) => PromiseOrValue<GitRemote[]>, cancellation?: AbortSignal): Promise<GitRemote[]>;
635
666
  getStash(repoPath: string, cacheKey: string, factory: (commonPath: string, cacheable: CacheController, cancellation?: AbortSignal) => PromiseOrValue<GitStash>, options?: {
package/dist/git/cache.js CHANGED
@@ -221,13 +221,51 @@ var Cache = class Cache {
221
221
  * falls back to the coarse clear.
222
222
  */
223
223
  _gkConfigReconciler;
224
+ /** Run before each read of a cache with no expiry (see {@link setReadValidator}) */
225
+ _readValidator;
226
+ /** What the read validator reports among {@link getResourceUsage}'s */
227
+ _readValidatorUsage;
224
228
  [Symbol.dispose]() {
225
229
  this.dispose();
226
230
  }
227
231
  dispose() {
228
232
  this.reset();
233
+ this._readValidator = void 0;
234
+ this._readValidatorUsage = void 0;
229
235
  this._onDidChangeMergeTargets.dispose();
230
236
  }
237
+ /**
238
+ * Registers what runs before each read of the caches that only a change report, core's own writes or an explicit
239
+ * clear drop in time (the branches, current branch and its reference, refs and their tips, tags, remotes, worktrees,
240
+ * stashes, gk config, paused operation, and what is derived from them: default and base branch names, merge
241
+ * targets, branch metadata, the initial commit, resolved revisions, commit counts, reachability, branch overviews,
242
+ * contributors, the current user, the ahead-of-base and gitignore config listings, and the cached git runs). It
243
+ * answers `undefined` when the read can go ahead at once, or a promise that settles, never rejecting, once it
244
+ * applied whatever changed (as {@link onRepositoryChanged}), after which the read runs. A host that watches only
245
+ * some repositories registers one that checks the others' git dirs (see `UnwatchedCacheValidator`); `undefined`
246
+ * removes it. Kept across {@link reset}: it is host wiring, not cached state. `getResourceUsage` reports what it
247
+ * costs among {@link getResourceUsage}'s.
248
+ */
249
+ setReadValidator(validator, getResourceUsage) {
250
+ this._readValidator = validator;
251
+ this._readValidatorUsage = validator != null ? getResourceUsage : void 0;
252
+ }
253
+ /**
254
+ * Runs the read validator (see {@link setReadValidator}) for a read of one of its caches made without the wrappers
255
+ * here: `undefined` when the read can go ahead at once, or a promise (that never rejects) to read after
256
+ */
257
+ validateBeforeRead(repoPath) {
258
+ return this._readValidator?.(repoPath);
259
+ }
260
+ /** Runs `read` once the read validator let `repoPath` be read, at once when it has nothing to wait for */
261
+ readValidated(repoPath, read) {
262
+ const validation = this._readValidator?.(repoPath);
263
+ return validation != null ? validation.then(read) : read();
264
+ }
265
+ /** A map read directly by the providers, whose every `getOrCreate` is validated as the cache's own reads are */
266
+ createValidatedRepoPromiseCacheMap(options) {
267
+ return new ValidatedRepoPromiseCacheMap((repoPath) => this._readValidator?.(repoPath), options);
268
+ }
231
269
  /** Resource usage retained by instantiated sub-caches and their bookkeeping maps. */
232
270
  getResourceUsage() {
233
271
  const usage = {};
@@ -241,6 +279,7 @@ var Cache = class Cache {
241
279
  usage["cache.currentBranchDroppedAt.entries.count"] = this._droppedAt.currentBranchReference.byPath.size;
242
280
  usage["cache.currentUserDroppedAt.entries.count"] = this._droppedAt.currentUser.byPath.size;
243
281
  usage["cache.seededWorktrees.entries.count"] = this._seededWorktrees.size;
282
+ if (this._readValidatorUsage != null) Object.assign(usage, this._readValidatorUsage());
244
283
  return usage;
245
284
  }
246
285
  get aheadOfBaseConfigKey() {
@@ -461,7 +500,7 @@ var Cache = class Cache {
461
500
  return this._caches.gitIgnore ??= /* @__PURE__ */ new Map();
462
501
  }
463
502
  get gitResults() {
464
- return this._caches.gitResults ??= new RepoPromiseCacheMap({ capacity: 200 });
503
+ return this._caches.gitResults ??= this.createValidatedRepoPromiseCacheMap({ capacity: 200 });
465
504
  }
466
505
  get ignoreConfigListing() {
467
506
  return this._caches.ignoreConfigListing ??= new PromiseMap();
@@ -485,7 +524,7 @@ var Cache = class Cache {
485
524
  });
486
525
  }
487
526
  get commitCount() {
488
- return this._caches.commitCount ??= new RepoPromiseCacheMap({
527
+ return this._caches.commitCount ??= this.createValidatedRepoPromiseCacheMap({
489
528
  accessTTL: 36e5,
490
529
  capacity: 50
491
530
  });
@@ -529,7 +568,7 @@ var Cache = class Cache {
529
568
  return this._caches.refTips ??= new PromiseMap();
530
569
  }
531
570
  get reachability() {
532
- return this._caches.reachability ??= new RepoPromiseCacheMap({
571
+ return this._caches.reachability ??= this.createValidatedRepoPromiseCacheMap({
533
572
  accessTTL: 36e5,
534
573
  capacity: 25
535
574
  });
@@ -680,6 +719,7 @@ var Cache = class Cache {
680
719
  keysToClear.add("resolvedRevisions");
681
720
  keysToClear.add("leftRightCommitCount");
682
721
  keysToClear.add("mergeBase");
722
+ keysToClear.add("reachability");
683
723
  }
684
724
  if (types.includes("tracking")) {
685
725
  keysToClear.add("fileExistence");
@@ -1077,6 +1117,9 @@ var Cache = class Cache {
1077
1117
  * it needs for `repoPath`; {@link getBranches} keeps a mapped copy per worktree.
1078
1118
  */
1079
1119
  getSharedBranches(repoPath, factory, cancellation) {
1120
+ return this.readValidated(repoPath, () => this.getSharedBranchesCore(repoPath, factory, cancellation));
1121
+ }
1122
+ getSharedBranchesCore(repoPath, factory, cancellation) {
1080
1123
  const commonPath = this.getCommonPath(repoPath);
1081
1124
  return this.sharedBranches.getOrCreate(commonPath, (cacheable, signal) => {
1082
1125
  const p = Promise.resolve(factory(commonPath, cacheable, signal));
@@ -1094,8 +1137,11 @@ var Cache = class Cache {
1094
1137
  return this._caches.sharedBranches?.getSettled(this.getCommonPath(repoPath))?.value === result;
1095
1138
  }
1096
1139
  getBranches(repoPath, factory, mapper, cancellation) {
1140
+ return this.readValidated(repoPath, () => this.getBranchesCore(repoPath, factory, mapper, cancellation));
1141
+ }
1142
+ getBranchesCore(repoPath, factory, mapper, cancellation) {
1097
1143
  const commonPath = this.getCommonPath(repoPath);
1098
- const registration = this.getSharedBranches(repoPath, factory, cancellation);
1144
+ const registration = this.getSharedBranchesCore(repoPath, factory, cancellation);
1099
1145
  registration.catch(() => {});
1100
1146
  return this.branches.getOrCreate(repoPath, (_cacheable, mapperSignal) => {
1101
1147
  const rawShared = this.sharedBranches.get(commonPath) ?? registration;
@@ -1150,12 +1196,12 @@ var Cache = class Cache {
1150
1196
  * `reconcileGkConfigMap`; later refreshes of that snapshot are owned by the reconcile itself.
1151
1197
  */
1152
1198
  getGkConfigMap(repoPath, factory) {
1153
- return this.getSharedSimple(this.gkConfigMap, repoPath, async (commonPath, cacheable) => {
1199
+ return this.readValidated(repoPath, () => this.getSharedSimple(this.gkConfigMap, repoPath, async (commonPath, cacheable) => {
1154
1200
  const closeGeneration = this.getCloseGeneration(commonPath);
1155
1201
  const map = await factory(cacheable);
1156
1202
  if (!this._gkConfigSnapshots.has(commonPath) && this.isReadPathCurrent(commonPath, closeGeneration)) this._gkConfigSnapshots.set(commonPath, this.extractReconciledGkConfig(map));
1157
1203
  return map;
1158
- });
1204
+ }));
1159
1205
  }
1160
1206
  /** Whether a read that started under the common path `path` may still seed state for it: not registered or closed since */
1161
1207
  isReadPathCurrent(path, closeGeneration) {
@@ -1322,25 +1368,28 @@ var Cache = class Cache {
1322
1368
  }
1323
1369
  }
1324
1370
  async getBranchOverview(repoPath, cacheKey, factory, options) {
1325
- return this.getSharedOrCreateWithKey(this.branchOverviews, repoPath, cacheKey, factory, (data, newRepoPath) => data == null ? data : {
1371
+ return this.readValidated(repoPath, () => this.getSharedOrCreateWithKey(this.branchOverviews, repoPath, cacheKey, factory, (data, newRepoPath) => data == null ? data : {
1326
1372
  ...data,
1327
1373
  repoPath: newRepoPath,
1328
1374
  contributors: data.contributors.map((c) => c.withRepoPath(newRepoPath))
1329
- }, options);
1375
+ }, options));
1330
1376
  }
1331
1377
  async getContributors(repoPath, cacheKey, factory, options) {
1332
- return this.getSharedOrCreateWithKey(this.contributors, repoPath, cacheKey, factory, (data, newRepoPath) => ({
1378
+ return this.readValidated(repoPath, () => this.getSharedOrCreateWithKey(this.contributors, repoPath, cacheKey, factory, (data, newRepoPath) => ({
1333
1379
  ...data,
1334
1380
  contributors: data.contributors.map((c) => c.withRepoPath(newRepoPath))
1335
- }), options);
1381
+ }), options));
1336
1382
  }
1337
1383
  async getContributorsLite(repoPath, cacheKey, factory, options) {
1338
- return this.getSharedOrCreateWithKey(this.contributorsLite, repoPath, cacheKey, factory, (data, newRepoPath) => data.map((c) => c.withRepoPath(newRepoPath)), options);
1384
+ return this.readValidated(repoPath, () => this.getSharedOrCreateWithKey(this.contributorsLite, repoPath, cacheKey, factory, (data, newRepoPath) => data.map((c) => c.withRepoPath(newRepoPath)), options));
1339
1385
  }
1340
1386
  getContributorsStats(repoPath, cacheKey, factory, options) {
1341
- return this.getSharedSimpleWithKey(this.contributorsStats, repoPath, cacheKey, factory, options);
1387
+ return this.readValidated(repoPath, () => this.getSharedSimpleWithKey(this.contributorsStats, repoPath, cacheKey, factory, options));
1342
1388
  }
1343
1389
  getBaseBranchName(repoPath, ref, factory, cancellation) {
1390
+ return this.readValidated(repoPath, () => this.getBaseBranchNameCore(repoPath, ref, factory, cancellation));
1391
+ }
1392
+ getBaseBranchNameCore(repoPath, ref, factory, cancellation) {
1344
1393
  return this.getSharedSimpleWithKey(this.baseBranchName, repoPath, ref, factory, {
1345
1394
  createTTL: baseBranchNameTTL,
1346
1395
  cancellation
@@ -1443,7 +1492,7 @@ var Cache = class Cache {
1443
1492
  }
1444
1493
  /** Config can differ by checkout through config.worktree and conditional includes. */
1445
1494
  getAheadOfBaseConfigKey(repoPath, factory, cancellation) {
1446
- return this.aheadOfBaseConfigKey.getOrCreate(repoPath, (cacheable, signal) => Promise.resolve(factory(repoPath, cacheable, signal)), cancellation);
1495
+ return this.readValidated(repoPath, () => this.aheadOfBaseConfigKey.getOrCreate(repoPath, (cacheable, signal) => Promise.resolve(factory(repoPath, cacheable, signal)), cancellation));
1447
1496
  }
1448
1497
  /**
1449
1498
  * One listing for every checkout of a repository, which serves a checkout's {@link getAheadOfBaseConfigKey} while
@@ -1451,7 +1500,7 @@ var Cache = class Cache {
1451
1500
  * before it.
1452
1501
  */
1453
1502
  getAheadOfBaseConfigListing(repoPath, factory, cancellation) {
1454
- return this.getSharedSimple(this.aheadOfBaseConfigListing, repoPath, factory, cancellation);
1503
+ return this.readValidated(repoPath, () => this.getSharedSimple(this.aheadOfBaseConfigListing, repoPath, factory, cancellation));
1455
1504
  }
1456
1505
  /**
1457
1506
  * One listing of the gitignore filter's config inputs for every checkout of a repository, which serves a checkout's
@@ -1459,13 +1508,13 @@ var Cache = class Cache {
1459
1508
  * from before it.
1460
1509
  */
1461
1510
  getIgnoreConfigListing(repoPath, factory, cancellation) {
1462
- return this.getSharedSimple(this.ignoreConfigListing, repoPath, factory, cancellation);
1511
+ return this.readValidated(repoPath, () => this.getSharedSimple(this.ignoreConfigListing, repoPath, factory, cancellation));
1463
1512
  }
1464
1513
  getBranchMetadataMap(repoPath, factory) {
1465
- return this.getSharedSimple(this.branchMetadataMap, repoPath, factory);
1514
+ return this.readValidated(repoPath, () => this.getSharedSimple(this.branchMetadataMap, repoPath, factory));
1466
1515
  }
1467
1516
  getDefaultBranchName(repoPath, remote, factory, cancellation) {
1468
- return this.getSharedSimpleWithKey(this.defaultBranchName, repoPath, remote, factory, { cancellation });
1517
+ return this.readValidated(repoPath, () => this.getSharedSimpleWithKey(this.defaultBranchName, repoPath, remote, factory, { cancellation }));
1469
1518
  }
1470
1519
  /** The cached default branch for one `remote` key, without reading it; `undefined` when none is cached */
1471
1520
  peekDefaultBranchName(repoPath, remote) {
@@ -1476,6 +1525,9 @@ var Cache = class Cache {
1476
1525
  * (see {@link CachedMergeTarget}). A checkout evicts only the entries marked `evictOnCheckout`
1477
1526
  */
1478
1527
  getMergeTarget(repoPath, cacheKey, factory, cancellation) {
1528
+ return this.readValidated(repoPath, () => this.getMergeTargetCore(repoPath, cacheKey, factory, cancellation));
1529
+ }
1530
+ getMergeTargetCore(repoPath, cacheKey, factory, cancellation) {
1479
1531
  const pending = this.getSharedSimpleWithKey(this.mergeTargets, repoPath, cacheKey, async (commonPath, cacheable, signal) => {
1480
1532
  const generation = this._mergeTargetCheckoutGeneration;
1481
1533
  const closeGeneration = this.getCloseGeneration(commonPath);
@@ -1526,7 +1578,7 @@ var Cache = class Cache {
1526
1578
  this._caches.defaultBranchName?.delete(this.getCommonPath(repoPath), remote);
1527
1579
  }
1528
1580
  getInitialCommitSha(repoPath, factory) {
1529
- return this.getSharedSimple(this.initialCommitSha, repoPath, factory);
1581
+ return this.readValidated(repoPath, () => this.getSharedSimple(this.initialCommitSha, repoPath, factory));
1530
1582
  }
1531
1583
  /** A rejected factory is never cached (`PromiseMap` evicts on rejection) — a failed read retries next time. */
1532
1584
  getEmptyTreeSha(repoPath, factory) {
@@ -1536,6 +1588,9 @@ var Cache = class Cache {
1536
1588
  return this.getSharedSimple(this.lastFetched, repoPath, factory);
1537
1589
  }
1538
1590
  getRefs(repoPath, factory, cancellation) {
1591
+ return this.readValidated(repoPath, () => this.getRefsCore(repoPath, factory, cancellation));
1592
+ }
1593
+ getRefsCore(repoPath, factory, cancellation) {
1539
1594
  const commonPath = this.getCommonPath(repoPath);
1540
1595
  return this.refs.getOrCreate(commonPath, async (cacheable, signal) => {
1541
1596
  const read = {
@@ -1556,30 +1611,34 @@ var Cache = class Cache {
1556
1611
  }, cancellation);
1557
1612
  }
1558
1613
  getRefTips(repoPath, factory, cancellation) {
1559
- const commonPath = this.getCommonPath(repoPath);
1560
- return this.refTips.getOrCreate(commonPath, (cacheable, signal) => Promise.resolve(factory(commonPath, cacheable, signal)), cancellation);
1614
+ return this.readValidated(repoPath, () => {
1615
+ const commonPath = this.getCommonPath(repoPath);
1616
+ return this.refTips.getOrCreate(commonPath, (cacheable, signal) => Promise.resolve(factory(commonPath, cacheable, signal)), cancellation);
1617
+ });
1561
1618
  }
1562
1619
  async getRemotes(repoPath, factory, cancellation) {
1563
- return this.getSharedOrCreate(this.remotes, repoPath, factory, (data, newRepoPath) => data.map((r) => r.withRepoPath(newRepoPath)), cancellation);
1620
+ return this.readValidated(repoPath, () => this.getSharedOrCreate(this.remotes, repoPath, factory, (data, newRepoPath) => data.map((r) => r.withRepoPath(newRepoPath)), cancellation));
1564
1621
  }
1565
1622
  async getStash(repoPath, cacheKey, factory, options) {
1566
- return this.getSharedOrCreateWithKey(this.stashes, repoPath, cacheKey, factory, (data, newRepoPath) => ({
1623
+ return this.readValidated(repoPath, () => this.getSharedOrCreateWithKey(this.stashes, repoPath, cacheKey, factory, (data, newRepoPath) => ({
1567
1624
  repoPath: newRepoPath,
1568
1625
  stashes: new Map(Array.from(data.stashes.entries(), ([sha, s]) => [sha, s.withRepoPath(newRepoPath)]))
1569
- }), options);
1626
+ }), options));
1570
1627
  }
1571
1628
  async getTags(repoPath, factory, cancellation) {
1572
- return this.getSharedOrCreate(this.tags, repoPath, factory, (data, newRepoPath) => ({
1629
+ return this.readValidated(repoPath, () => this.getSharedOrCreate(this.tags, repoPath, factory, (data, newRepoPath) => ({
1573
1630
  ...data,
1574
1631
  values: data.values.map((t) => t.withRepoPath(newRepoPath))
1575
- }), cancellation);
1632
+ }), cancellation));
1576
1633
  }
1577
1634
  async getWorktrees(repoPath, factory, options, cancellation) {
1578
- if (options?.force) {
1579
- if (cancellation?.aborted) throw new CancellationError();
1580
- this.evictCaches(repoPath, "worktreeList");
1581
- }
1582
- return this.getSharedOrCreate(this.worktrees, repoPath, factory, (data, newRepoPath) => data.map((w) => w.withRepoPath(newRepoPath)), cancellation);
1635
+ return this.readValidated(repoPath, () => {
1636
+ if (options?.force) {
1637
+ if (cancellation?.aborted) throw new CancellationError();
1638
+ this.evictCaches(repoPath, "worktreeList");
1639
+ }
1640
+ return this.getSharedOrCreate(this.worktrees, repoPath, factory, (data, newRepoPath) => data.map((w) => w.withRepoPath(newRepoPath)), cancellation);
1641
+ });
1583
1642
  }
1584
1643
  async getSharedOrCreate(cache, repoPath, factory, mapper, cancellation) {
1585
1644
  const commonPath = this.getCommonPath(repoPath);
@@ -1643,6 +1702,18 @@ __decorate([debug({ onlyExit: true })], Cache.prototype, "unregisterRepoPath", n
1643
1702
  __decorate([debug({ onlyExit: true })], Cache.prototype, "reset", null);
1644
1703
  __decorate([debug({ onlyExit: true })], Cache.prototype, "onRepositoryChanged", null);
1645
1704
  __decorate([debug({ onlyExit: true })], Cache.prototype, "applyRepositoryChanges", null);
1705
+ /** A {@link RepoPromiseCacheMap} whose `getOrCreate` waits for `validate` first (see {@link Cache.setReadValidator}) */
1706
+ var ValidatedRepoPromiseCacheMap = class extends RepoPromiseCacheMap {
1707
+ validate;
1708
+ constructor(validate, options) {
1709
+ super(options);
1710
+ this.validate = validate;
1711
+ }
1712
+ getOrCreate(...args) {
1713
+ const validation = this.validate(args[0]);
1714
+ return validation != null ? validation.then(() => super.getOrCreate(...args)) : super.getOrCreate(...args);
1715
+ }
1716
+ };
1646
1717
  //#endregion
1647
1718
  export { Cache, areUriScopedCachedGitTypes, resetDropsPendingRuns, shouldEvictBlameCacheEntry };
1648
1719