@gitkraken/core-gitlens 0.32.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CHANGELOG.md +42 -1
  2. package/dist/git/cache.d.ts +121 -15
  3. package/dist/git/cache.js +316 -74
  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/models/repositoryIdentities.d.ts +0 -1
  14. package/dist/git/models/repositoryIdentities.js +1 -4
  15. package/dist/git/models/repositoryIdentities.js.map +1 -1
  16. package/dist/git/providers/provider.d.ts +7 -0
  17. package/dist/git/providers/shared/remotes.js +2 -0
  18. package/dist/git/providers/shared/remotes.js.map +1 -1
  19. package/dist/git/remotes/gitlab.js +15 -9
  20. package/dist/git/remotes/gitlab.js.map +1 -1
  21. package/dist/git/service.js +4 -1
  22. package/dist/git/service.js.map +1 -1
  23. package/dist/git/utils/pullRequest.utils.d.ts +72 -1
  24. package/dist/git/utils/pullRequest.utils.js +99 -1
  25. package/dist/git/utils/pullRequest.utils.js.map +1 -1
  26. package/dist/git/utils/repository.utils.d.ts +16 -0
  27. package/dist/git/utils/repository.utils.js +37 -2
  28. package/dist/git/utils/repository.utils.js.map +1 -1
  29. package/dist/git/watching/changeEvent.d.ts +13 -3
  30. package/dist/git/watching/changeEvent.js +19 -4
  31. package/dist/git/watching/changeEvent.js.map +1 -1
  32. package/dist/git/watching/gitDirPoller.d.ts +10 -1
  33. package/dist/git/watching/gitDirPoller.js +9 -3
  34. package/dist/git/watching/gitDirPoller.js.map +1 -1
  35. package/dist/git/watching/unwatchedCacheValidator.d.ts +144 -0
  36. package/dist/git/watching/unwatchedCacheValidator.js +884 -0
  37. package/dist/git/watching/unwatchedCacheValidator.js.map +1 -0
  38. package/dist/git/watching/watchGroup.d.ts +6 -2
  39. package/dist/git/watching/watchGroup.js +35 -24
  40. package/dist/git/watching/watchGroup.js.map +1 -1
  41. package/dist/git/watching/watchService.d.ts +27 -1
  42. package/dist/git/watching/watchService.js +60 -17
  43. package/dist/git/watching/watchService.js.map +1 -1
  44. package/dist/git/watching/watchSession.d.ts +29 -12
  45. package/dist/git/watching/watchSession.js +52 -21
  46. package/dist/git/watching/watchSession.js.map +1 -1
  47. package/dist/git/watching/worktreeSummary.js +7 -7
  48. package/dist/git/watching/worktreeSummary.js.map +1 -1
  49. package/dist/git-cli/cliGitProvider.d.ts +28 -2
  50. package/dist/git-cli/cliGitProvider.js +63 -20
  51. package/dist/git-cli/cliGitProvider.js.map +1 -1
  52. package/dist/git-cli/exec/commandClassifier.d.ts +31 -1
  53. package/dist/git-cli/exec/commandClassifier.js +67 -16
  54. package/dist/git-cli/exec/commandClassifier.js.map +1 -1
  55. package/dist/git-cli/exec/git.d.ts +46 -2
  56. package/dist/git-cli/exec/git.js +87 -9
  57. package/dist/git-cli/exec/git.js.map +1 -1
  58. package/dist/git-cli/exec/gitDirResolver.d.ts +11 -0
  59. package/dist/git-cli/exec/gitDirResolver.js +34 -1
  60. package/dist/git-cli/exec/gitDirResolver.js.map +1 -1
  61. package/dist/git-cli/exec/gitQueue.js +2 -28
  62. package/dist/git-cli/exec/gitQueue.js.map +1 -1
  63. package/dist/git-cli/providers/branches.d.ts +1 -0
  64. package/dist/git-cli/providers/branches.js +21 -10
  65. package/dist/git-cli/providers/branches.js.map +1 -1
  66. package/dist/git-cli/providers/config.d.ts +15 -1
  67. package/dist/git-cli/providers/config.js +67 -22
  68. package/dist/git-cli/providers/config.js.map +1 -1
  69. package/dist/git-cli/providers/pausedOperations.d.ts +1 -0
  70. package/dist/git-cli/providers/pausedOperations.js +4 -0
  71. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  72. package/dist/git-cli/providers/revision.js +2 -0
  73. package/dist/git-cli/providers/revision.js.map +1 -1
  74. package/dist/git-cli/providers/worktrees.js +36 -10
  75. package/dist/git-cli/providers/worktrees.js.map +1 -1
  76. package/dist/git-cli/service.d.ts +25 -1
  77. package/dist/git-cli/service.js +46 -1
  78. package/dist/git-cli/service.js.map +1 -1
  79. package/dist/plus/ai/errors.d.ts +8 -2
  80. package/dist/plus/ai/errors.js +15 -3
  81. package/dist/plus/ai/errors.js.map +1 -1
  82. package/dist/plus/git-github/api/github.d.ts +51 -1
  83. package/dist/plus/git-github/api/github.js +276 -3
  84. package/dist/plus/git-github/api/github.js.map +1 -1
  85. package/dist/plus/git-github/models.d.ts +54 -1
  86. package/dist/plus/git-github/models.js +48 -3
  87. package/dist/plus/git-github/models.js.map +1 -1
  88. package/dist/plus/integrations/fieldPresence.d.ts +6 -1
  89. package/dist/plus/integrations/fieldPresence.js +19 -9
  90. package/dist/plus/integrations/fieldPresence.js.map +1 -1
  91. package/dist/plus/integrations/models/gitHostIntegration.d.ts +26 -1
  92. package/dist/plus/integrations/models/gitHostIntegration.js +51 -0
  93. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  94. package/dist/plus/integrations/models/integration.d.ts +15 -2
  95. package/dist/plus/integrations/models/integration.js +1 -1
  96. package/dist/plus/integrations/models/integration.js.map +1 -1
  97. package/dist/plus/integrations/providers/github.d.ts +16 -1
  98. package/dist/plus/integrations/providers/github.js +53 -1
  99. package/dist/plus/integrations/providers/github.js.map +1 -1
  100. package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +10 -0
  101. package/dist/plus/integrations/providers/gitlab/gitlab.js +62 -15
  102. package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
  103. package/dist/plus/integrations/providers/gitlab/gitlab.utils.d.ts +8 -0
  104. package/dist/plus/integrations/providers/gitlab/gitlab.utils.js +32 -16
  105. package/dist/plus/integrations/providers/gitlab/gitlab.utils.js.map +1 -1
  106. package/dist/plus/integrations/reads/etag.js +11 -0
  107. package/dist/plus/integrations/reads/etag.js.map +1 -1
  108. package/docs/integrations.md +39 -6
  109. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"changeEvent.js","names":[],"sources":["../../../../git/src/watching/changeEvent.ts"],"sourcesContent":["import { filter, some } from '@gitlens/utils/iterable.js';\nimport type { RepositoryChange } from '../models/repository.js';\n\n/** The {@link RepositoryChange} kinds that describe ref movement, which an event can attribute to named refs */\nexport type RefChangeKind = 'heads' | 'remotes' | 'tags' | 'stash';\n\nexport interface WatcherRefChanges {\n\t/** Full ref names whose files changed (`refs/heads/main`), plus per-worktree pseudo-refs (`HEAD`, `ORIG_HEAD`). A name may be a ref directory and then covers every ref beneath it. */\n\treadonly names?: Iterable<string>;\n\t/** Ref kinds that changed without a name (packed-refs rewrite, a ref namespace directory like `refs/remotes`, shallow/replace, an injected change): any ref of that kind may have moved. */\n\treadonly unnamed?: Iterable<RefChangeKind>;\n\t/**\n\t * The local branches (full `refs/heads/` names) whose `branch.<name>` sections are all that every `config` change\n\t * among the changes touched in `.git/config`. Omitted when any of them may have changed anything else.\n\t */\n\treadonly configBranches?: Iterable<string>;\n}\n\nexport function isRefChangeKind(change: RepositoryChange): change is RefChangeKind {\n\treturn change === 'heads' || change === 'remotes' || change === 'tags' || change === 'stash';\n}\n\n/**\n * The kind of ref a full ref name (or ref directory) belongs to. A pseudo-ref (no `refs/` prefix, e.g. `HEAD`,\n * `ORIG_HEAD`) counts as `heads`; a ref outside the watched namespaces (e.g. `refs/notes/x`) has no kind, and neither\n * has a namespace directory itself (`refs/remotes`), so a change reported for one names no ref: any ref of the kind it\n * holds may have moved.\n */\nexport function getRefChangeKind(ref: string): RefChangeKind | undefined {\n\tif (!ref.startsWith('refs/')) return 'heads';\n\tif (ref.startsWith('refs/heads/')) return 'heads';\n\tif (ref.startsWith('refs/remotes/')) return 'remotes';\n\tif (ref.startsWith('refs/tags/')) return 'tags';\n\tif (ref === 'refs/stash') return 'stash';\n\n\treturn undefined;\n}\n\n/**\n * An event describing changes to a repository, produced by the watching pipeline.\n *\n * Changes are coalesced within a debounce window — a single event may represent\n * multiple filesystem changes. Use {@link changed} to test for specific change types,\n * and {@link mayHaveChangedRef} to test whether a specific ref may have moved.\n */\nexport class WatcherRepoChangeEvent {\n\tprotected readonly _changes: Set<RepositoryChange>;\n\tprivate readonly _refs: Set<string>;\n\tprivate readonly _unnamedRefKinds: Set<RefChangeKind>;\n\tprivate readonly _announced: Set<RepositoryChange>;\n\tprivate readonly _configBranches: Set<string> | undefined;\n\n\tconstructor(\n\t\t/** The repository path this event is for */\n\t\tpublic readonly repoPath: string,\n\t\tchanges: RepositoryChange[],\n\t\t/** Which refs changed; when omitted, every ref kind in `changes` is unnamed (any ref of that kind may have moved) */\n\t\trefs?: WatcherRefChanges,\n\t\t/** The kinds of `changes` that come only from core's own announced writes (see {@link announced}) */\n\t\tannounced?: Iterable<RepositoryChange>,\n\t) {\n\t\tthis._changes = new Set(changes);\n\t\tif (refs == null) {\n\t\t\tthis._refs = new Set();\n\t\t\tthis._unnamedRefKinds = new Set(filter(changes, isRefChangeKind));\n\t\t} else {\n\t\t\tthis._refs = new Set(refs.names);\n\t\t\tthis._unnamedRefKinds = new Set(refs.unnamed);\n\t\t}\n\t\tthis._configBranches =\n\t\t\trefs?.configBranches != null && this._changes.has('config') ? new Set(refs.configBranches) : undefined;\n\t\tthis._announced = announced != null ? new Set(filter(announced, c => this._changes.has(c))) : new Set();\n\t}\n\n\tget changes(): ReadonlySet<RepositoryChange> {\n\t\treturn this._changes;\n\t}\n\n\t/**\n\t * The kinds in {@link changes} that come only from core's own writes, which core already announced through\n\t * `hooks.repository.onChanged` after evicting their caches. A host that handled that announcement can skip them;\n\t * a kind the watcher or an injected change also reported is not among them.\n\t */\n\tget announced(): ReadonlySet<RepositoryChange> {\n\t\treturn this._announced;\n\t}\n\n\t/** The kinds in {@link changes} that aren't {@link announced}: what a cache that core already evicted for its write still has to clear */\n\tgetUnannouncedChanges(): RepositoryChange[] {\n\t\treturn this._announced.size ? [...filter(this._changes, c => !this._announced.has(c))] : [...this._changes];\n\t}\n\n\t/** Full ref names (or ref directories, or pseudo-refs) known to have changed. See {@link WatcherRefChanges.names}. */\n\tget refs(): ReadonlySet<string> {\n\t\treturn this._refs;\n\t}\n\n\t/** Ref kinds that changed without a name — any ref of these kinds may have moved */\n\tget unnamedRefKinds(): ReadonlySet<RefChangeKind> {\n\t\treturn this._unnamedRefKinds;\n\t}\n\n\t/**\n\t * The local branches (full `refs/heads/` names) whose `branch.<name>` sections are the only part of `.git/config`\n\t * that changed; `undefined` when `config` didn't change, or any config change may be elsewhere. Independent of\n\t * {@link refs}: an outside edit to a branch's tracking moves no ref.\n\t */\n\tget configBranches(): ReadonlySet<string> | undefined {\n\t\treturn this._configBranches;\n\t}\n\n\t/** Whether `config` changed only in the sections of {@link configBranches} */\n\tget configConfined(): boolean {\n\t\treturn this._configBranches != null;\n\t}\n\n\t/**\n\t * Test whether `config` may have changed in a way that concerns a subscriber following `relevantRefs`.\n\t *\n\t * A branch's config section matters only to a checkout on that branch or one whose upstream or base is that branch,\n\t * and those follow `refs/heads/<name>` (or `HEAD`, which may be on any branch). So a {@link configConfined} change\n\t * concerns `relevantRefs` only when one of them is `HEAD` or one of {@link configBranches}; any other config change\n\t * concerns everyone.\n\t */\n\tmayHaveChangedConfig(relevantRefs: Iterable<string>): boolean {\n\t\tif (!this._changes.has('config')) return false;\n\t\tif (this._configBranches == null) return true;\n\n\t\tfor (const ref of relevantRefs) {\n\t\t\tif (ref === 'HEAD' || this._configBranches.has(ref)) return true;\n\t\t}\n\t\treturn false;\n\t}\n\n\ttoString(changesOnly: boolean = false): string {\n\t\tconst changeList = [...this._changes].join(', ');\n\t\tconst refCount = this._refs.size;\n\t\tif (changesOnly) return refCount ? `changes=${changeList}, refs=${refCount}` : `changes=${changeList}`;\n\n\t\treturn refCount\n\t\t\t? `{ repoPath: ${this.repoPath}, changes: ${changeList}, refs: ${refCount} }`\n\t\t\t: `{ repoPath: ${this.repoPath}, changes: ${changeList} }`;\n\t}\n\n\t/**\n\t * Test whether the given ref may have moved in this event.\n\t *\n\t * @param ref - A full ref name (`refs/heads/main`) or a pseudo-ref (`HEAD`).\n\t * @returns `false` when the ref's kind didn't change (or the ref is outside the watched kinds); `true` when its kind\n\t * changed without a name, or when the ref itself or a ref directory above it changed. `HEAD` is usually a symref\n\t * to the checked-out branch, so it may have moved whenever any `heads` ref did.\n\t */\n\tmayHaveChangedRef(ref: string): boolean {\n\t\tconst kind = getRefChangeKind(ref);\n\t\tif (kind == null || !this._changes.has(kind)) return false;\n\t\tif (this._unnamedRefKinds.has(kind) || ref === 'HEAD') return true;\n\n\t\treturn findCoveringRefName(this._refs, ref) != null;\n\t}\n\n\t/**\n\t * Test whether any of the specified change types are present in the event.\n\t *\n\t * @param affected - Change types to test for.\n\t * @returns `true` if any of the specified changes are present.\n\t */\n\tchanged(...affected: RepositoryChange[]): boolean {\n\t\treturn some(this._changes, c => affected.includes(c));\n\t}\n\n\t/**\n\t * Test whether the event contains ONLY the specified change types.\n\t *\n\t * `pausedOp` is treated as a union of `cherryPick`, `merge`, `rebase`,\n\t * and `revert` for convenience.\n\t *\n\t * @param affected - Change types to test for.\n\t * @returns `true` if the event contains only the specified changes.\n\t */\n\tchangedExclusive(...affected: RepositoryChange[]): boolean {\n\t\tlet changes = this._changes;\n\n\t\t// When checking for specific paused operation types, also accept the union type\n\t\tif (\n\t\t\taffected.includes('cherryPick') ||\n\t\t\taffected.includes('merge') ||\n\t\t\taffected.includes('rebase') ||\n\t\t\taffected.includes('revert')\n\t\t) {\n\t\t\tif (!affected.includes('pausedOp')) {\n\t\t\t\taffected = [...affected, 'pausedOp'];\n\t\t\t}\n\t\t} else if (affected.includes('pausedOp')) {\n\t\t\t// When checking for the union type exclusively, ignore specific subtypes\n\t\t\tchanges = new Set(changes);\n\t\t\tchanges.delete('cherryPick');\n\t\t\tchanges.delete('merge');\n\t\t\tchanges.delete('rebase');\n\t\t\tchanges.delete('revert');\n\t\t}\n\n\t\tconst intersection = [...filter(changes, c => affected.includes(c))];\n\t\treturn intersection.length === changes.size;\n\t}\n\n\t/**\n\t * Coalesce: return a new event with all changes and refs from both this and the given set. When `refs` is omitted,\n\t * every ref kind in `changes` counts as unnamed. A kind in `changes` is no longer {@link announced}. `config` stays\n\t * {@link configConfined}, to the branches of both, only when each side that changed it was confined.\n\t */\n\twith(changes: RepositoryChange[], refs?: WatcherRefChanges): WatcherRepoChangeEvent {\n\t\tconst names = [...this._refs];\n\t\tconst unnamed = [...this._unnamedRefKinds];\n\t\tif (refs == null) {\n\t\t\tunnamed.push(...filter(changes, isRefChangeKind));\n\t\t} else {\n\t\t\tif (refs.names != null) {\n\t\t\t\tnames.push(...refs.names);\n\t\t\t}\n\t\t\tif (refs.unnamed != null) {\n\t\t\t\tunnamed.push(...refs.unnamed);\n\t\t\t}\n\t\t}\n\n\t\tlet configBranches: Set<string> | undefined;\n\t\tconst own = this._changes.has('config') ? this._configBranches : new Set<string>();\n\t\tconst other = changes.includes('config') ? refs?.configBranches : [];\n\t\tif (own != null && other != null) {\n\t\t\tconfigBranches = new Set([...own, ...other]);\n\t\t}\n\n\t\treturn new WatcherRepoChangeEvent(\n\t\t\tthis.repoPath,\n\t\t\t[...this._changes, ...changes],\n\t\t\t{ names: names, unnamed: unnamed, configBranches: configBranches },\n\t\t\tfilter(this._announced, c => !changes.includes(c)),\n\t\t);\n\t}\n}\n\n/**\n * Returns the name in `names` that covers `ref` — `ref` itself, or a ref directory above it (compared on `/`\n * boundaries, so `refs/heads/fe` doesn't cover `refs/heads/feature`) — or `undefined` if none does.\n */\nexport function findCoveringRefName(names: ReadonlySet<string>, ref: string): string | undefined {\n\tif (names.size === 0) return undefined;\n\tif (names.has(ref)) return ref;\n\n\tlet index = ref.lastIndexOf('/');\n\twhile (index > 0) {\n\t\tconst dir = ref.substring(0, index);\n\t\tif (names.has(dir)) return dir;\n\n\t\tindex = ref.lastIndexOf('/', index - 1);\n\t}\n\treturn undefined;\n}\n\n/**\n * An event describing working tree file changes, produced by the working tree pipeline.\n *\n * Paths have already been filtered through the gitignore filter and noise filter.\n */\nexport interface WorkingTreeChangeEvent {\n\treadonly repoPath: string;\n\t/**\n\t * Absolute paths of changed files or directories (post-gitignore filtering). A directory stands for everything\n\t * beneath it. Partial when {@link incomplete}.\n\t */\n\treadonly paths: ReadonlySet<string>;\n\t/**\n\t * `true` when more paths changed than the accumulator retains, so {@link paths} is a partial set and a\n\t * miss does NOT mean the file is unchanged. Consumers testing membership must treat this as a match.\n\t */\n\treadonly incomplete: boolean;\n}\n"],"mappings":";;AAkBA,SAAgB,gBAAgB,QAAmD;CAClF,OAAO,WAAW,WAAW,WAAW,aAAa,WAAW,UAAU,WAAW;AACtF;;;;;;;AAQA,SAAgB,iBAAiB,KAAwC;CACxE,IAAI,CAAC,IAAI,WAAW,OAAO,GAAG,OAAO;CACrC,IAAI,IAAI,WAAW,aAAa,GAAG,OAAO;CAC1C,IAAI,IAAI,WAAW,eAAe,GAAG,OAAO;CAC5C,IAAI,IAAI,WAAW,YAAY,GAAG,OAAO;CACzC,IAAI,QAAQ,cAAc,OAAO;AAGlC;;;;;;;;AASA,IAAa,yBAAb,MAAa,uBAAuB;CASlB;CARjB;CACA;CACA;CACA;CACA;CAEA,YAEC,UACA,SAEA,MAEA,WACC;EANe,KAAA,WAAA;EAOhB,KAAK,WAAW,IAAI,IAAI,OAAO;EAC/B,IAAI,QAAQ,MAAM;GACjB,KAAK,wBAAQ,IAAI,IAAI;GACrB,KAAK,mBAAmB,IAAI,IAAI,OAAO,SAAS,eAAe,CAAC;EACjE,OAAO;GACN,KAAK,QAAQ,IAAI,IAAI,KAAK,KAAK;GAC/B,KAAK,mBAAmB,IAAI,IAAI,KAAK,OAAO;EAC7C;EACA,KAAK,kBACJ,MAAM,kBAAkB,QAAQ,KAAK,SAAS,IAAI,QAAQ,IAAI,I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IAAI,MAAM,iBAAiB,CAAC;EACnE,IAAI,OAAO,QAAQ,SAAS,MAC3B,iCAAiB,IAAI,IAAI,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC;EAG5C,OAAO,IAAI,uBACV,KAAK,UACL,CAAC,GAAG,KAAK,UAAU,GAAG,OAAO,GAC7B;GAAS;GAAgB;GAAyB;EAAe,GACjE,OAAO,KAAK,aAAY,MAAK,CAAC,QAAQ,SAAS,CAAC,CAAC,CAClD;CACD;AACD;;;;;AAMA,SAAgB,oBAAoB,OAA4B,KAAiC;CAChG,IAAI,MAAM,SAAS,GAAG,OAAO,KAAA;CAC7B,IAAI,MAAM,IAAI,GAAG,GAAG,OAAO;CAE3B,IAAI,QAAQ,IAAI,YAAY,GAAG;CAC/B,OAAO,QAAQ,GAAG;EACjB,MAAM,MAAM,IAAI,UAAU,GAAG,KAAK;EAClC,IAAI,MAAM,IAAI,GAAG,GAAG,OAAO;EAE3B,QAAQ,IAAI,YAAY,KAAK,QAAQ,CAAC;CACvC;AAED"}
1
+ {"version":3,"file":"changeEvent.js","names":[],"sources":["../../../../git/src/watching/changeEvent.ts"],"sourcesContent":["import { filter, some } from '@gitlens/utils/iterable.js';\nimport type { RepositoryChange } from '../models/repository.js';\n\n/** The {@link RepositoryChange} kinds that describe ref movement, which an event can attribute to named refs */\nexport type RefChangeKind = 'heads' | 'remotes' | 'tags' | 'stash';\n\nexport interface WatcherRefChanges {\n\t/** Full ref names whose files changed (`refs/heads/main`), plus per-worktree pseudo-refs (`HEAD`, `ORIG_HEAD`). A name may be a ref directory and then covers every ref beneath it. */\n\treadonly names?: Iterable<string>;\n\t/** Ref kinds that changed without a name (packed-refs rewrite, a ref namespace directory like `refs/remotes`, shallow/replace, an injected change): any ref of that kind may have moved. */\n\treadonly unnamed?: Iterable<RefChangeKind>;\n\t/**\n\t * The local branches (full `refs/heads/` names) whose `branch.<name>` sections are all that every `config` change\n\t * among the changes touched in `.git/config`. Omitted when any of them may have changed anything else.\n\t */\n\treadonly configBranches?: Iterable<string>;\n}\n\nexport function isRefChangeKind(change: RepositoryChange): change is RefChangeKind {\n\treturn change === 'heads' || change === 'remotes' || change === 'tags' || change === 'stash';\n}\n\n/**\n * The kind of ref a full ref name (or ref directory) belongs to. A pseudo-ref (no `refs/` prefix, e.g. `HEAD`,\n * `ORIG_HEAD`) counts as `heads`; a ref outside the watched namespaces (e.g. `refs/notes/x`) has no kind, and neither\n * has a namespace directory itself (`refs/remotes`), so a change reported for one names no ref: any ref of the kind it\n * holds may have moved.\n */\nexport function getRefChangeKind(ref: string): RefChangeKind | undefined {\n\tif (!ref.startsWith('refs/')) return 'heads';\n\tif (ref.startsWith('refs/heads/')) return 'heads';\n\tif (ref.startsWith('refs/remotes/')) return 'remotes';\n\tif (ref.startsWith('refs/tags/')) return 'tags';\n\tif (ref === 'refs/stash') return 'stash';\n\n\treturn undefined;\n}\n\n/**\n * An event describing changes to a repository, produced by the watching pipeline.\n *\n * Changes are coalesced within a debounce window — a single event may represent\n * multiple filesystem changes. Use {@link changed} to test for specific change types,\n * and {@link mayHaveChangedRef} to test whether a specific ref may have moved.\n */\nexport class WatcherRepoChangeEvent {\n\tprotected readonly _changes: Set<RepositoryChange>;\n\tprivate readonly _refs: Set<string>;\n\tprivate readonly _unnamedRefKinds: Set<RefChangeKind>;\n\tprivate readonly _announced: Set<RepositoryChange>;\n\tprivate readonly _configBranches: Set<string> | undefined;\n\tprivate readonly _movedWorktrees: Set<string> | undefined;\n\n\tconstructor(\n\t\t/** The repository path this event is for */\n\t\tpublic readonly repoPath: string,\n\t\tchanges: RepositoryChange[],\n\t\t/** Which refs changed; when omitted, every ref kind in `changes` is unnamed (any ref of that kind may have moved) */\n\t\trefs?: WatcherRefChanges,\n\t\t/** The kinds of `changes` that come only from core's own announced writes (see {@link announced}) */\n\t\tannounced?: Iterable<RepositoryChange>,\n\t\t/** For a `worktreeHead` among `changes`, the worktrees moved outside core's writes (see {@link movedWorktrees}) */\n\t\tmovedWorktrees?: Iterable<string>,\n\t) {\n\t\tthis._changes = new Set(changes);\n\t\tif (refs == null) {\n\t\t\tthis._refs = new Set();\n\t\t\tthis._unnamedRefKinds = new Set(filter(changes, isRefChangeKind));\n\t\t} else {\n\t\t\tthis._refs = new Set(refs.names);\n\t\t\tthis._unnamedRefKinds = new Set(refs.unnamed);\n\t\t}\n\t\tthis._configBranches =\n\t\t\trefs?.configBranches != null && this._changes.has('config') ? new Set(refs.configBranches) : undefined;\n\t\tthis._announced = announced != null ? new Set(filter(announced, c => this._changes.has(c))) : new Set();\n\t\tthis._movedWorktrees =\n\t\t\tmovedWorktrees != null && this._changes.has('worktreeHead') ? new Set(movedWorktrees) : undefined;\n\t}\n\n\tget changes(): ReadonlySet<RepositoryChange> {\n\t\treturn this._changes;\n\t}\n\n\t/**\n\t * The kinds in {@link changes} that come only from core's own writes, which core already announced through\n\t * `hooks.repository.onChanged` after evicting their caches. A host that handled that announcement can skip them;\n\t * a kind the watcher or an injected change also reported is not among them.\n\t */\n\tget announced(): ReadonlySet<RepositoryChange> {\n\t\treturn this._announced;\n\t}\n\n\t/** The kinds in {@link changes} that aren't {@link announced}: what a cache that core already evicted for its write still has to clear */\n\tgetUnannouncedChanges(): RepositoryChange[] {\n\t\treturn this._announced.size ? [...filter(this._changes, c => !this._announced.has(c))] : [...this._changes];\n\t}\n\n\t/** Full ref names (or ref directories, or pseudo-refs) known to have changed. See {@link WatcherRefChanges.names}. */\n\tget refs(): ReadonlySet<string> {\n\t\treturn this._refs;\n\t}\n\n\t/** Ref kinds that changed without a name — any ref of these kinds may have moved */\n\tget unnamedRefKinds(): ReadonlySet<RefChangeKind> {\n\t\treturn this._unnamedRefKinds;\n\t}\n\n\t/**\n\t * The local branches (full `refs/heads/` names) whose `branch.<name>` sections are the only part of `.git/config`\n\t * that changed; `undefined` when `config` didn't change, or any config change may be elsewhere. Independent of\n\t * {@link refs}: an outside edit to a branch's tracking moves no ref.\n\t */\n\tget configBranches(): ReadonlySet<string> | undefined {\n\t\treturn this._configBranches;\n\t}\n\n\t/**\n\t * The admin ids (the `<id>` of `.git/worktrees/<id>`) of the linked worktrees whose HEAD moved other than by core's\n\t * announced writes, which are all that an unannounced `worktreeHead` reports; `undefined` when `worktreeHead` didn't\n\t * change, or any linked worktree's HEAD may have moved.\n\t */\n\tget movedWorktrees(): ReadonlySet<string> | undefined {\n\t\treturn this._movedWorktrees;\n\t}\n\n\t/** Whether `config` changed only in the sections of {@link configBranches} */\n\tget configConfined(): boolean {\n\t\treturn this._configBranches != null;\n\t}\n\n\t/**\n\t * Test whether `config` may have changed in a way that concerns a subscriber following `relevantRefs`.\n\t *\n\t * A branch's config section matters only to a checkout on that branch or one whose upstream or base is that branch,\n\t * and those follow `refs/heads/<name>` (or `HEAD`, which may be on any branch). So a {@link configConfined} change\n\t * concerns `relevantRefs` only when one of them is `HEAD` or one of {@link configBranches}; any other config change\n\t * concerns everyone.\n\t */\n\tmayHaveChangedConfig(relevantRefs: Iterable<string>): boolean {\n\t\tif (!this._changes.has('config')) return false;\n\t\tif (this._configBranches == null) return true;\n\n\t\tfor (const ref of relevantRefs) {\n\t\t\tif (ref === 'HEAD' || this._configBranches.has(ref)) return true;\n\t\t}\n\t\treturn false;\n\t}\n\n\ttoString(changesOnly: boolean = false): string {\n\t\tconst changeList = [...this._changes].join(', ');\n\t\tconst refCount = this._refs.size;\n\t\tif (changesOnly) return refCount ? `changes=${changeList}, refs=${refCount}` : `changes=${changeList}`;\n\n\t\treturn refCount\n\t\t\t? `{ repoPath: ${this.repoPath}, changes: ${changeList}, refs: ${refCount} }`\n\t\t\t: `{ repoPath: ${this.repoPath}, changes: ${changeList} }`;\n\t}\n\n\t/**\n\t * Test whether the given ref may have moved in this event.\n\t *\n\t * @param ref - A full ref name (`refs/heads/main`) or a pseudo-ref (`HEAD`).\n\t * @returns `false` when the ref's kind didn't change (or the ref is outside the watched kinds); `true` when its kind\n\t * changed without a name, or when the ref itself or a ref directory above it changed. `HEAD` is usually a symref\n\t * to the checked-out branch, so it may have moved whenever any `heads` ref did.\n\t */\n\tmayHaveChangedRef(ref: string): boolean {\n\t\tconst kind = getRefChangeKind(ref);\n\t\tif (kind == null || !this._changes.has(kind)) return false;\n\t\tif (this._unnamedRefKinds.has(kind) || ref === 'HEAD') return true;\n\n\t\treturn findCoveringRefName(this._refs, ref) != null;\n\t}\n\n\t/**\n\t * Test whether any of the specified change types are present in the event.\n\t *\n\t * @param affected - Change types to test for.\n\t * @returns `true` if any of the specified changes are present.\n\t */\n\tchanged(...affected: RepositoryChange[]): boolean {\n\t\treturn some(this._changes, c => affected.includes(c));\n\t}\n\n\t/**\n\t * Test whether the event contains ONLY the specified change types.\n\t *\n\t * `pausedOp` is treated as a union of `cherryPick`, `merge`, `rebase`,\n\t * and `revert` for convenience.\n\t *\n\t * @param affected - Change types to test for.\n\t * @returns `true` if the event contains only the specified changes.\n\t */\n\tchangedExclusive(...affected: RepositoryChange[]): boolean {\n\t\tlet changes = this._changes;\n\n\t\t// When checking for specific paused operation types, also accept the union type\n\t\tif (\n\t\t\taffected.includes('cherryPick') ||\n\t\t\taffected.includes('merge') ||\n\t\t\taffected.includes('rebase') ||\n\t\t\taffected.includes('revert')\n\t\t) {\n\t\t\tif (!affected.includes('pausedOp')) {\n\t\t\t\taffected = [...affected, 'pausedOp'];\n\t\t\t}\n\t\t} else if (affected.includes('pausedOp')) {\n\t\t\t// When checking for the union type exclusively, ignore specific subtypes\n\t\t\tchanges = new Set(changes);\n\t\t\tchanges.delete('cherryPick');\n\t\t\tchanges.delete('merge');\n\t\t\tchanges.delete('rebase');\n\t\t\tchanges.delete('revert');\n\t\t}\n\n\t\tconst intersection = [...filter(changes, c => affected.includes(c))];\n\t\treturn intersection.length === changes.size;\n\t}\n\n\t/**\n\t * Coalesce: return a new event with all changes and refs from both this and the given set. When `refs` is omitted,\n\t * every ref kind in `changes` counts as unnamed. A kind in `changes` is no longer {@link announced}. `config` stays\n\t * {@link configConfined}, to the branches of both, only when each side that changed it was confined, and\n\t * `worktreeHead` keeps {@link movedWorktrees}, those of both, only when each side that changed it named them.\n\t */\n\twith(\n\t\tchanges: RepositoryChange[],\n\t\trefs?: WatcherRefChanges,\n\t\tmovedWorktrees?: Iterable<string>,\n\t): WatcherRepoChangeEvent {\n\t\tconst names = [...this._refs];\n\t\tconst unnamed = [...this._unnamedRefKinds];\n\t\tif (refs == null) {\n\t\t\tunnamed.push(...filter(changes, isRefChangeKind));\n\t\t} else {\n\t\t\tif (refs.names != null) {\n\t\t\t\tnames.push(...refs.names);\n\t\t\t}\n\t\t\tif (refs.unnamed != null) {\n\t\t\t\tunnamed.push(...refs.unnamed);\n\t\t\t}\n\t\t}\n\n\t\tlet configBranches: Set<string> | undefined;\n\t\tconst own = this._changes.has('config') ? this._configBranches : new Set<string>();\n\t\tconst other = changes.includes('config') ? refs?.configBranches : [];\n\t\tif (own != null && other != null) {\n\t\t\tconfigBranches = new Set([...own, ...other]);\n\t\t}\n\n\t\tlet moved: Set<string> | undefined;\n\t\tconst ownMoved = this._changes.has('worktreeHead') ? this._movedWorktrees : new Set<string>();\n\t\tconst otherMoved = changes.includes('worktreeHead') ? movedWorktrees : [];\n\t\tif (ownMoved != null && otherMoved != null) {\n\t\t\tmoved = new Set([...ownMoved, ...otherMoved]);\n\t\t}\n\n\t\treturn new WatcherRepoChangeEvent(\n\t\t\tthis.repoPath,\n\t\t\t[...this._changes, ...changes],\n\t\t\t{ names: names, unnamed: unnamed, configBranches: configBranches },\n\t\t\tfilter(this._announced, c => !changes.includes(c)),\n\t\t\tmoved,\n\t\t);\n\t}\n}\n\n/**\n * Returns the name in `names` that covers `ref` — `ref` itself, or a ref directory above it (compared on `/`\n * boundaries, so `refs/heads/fe` doesn't cover `refs/heads/feature`) — or `undefined` if none does.\n */\nexport function findCoveringRefName(names: ReadonlySet<string>, ref: string): string | undefined {\n\tif (names.size === 0) return undefined;\n\tif (names.has(ref)) return ref;\n\n\tlet index = ref.lastIndexOf('/');\n\twhile (index > 0) {\n\t\tconst dir = ref.substring(0, index);\n\t\tif (names.has(dir)) return dir;\n\n\t\tindex = ref.lastIndexOf('/', index - 1);\n\t}\n\treturn undefined;\n}\n\n/**\n * An event describing working tree file changes, produced by the working tree pipeline.\n *\n * Paths have already been filtered through the gitignore filter and noise filter.\n */\nexport interface WorkingTreeChangeEvent {\n\treadonly repoPath: string;\n\t/**\n\t * Absolute paths of changed files or directories (post-gitignore filtering). A directory stands for everything\n\t * beneath it. Partial when {@link incomplete}.\n\t */\n\treadonly paths: ReadonlySet<string>;\n\t/**\n\t * `true` when more paths changed than the accumulator retains, so {@link paths} is a partial set and a\n\t * miss does NOT mean the file is unchanged. Consumers testing membership must treat this as a match.\n\t */\n\treadonly incomplete: boolean;\n}\n"],"mappings":";;AAkBA,SAAgB,gBAAgB,QAAmD;CAClF,OAAO,WAAW,WAAW,WAAW,aAAa,WAAW,UAAU,WAAW;AACtF;;;;;;;AAQA,SAAgB,iBAAiB,KAAwC;CACxE,IAAI,CAAC,IAAI,WAAW,OAAO,GAAG,OAAO;CACrC,IAAI,IAAI,WAAW,aAAa,GAAG,OAAO;CAC1C,IAAI,IAAI,WAAW,eAAe,GAAG,OAAO;CAC5C,IAAI,IAAI,WAAW,YAAY,GAAG,OAAO;CACzC,IAAI,QAAQ,cAAc,OAAO;AAGlC;;;;;;;;AASA,IAAa,yBAAb,MAAa,uBAAuB;CAUlB;CATjB;CACA;CACA;CACA;CACA;CACA;CAEA,YAEC,UACA,SAEA,MAEA,WAEA,gBACC;EARe,KAAA,WAAA;EAShB,KAAK,WAAW,IAAI,IAAI,OAAO;EAC/B,IAAI,QAAQ,MAAM;GACjB,KAAK,wBAAQ,IAAI,IAAI;GACrB,KAAK,mBAAmB,IAAI,IAAI,OAAO,SAAS,eAAe,CAAC;EACjE,OAAO;GACN,KAAK,QAAQ,IAAI,IAAI,KAAK,KAAK;GAC/B,KAAK,mBAAmB,IAAI,IAAI,KAAK,OAAO;EAC7C;EACA,KAAK,kBACJ,MAAM,kBAAkB,Q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I,KAAK,WAAW,MACnB,QAAQ,KAAK,GAAG,KAAK,OAAO;EAE9B;EAEA,IAAI;EACJ,MAAM,MAAM,KAAK,SAAS,IAAI,QAAQ,IAAI,KAAK,kCAAkB,IAAI,IAAY;EACjF,MAAM,QAAQ,QAAQ,SAAS,QAAQ,IAAI,MAAM,iBAAiB,CAAC;EACnE,IAAI,OAAO,QAAQ,SAAS,MAC3B,iCAAiB,IAAI,IAAI,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC;EAG5C,IAAI;EACJ,MAAM,WAAW,KAAK,SAAS,IAAI,cAAc,IAAI,KAAK,kCAAkB,IAAI,IAAY;EAC5F,MAAM,aAAa,QAAQ,SAAS,cAAc,IAAI,iBAAiB,CAAC;EACxE,IAAI,YAAY,QAAQ,cAAc,MACrC,wBAAQ,IAAI,IAAI,CAAC,GAAG,UAAU,GAAG,UAAU,CAAC;EAG7C,OAAO,IAAI,uBACV,KAAK,UACL,CAAC,GAAG,KAAK,UAAU,GAAG,OAAO,GAC7B;GAAS;GAAgB;GAAyB;EAAe,GACjE,OAAO,KAAK,aAAY,MAAK,CAAC,QAAQ,SAAS,CAAC,CAAC,GACjD,KACD;CACD;AACD;;;;;AAMA,SAAgB,oBAAoB,OAA4B,KAAiC;CAChG,IAAI,MAAM,SAAS,GAAG,OAAO,KAAA;CAC7B,IAAI,MAAM,IAAI,GAAG,GAAG,OAAO;CAE3B,IAAI,QAAQ,IAAI,YAAY,GAAG;CAC/B,OAAO,QAAQ,GAAG;EACjB,MAAM,MAAM,IAAI,UAAU,GAAG,KAAK;EAClC,IAAI,MAAM,IAAI,GAAG,GAAG,OAAO;EAE3B,QAAQ,IAAI,YAAY,KAAK,QAAQ,CAAC;CACvC;AAED"}
@@ -91,12 +91,21 @@ export declare class GitDirProbeTarget implements PollTarget {
91
91
  /** For each path a probe may be emitted as, the paths of the probes emitted as it */
92
92
  private readonly probesByEmittedPath;
93
93
  private readonly onMoved;
94
+ private readonly options?;
94
95
  private readonly signatures;
95
96
  /** For each poll whose stats are in flight, the paths {@link forget} cleared meanwhile, which it must not record */
96
97
  private readonly forgottenDuringPolls;
98
+ private racyReadings;
97
99
  constructor(basePath: string, stats: Pick<GitDirPoller, 'stat' | 'invalidate'>, getProbes: () => Iterable<GitDirProbe>,
98
100
  /** For each path a probe may be emitted as, the paths of the probes emitted as it */
99
- probesByEmittedPath: ReadonlyMap<string, readonly string[]>, onMoved: (event: FileWatchEvent, probe: GitDirProbe) => void);
101
+ probesByEmittedPath: ReadonlyMap<string, readonly string[]>, onMoved: (event: FileWatchEvent, probe: GitDirProbe) => void, options?: {
102
+ /**
103
+ * Whether a reading can't be trusted to show the next change, as on a file system whose timestamps tick
104
+ * too coarsely to tell a write just after the stat from the one before it. Such a reading is recorded as
105
+ * matching no other, so the probe counts as moved at its next read. Given the absolute path it was read from
106
+ */
107
+ readonly isRacy?: (stat: NonNullable<GitDirStat>, path: string) => boolean;
108
+ } | undefined);
100
109
  poll(): Promise<void>;
101
110
  /**
102
111
  * The watcher reported `path` itself, so the next poll records the probes it touched (the path, a ref's lock file
@@ -201,15 +201,18 @@ var GitDirProbeTarget = class {
201
201
  getProbes;
202
202
  probesByEmittedPath;
203
203
  onMoved;
204
+ options;
204
205
  signatures = /* @__PURE__ */ new Map();
205
206
  /** For each poll whose stats are in flight, the paths {@link forget} cleared meanwhile, which it must not record */
206
207
  forgottenDuringPolls = /* @__PURE__ */ new Set();
207
- constructor(basePath, stats, getProbes, probesByEmittedPath, onMoved) {
208
+ racyReadings = 0;
209
+ constructor(basePath, stats, getProbes, probesByEmittedPath, onMoved, options) {
208
210
  this.basePath = basePath;
209
211
  this.stats = stats;
210
212
  this.getProbes = getProbes;
211
213
  this.probesByEmittedPath = probesByEmittedPath;
212
214
  this.onMoved = onMoved;
215
+ this.options = options;
213
216
  }
214
217
  async poll() {
215
218
  const probes = [...this.getProbes()];
@@ -253,8 +256,11 @@ var GitDirProbeTarget = class {
253
256
  }
254
257
  async read(path) {
255
258
  try {
256
- const stat = await this.stats.stat(joinPaths(this.basePath, path));
257
- return stat == null ? "missing" : `${stat.mtime}:${stat.size}`;
259
+ const absolutePath = joinPaths(this.basePath, path);
260
+ const stat = await this.stats.stat(absolutePath);
261
+ if (stat == null) return "missing";
262
+ const signature = `${stat.mtime}:${stat.size}`;
263
+ return this.options?.isRacy?.(stat, absolutePath) ? `${signature}:racy:${++this.racyReadings}` : signature;
258
264
  } catch {
259
265
  return;
260
266
  }
@@ -1 +1 @@
1
- {"version":3,"file":"gitDirPoller.js","names":[],"sources":["../../../../git/src/watching/gitDirPoller.ts"],"sourcesContent":["import type { UnifiedDisposable } from '@gitlens/utils/disposable.js';\nimport { isDescendant, joinPaths, relative } from '@gitlens/utils/path.js';\nimport type { FileWatchEvent } from './provider.js';\nimport type { WatchPollingOptions } from './watchService.js';\n\nconst defaultPollIntervalMs = 60_000;\nconst defaultPollActiveCheckMs = 5_000;\nconst defaultPollConcurrency = 4;\n\ntype GitDirStat = Awaited<ReturnType<WatchPollingOptions['stat']>>;\n\n/** Something the {@link GitDirPoller} reads once per pass */\nexport interface PollTarget {\n\tpoll(): Promise<void>;\n}\n\n/** A file or directory a poll stats, relative to the directory it watches in place of a watcher */\nexport interface GitDirProbe {\n\t/** `/`-separated, relative to the target's base path */\n\treadonly path: string;\n\t/** The relative paths a move is reported as, in place of `path` */\n\treadonly emitAs?: readonly string[];\n}\n\n/**\n * Runs passes over the poll targets of every watcher that can't be trusted, reading at most 4 targets at once across\n * passes and first readings. A target is read once soon after it is added, so its baseline doesn't wait for the next\n * pass; targets added together are read together.\n *\n * With the default gate (no `isActive`), one timer runs a pass every `intervalMs`, stopped by {@link suspend} and\n * restarted by {@link resume}, which runs a pass at once. With a host's `isActive`, whose changes core can't see, one\n * timer looks at it every `activeCheckMs`: a pass is due once `intervalMs` has gone by since the last one, or at the\n * first look after the gate opens (or after {@link nudge}), so a window that comes back between passes doesn't wait out\n * the rest of one.\n */\nexport class GitDirPoller implements UnifiedDisposable {\n\tprivate readonly targets = new Set<PollTarget>();\n\t/** Targets added since the last pass and not yet read */\n\tprivate readonly unread = new Set<PollTarget>();\n\t/** Each target's last read asked for; a target is never read twice at once, so the next waits for it */\n\tprivate readonly reading = new Map<PollTarget, Promise<void>>();\n\t/** Reads waiting for one of the {@link defaultPollConcurrency} slots, which a finished read hands over */\n\tprivate readonly waiting: (() => void)[] = [];\n\t/**\n\t * The stats of the batches (a pass, or first readings) in flight, shared by every target that probes the same path,\n\t * as the main checkout's root and its common dir do\n\t */\n\tprivate readonly stats = new Map<string, Promise<GitDirStat>>();\n\tprivate readonly intervalMs: number;\n\tprivate readonly activeCheckMs: number;\n\tprivate timer: ReturnType<typeof setTimeout> | undefined;\n\tprivate running: Promise<void> | undefined;\n\tprivate batches = 0;\n\tprivate slotsInUse = 0;\n\t/** The next look runs a pass whatever the interval says */\n\tprivate due = true;\n\tprivate lastPassAt = 0;\n\tprivate suspended = false;\n\tprivate disposed = false;\n\n\tconstructor(readonly options: WatchPollingOptions) {\n\t\tthis.intervalMs = options.intervalMs ?? defaultPollIntervalMs;\n\t\tthis.activeCheckMs = options.activeCheckMs ?? defaultPollActiveCheckMs;\n\t}\n\n\t[Symbol.dispose](): void {\n\t\tthis.dispose();\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.targets.clear();\n\t\tthis.unread.clear();\n\t\tthis.stats.clear();\n\t\tthis.stopTimer();\n\t}\n\n\tget size(): number {\n\t\treturn this.targets.size;\n\t}\n\n\tadd(target: PollTarget): void {\n\t\tif (this.disposed || this.targets.has(target)) return;\n\n\t\tthis.targets.add(target);\n\t\tthis.unread.add(target);\n\t\tif (this.unread.size === 1) {\n\t\t\tqueueMicrotask(() => this.readUnread());\n\t\t}\n\t\tthis.startTimer();\n\t}\n\n\tdelete(target: PollTarget): void {\n\t\tthis.unread.delete(target);\n\t\tif (!this.targets.delete(target) || this.targets.size !== 0) return;\n\n\t\tthis.stopTimer();\n\t}\n\n\t/** Makes the next look a pass, and looks now */\n\tnudge(): void {\n\t\tthis.due = true;\n\t\tvoid this.tick();\n\t}\n\n\t/** Under the default gate, stops passes (and the timer) until {@link resume}; a host's `isActive` ignores it */\n\tsuspend(): void {\n\t\tthis.suspended = true;\n\t\tif (this.options.isActive == null) {\n\t\t\tthis.stopTimer();\n\t\t}\n\t}\n\n\t/** Lifts {@link suspend}, and runs a pass now, so what moved meanwhile is polled rather than at the next look */\n\tresume(): void {\n\t\tthis.suspended = false;\n\t\tthis.nudge();\n\t}\n\n\t/** One look at the gate: runs a pass when one is due, the gate is open and none is in flight */\n\ttick(): Promise<void> {\n\t\tif (this.disposed || this.targets.size === 0) return Promise.resolve();\n\n\t\tif (!(this.options.isActive?.() ?? !this.suspended)) {\n\t\t\tthis.due = true;\n\t\t\treturn Promise.resolve();\n\t\t}\n\n\t\t// A pass asked for while one is in flight runs once it ends; an elapsed interval just waits for the next look\n\t\tif (this.running != null) return this.running;\n\n\t\tconst now = performance.now();\n\t\tif (!this.due && now - this.lastPassAt < this.intervalMs) return Promise.resolve();\n\n\t\t// Under the default gate the timer counts the interval from this pass, whatever started it\n\t\tif (this.options.isActive == null) {\n\t\t\tthis.stopTimer();\n\t\t\tthis.startTimer();\n\t\t}\n\t\tthis.due = false;\n\t\tthis.lastPassAt = now;\n\t\tthis.running = this.pass().finally(() => {\n\t\t\tthis.running = undefined;\n\t\t\tif (this.due) {\n\t\t\t\tvoid this.tick();\n\t\t\t}\n\t\t});\n\t\treturn this.running;\n\t}\n\n\t/** Stats `path` once for every target that probes it in the batches in flight */\n\tstat(path: string): Promise<GitDirStat> {\n\t\tif (this.batches === 0) return this.options.stat(path);\n\n\t\tlet stat = this.stats.get(path);\n\t\tif (stat == null) {\n\t\t\tstat = this.options.stat(path);\n\t\t\tthis.stats.set(path, stat);\n\t\t}\n\t\treturn stat;\n\t}\n\n\t/** `path` changed since it was statted, so the next target to probe it in a batch in flight stats it again */\n\tinvalidate(path: string): void {\n\t\tthis.stats.delete(path);\n\t}\n\n\tprivate pass(): Promise<void> {\n\t\t// A pass reads its own stats, never ones from before it began\n\t\tthis.stats.clear();\n\t\t// The pass baselines any target not read yet\n\t\tthis.unread.clear();\n\t\treturn this.readAll([...this.targets]);\n\t}\n\n\tprivate readUnread(): void {\n\t\tif (this.unread.size === 0) return;\n\n\t\tconst targets = [...this.unread];\n\t\tthis.unread.clear();\n\t\tvoid this.readAll(targets);\n\t}\n\n\tprivate async readAll(targets: readonly PollTarget[]): Promise<void> {\n\t\tthis.batches++;\n\t\ttry {\n\t\t\t// A target that fails is read again next pass; nothing it saw this time is reported\n\t\t\tawait Promise.allSettled(targets.map(target => this.read(target)));\n\t\t} finally {\n\t\t\tthis.batches--;\n\t\t\tif (this.batches === 0) {\n\t\t\t\tthis.stats.clear();\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Reads `target` once any read of it in flight ends, so the reading is fresh and its probes current */\n\tprivate read(target: PollTarget): Promise<void> {\n\t\tconst poll = async (): Promise<void> => {\n\t\t\tif (!this.targets.has(target)) return;\n\n\t\t\tawait this.acquireSlot();\n\t\t\ttry {\n\t\t\t\tif (this.targets.has(target)) {\n\t\t\t\t\tawait target.poll();\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tthis.releaseSlot();\n\t\t\t}\n\t\t};\n\t\tconst previous = this.reading.get(target);\n\t\tconst reading: Promise<void> = (previous != null ? previous.then(poll, poll) : poll()).finally(() => {\n\t\t\tif (this.reading.get(target) === reading) {\n\t\t\t\tthis.reading.delete(target);\n\t\t\t}\n\t\t});\n\t\tthis.reading.set(target, reading);\n\t\treturn reading;\n\t}\n\n\tprivate acquireSlot(): Promise<void> | undefined {\n\t\tif (this.slotsInUse < defaultPollConcurrency) {\n\t\t\tthis.slotsInUse++;\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn new Promise(resolve => this.waiting.push(resolve));\n\t}\n\n\tprivate releaseSlot(): void {\n\t\tconst next = this.waiting.shift();\n\t\tif (next != null) {\n\t\t\tnext();\n\t\t} else {\n\t\t\tthis.slotsInUse--;\n\t\t}\n\t}\n\n\tprivate startTimer(): void {\n\t\tif (this.timer != null || this.disposed || this.targets.size === 0) return;\n\n\t\tif (this.options.isActive != null) {\n\t\t\tthis.timer = setInterval(() => void this.tick(), this.activeCheckMs);\n\t\t} else if (!this.suspended) {\n\t\t\tthis.timer = setTimeout(() => {\n\t\t\t\tthis.timer = undefined;\n\t\t\t\tthis.due = true;\n\t\t\t\tvoid this.tick();\n\t\t\t}, this.intervalMs);\n\t\t} else {\n\t\t\treturn;\n\t\t}\n\n\t\t// A poll alone must not keep a (Node) process alive; in the browser timers are numbers\n\t\tif (typeof this.timer !== 'number') {\n\t\t\tthis.timer.unref();\n\t\t}\n\t}\n\n\tprivate stopTimer(): void {\n\t\tif (this.timer == null) return;\n\n\t\tif (this.options.isActive != null) {\n\t\t\tclearInterval(this.timer);\n\t\t} else {\n\t\t\tclearTimeout(this.timer);\n\t\t}\n\t\tthis.timer = undefined;\n\t\tthis.due = true;\n\t}\n}\n\n/**\n * Stands in for a watcher on `basePath`: stats each probe and reports one whose `mtime:size` moved as a `change` of\n * the paths it is emitted as, through the same handler the watcher's own events take. A probe's first read (and a\n * probe new to the set, as after a branch switch) only records; one that was missing and is now present moved. A stat\n * that throws keeps the last reading, so it never counts as a move.\n */\nexport class GitDirProbeTarget implements PollTarget {\n\tprivate readonly signatures = new Map<string, string>();\n\t/** For each poll whose stats are in flight, the paths {@link forget} cleared meanwhile, which it must not record */\n\tprivate readonly forgottenDuringPolls = new Set<Set<string>>();\n\n\tconstructor(\n\t\tprivate readonly basePath: string,\n\t\tprivate readonly stats: Pick<GitDirPoller, 'stat' | 'invalidate'>,\n\t\tprivate readonly getProbes: () => Iterable<GitDirProbe>,\n\t\t/** For each path a probe may be emitted as, the paths of the probes emitted as it */\n\t\tprivate readonly probesByEmittedPath: ReadonlyMap<string, readonly string[]>,\n\t\tprivate readonly onMoved: (event: FileWatchEvent, probe: GitDirProbe) => void,\n\t) {}\n\n\tasync poll(): Promise<void> {\n\t\tconst probes = [...this.getProbes()];\n\t\tconst forgotten = new Set<string>();\n\t\tthis.forgottenDuringPolls.add(forgotten);\n\t\tconst readings = await Promise.all(probes.map(p => this.read(p.path)));\n\t\tthis.forgottenDuringPolls.delete(forgotten);\n\n\t\tconst seen = new Set<string>();\n\t\tconst moved: GitDirProbe[] = [];\n\t\tfor (let i = 0; i < probes.length; i++) {\n\t\t\tconst probe = probes[i];\n\t\t\tseen.add(probe.path);\n\n\t\t\tconst reading = readings[i];\n\t\t\tif (reading == null || forgotten.has(probe.path)) continue;\n\n\t\t\tconst previous = this.signatures.get(probe.path);\n\t\t\tthis.signatures.set(probe.path, reading);\n\t\t\tif (previous != null && previous !== reading) {\n\t\t\t\tmoved.push(probe);\n\t\t\t}\n\t\t}\n\n\t\t// A probe that left the set starts over if it comes back\n\t\tfor (const path of this.signatures.keys()) {\n\t\t\tif (!seen.has(path)) {\n\t\t\t\tthis.signatures.delete(path);\n\t\t\t}\n\t\t}\n\n\t\tfor (const probe of moved) {\n\t\t\tfor (const path of probe.emitAs ?? [probe.path]) {\n\t\t\t\tthis.onMoved({ path: joinPaths(this.basePath, path), reason: 'change' }, probe);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The watcher reported `path` itself, so the next poll records the probes it touched (the path, a ref's lock file\n\t * standing for the ref, the directories above it, and the probes emitted as it, like `logs/HEAD` as `HEAD`, which\n\t * the watcher never sees) without reporting them again.\n\t */\n\tforget(path: string): void {\n\t\tif (!isDescendant(path, this.basePath)) return;\n\n\t\tlet relativePath = relative(this.basePath, path);\n\t\tif (relativePath.endsWith('.lock')) {\n\t\t\trelativePath = relativePath.substring(0, relativePath.length - 5);\n\t\t}\n\n\t\tfor (let p = relativePath; p.length > 0; p = p.substring(0, Math.max(0, p.lastIndexOf('/')))) {\n\t\t\tthis.clearSignature(p);\n\t\t}\n\n\t\tfor (const probePath of this.probesByEmittedPath.get(relativePath) ?? []) {\n\t\t\tthis.clearSignature(probePath);\n\t\t}\n\t}\n\n\tprivate clearSignature(path: string): void {\n\t\tthis.signatures.delete(path);\n\t\tthis.stats.invalidate(joinPaths(this.basePath, path));\n\t\tfor (const forgotten of this.forgottenDuringPolls) {\n\t\t\tforgotten.add(path);\n\t\t}\n\t}\n\n\tprivate async read(path: string): Promise<string | undefined> {\n\t\ttry {\n\t\t\tconst stat = await this.stats.stat(joinPaths(this.basePath, path));\n\t\t\treturn stat == null ? 'missing' : `${stat.mtime}:${stat.size}`;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n}\n"],"mappings":";;AAKA,MAAM,wBAAwB;AAC9B,MAAM,2BAA2B;AACjC,MAAM,yBAAyB;;;;;;;;;;;;AA4B/B,IAAa,eAAb,MAAuD;CAyBjC;CAxBrB,0BAA2B,IAAI,IAAgB;;CAE/C,yBAA0B,IAAI,IAAgB;;CAE9C,0BAA2B,IAAI,IAA+B;;CAE9D,UAA2C,CAAC;;;;;CAK5C,wBAAyB,IAAI,IAAiC;CAC9D;CACA;CACA;CACA;CACA,UAAkB;CAClB,aAAqB;;CAErB,MAAc;CACd,aAAqB;CACrB,YAAoB;CACpB,WAAmB;CAEnB,YAAY,SAAuC;EAA9B,KAAA,UAAA;EACpB,KAAK,aAAa,QAAQ,cAAc;EACxC,KAAK,gBAAgB,QAAQ,iBAAiB;CAC/C;CAEA,CAAC,OAAO,WAAiB;EACxB,KAAK,QAAQ;CACd;CAEA,UAAgB;EACf,KAAK,WAAW;EAChB,KAAK,QAAQ,MAAM;EACnB,KAAK,OAAO,MAAM;EAClB,KAAK,MAAM,MAAM;EACjB,KAAK,UAAU;CAChB;CAEA,IAAI,OAAe;EAClB,OAAO,KAAK,QAAQ;CACrB;CAEA,IAAI,QAA0B;EAC7B,IAAI,KAAK,YAAY,KAAK,QAAQ,IAAI,MAAM,GAAG;EAE/C,KAAK,QAAQ,IAAI,MAAM;EACvB,KAAK,OAAO,IAAI,MAAM;EACtB,IAAI,KAAK,OAAO,SAAS,G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;EAC7D,IAAI;GACH,MAAM,OAAO,MAAM,KAAK,MAAM,KAAK,UAAU,KAAK,UAAU,IAAI,CAAC;GACjE,OAAO,QAAQ,OAAO,YAAY,GAAG,KAAK,MAAM,GAAG,KAAK;EACzD,QAAQ;GACP;EACD;CACD;AACD"}
1
+ {"version":3,"file":"gitDirPoller.js","names":[],"sources":["../../../../git/src/watching/gitDirPoller.ts"],"sourcesContent":["import type { UnifiedDisposable } from '@gitlens/utils/disposable.js';\nimport { isDescendant, joinPaths, relative } from '@gitlens/utils/path.js';\nimport type { FileWatchEvent } from './provider.js';\nimport type { WatchPollingOptions } from './watchService.js';\n\nconst defaultPollIntervalMs = 60_000;\nconst defaultPollActiveCheckMs = 5_000;\nconst defaultPollConcurrency = 4;\n\ntype GitDirStat = Awaited<ReturnType<WatchPollingOptions['stat']>>;\n\n/** Something the {@link GitDirPoller} reads once per pass */\nexport interface PollTarget {\n\tpoll(): Promise<void>;\n}\n\n/** A file or directory a poll stats, relative to the directory it watches in place of a watcher */\nexport interface GitDirProbe {\n\t/** `/`-separated, relative to the target's base path */\n\treadonly path: string;\n\t/** The relative paths a move is reported as, in place of `path` */\n\treadonly emitAs?: readonly string[];\n}\n\n/**\n * Runs passes over the poll targets of every watcher that can't be trusted, reading at most 4 targets at once across\n * passes and first readings. A target is read once soon after it is added, so its baseline doesn't wait for the next\n * pass; targets added together are read together.\n *\n * With the default gate (no `isActive`), one timer runs a pass every `intervalMs`, stopped by {@link suspend} and\n * restarted by {@link resume}, which runs a pass at once. With a host's `isActive`, whose changes core can't see, one\n * timer looks at it every `activeCheckMs`: a pass is due once `intervalMs` has gone by since the last one, or at the\n * first look after the gate opens (or after {@link nudge}), so a window that comes back between passes doesn't wait out\n * the rest of one.\n */\nexport class GitDirPoller implements UnifiedDisposable {\n\tprivate readonly targets = new Set<PollTarget>();\n\t/** Targets added since the last pass and not yet read */\n\tprivate readonly unread = new Set<PollTarget>();\n\t/** Each target's last read asked for; a target is never read twice at once, so the next waits for it */\n\tprivate readonly reading = new Map<PollTarget, Promise<void>>();\n\t/** Reads waiting for one of the {@link defaultPollConcurrency} slots, which a finished read hands over */\n\tprivate readonly waiting: (() => void)[] = [];\n\t/**\n\t * The stats of the batches (a pass, or first readings) in flight, shared by every target that probes the same path,\n\t * as the main checkout's root and its common dir do\n\t */\n\tprivate readonly stats = new Map<string, Promise<GitDirStat>>();\n\tprivate readonly intervalMs: number;\n\tprivate readonly activeCheckMs: number;\n\tprivate timer: ReturnType<typeof setTimeout> | undefined;\n\tprivate running: Promise<void> | undefined;\n\tprivate batches = 0;\n\tprivate slotsInUse = 0;\n\t/** The next look runs a pass whatever the interval says */\n\tprivate due = true;\n\tprivate lastPassAt = 0;\n\tprivate suspended = false;\n\tprivate disposed = false;\n\n\tconstructor(readonly options: WatchPollingOptions) {\n\t\tthis.intervalMs = options.intervalMs ?? defaultPollIntervalMs;\n\t\tthis.activeCheckMs = options.activeCheckMs ?? defaultPollActiveCheckMs;\n\t}\n\n\t[Symbol.dispose](): void {\n\t\tthis.dispose();\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.targets.clear();\n\t\tthis.unread.clear();\n\t\tthis.stats.clear();\n\t\tthis.stopTimer();\n\t}\n\n\tget size(): number {\n\t\treturn this.targets.size;\n\t}\n\n\tadd(target: PollTarget): void {\n\t\tif (this.disposed || this.targets.has(target)) return;\n\n\t\tthis.targets.add(target);\n\t\tthis.unread.add(target);\n\t\tif (this.unread.size === 1) {\n\t\t\tqueueMicrotask(() => this.readUnread());\n\t\t}\n\t\tthis.startTimer();\n\t}\n\n\tdelete(target: PollTarget): void {\n\t\tthis.unread.delete(target);\n\t\tif (!this.targets.delete(target) || this.targets.size !== 0) return;\n\n\t\tthis.stopTimer();\n\t}\n\n\t/** Makes the next look a pass, and looks now */\n\tnudge(): void {\n\t\tthis.due = true;\n\t\tvoid this.tick();\n\t}\n\n\t/** Under the default gate, stops passes (and the timer) until {@link resume}; a host's `isActive` ignores it */\n\tsuspend(): void {\n\t\tthis.suspended = true;\n\t\tif (this.options.isActive == null) {\n\t\t\tthis.stopTimer();\n\t\t}\n\t}\n\n\t/** Lifts {@link suspend}, and runs a pass now, so what moved meanwhile is polled rather than at the next look */\n\tresume(): void {\n\t\tthis.suspended = false;\n\t\tthis.nudge();\n\t}\n\n\t/** One look at the gate: runs a pass when one is due, the gate is open and none is in flight */\n\ttick(): Promise<void> {\n\t\tif (this.disposed || this.targets.size === 0) return Promise.resolve();\n\n\t\tif (!(this.options.isActive?.() ?? !this.suspended)) {\n\t\t\tthis.due = true;\n\t\t\treturn Promise.resolve();\n\t\t}\n\n\t\t// A pass asked for while one is in flight runs once it ends; an elapsed interval just waits for the next look\n\t\tif (this.running != null) return this.running;\n\n\t\tconst now = performance.now();\n\t\tif (!this.due && now - this.lastPassAt < this.intervalMs) return Promise.resolve();\n\n\t\t// Under the default gate the timer counts the interval from this pass, whatever started it\n\t\tif (this.options.isActive == null) {\n\t\t\tthis.stopTimer();\n\t\t\tthis.startTimer();\n\t\t}\n\t\tthis.due = false;\n\t\tthis.lastPassAt = now;\n\t\tthis.running = this.pass().finally(() => {\n\t\t\tthis.running = undefined;\n\t\t\tif (this.due) {\n\t\t\t\tvoid this.tick();\n\t\t\t}\n\t\t});\n\t\treturn this.running;\n\t}\n\n\t/** Stats `path` once for every target that probes it in the batches in flight */\n\tstat(path: string): Promise<GitDirStat> {\n\t\tif (this.batches === 0) return this.options.stat(path);\n\n\t\tlet stat = this.stats.get(path);\n\t\tif (stat == null) {\n\t\t\tstat = this.options.stat(path);\n\t\t\tthis.stats.set(path, stat);\n\t\t}\n\t\treturn stat;\n\t}\n\n\t/** `path` changed since it was statted, so the next target to probe it in a batch in flight stats it again */\n\tinvalidate(path: string): void {\n\t\tthis.stats.delete(path);\n\t}\n\n\tprivate pass(): Promise<void> {\n\t\t// A pass reads its own stats, never ones from before it began\n\t\tthis.stats.clear();\n\t\t// The pass baselines any target not read yet\n\t\tthis.unread.clear();\n\t\treturn this.readAll([...this.targets]);\n\t}\n\n\tprivate readUnread(): void {\n\t\tif (this.unread.size === 0) return;\n\n\t\tconst targets = [...this.unread];\n\t\tthis.unread.clear();\n\t\tvoid this.readAll(targets);\n\t}\n\n\tprivate async readAll(targets: readonly PollTarget[]): Promise<void> {\n\t\tthis.batches++;\n\t\ttry {\n\t\t\t// A target that fails is read again next pass; nothing it saw this time is reported\n\t\t\tawait Promise.allSettled(targets.map(target => this.read(target)));\n\t\t} finally {\n\t\t\tthis.batches--;\n\t\t\tif (this.batches === 0) {\n\t\t\t\tthis.stats.clear();\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Reads `target` once any read of it in flight ends, so the reading is fresh and its probes current */\n\tprivate read(target: PollTarget): Promise<void> {\n\t\tconst poll = async (): Promise<void> => {\n\t\t\tif (!this.targets.has(target)) return;\n\n\t\t\tawait this.acquireSlot();\n\t\t\ttry {\n\t\t\t\tif (this.targets.has(target)) {\n\t\t\t\t\tawait target.poll();\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tthis.releaseSlot();\n\t\t\t}\n\t\t};\n\t\tconst previous = this.reading.get(target);\n\t\tconst reading: Promise<void> = (previous != null ? previous.then(poll, poll) : poll()).finally(() => {\n\t\t\tif (this.reading.get(target) === reading) {\n\t\t\t\tthis.reading.delete(target);\n\t\t\t}\n\t\t});\n\t\tthis.reading.set(target, reading);\n\t\treturn reading;\n\t}\n\n\tprivate acquireSlot(): Promise<void> | undefined {\n\t\tif (this.slotsInUse < defaultPollConcurrency) {\n\t\t\tthis.slotsInUse++;\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn new Promise(resolve => this.waiting.push(resolve));\n\t}\n\n\tprivate releaseSlot(): void {\n\t\tconst next = this.waiting.shift();\n\t\tif (next != null) {\n\t\t\tnext();\n\t\t} else {\n\t\t\tthis.slotsInUse--;\n\t\t}\n\t}\n\n\tprivate startTimer(): void {\n\t\tif (this.timer != null || this.disposed || this.targets.size === 0) return;\n\n\t\tif (this.options.isActive != null) {\n\t\t\tthis.timer = setInterval(() => void this.tick(), this.activeCheckMs);\n\t\t} else if (!this.suspended) {\n\t\t\tthis.timer = setTimeout(() => {\n\t\t\t\tthis.timer = undefined;\n\t\t\t\tthis.due = true;\n\t\t\t\tvoid this.tick();\n\t\t\t}, this.intervalMs);\n\t\t} else {\n\t\t\treturn;\n\t\t}\n\n\t\t// A poll alone must not keep a (Node) process alive; in the browser timers are numbers\n\t\tif (typeof this.timer !== 'number') {\n\t\t\tthis.timer.unref();\n\t\t}\n\t}\n\n\tprivate stopTimer(): void {\n\t\tif (this.timer == null) return;\n\n\t\tif (this.options.isActive != null) {\n\t\t\tclearInterval(this.timer);\n\t\t} else {\n\t\t\tclearTimeout(this.timer);\n\t\t}\n\t\tthis.timer = undefined;\n\t\tthis.due = true;\n\t}\n}\n\n/**\n * Stands in for a watcher on `basePath`: stats each probe and reports one whose `mtime:size` moved as a `change` of\n * the paths it is emitted as, through the same handler the watcher's own events take. A probe's first read (and a\n * probe new to the set, as after a branch switch) only records; one that was missing and is now present moved. A stat\n * that throws keeps the last reading, so it never counts as a move.\n */\nexport class GitDirProbeTarget implements PollTarget {\n\tprivate readonly signatures = new Map<string, string>();\n\t/** For each poll whose stats are in flight, the paths {@link forget} cleared meanwhile, which it must not record */\n\tprivate readonly forgottenDuringPolls = new Set<Set<string>>();\n\tprivate racyReadings = 0;\n\n\tconstructor(\n\t\tprivate readonly basePath: string,\n\t\tprivate readonly stats: Pick<GitDirPoller, 'stat' | 'invalidate'>,\n\t\tprivate readonly getProbes: () => Iterable<GitDirProbe>,\n\t\t/** For each path a probe may be emitted as, the paths of the probes emitted as it */\n\t\tprivate readonly probesByEmittedPath: ReadonlyMap<string, readonly string[]>,\n\t\tprivate readonly onMoved: (event: FileWatchEvent, probe: GitDirProbe) => void,\n\t\tprivate readonly options?: {\n\t\t\t/**\n\t\t\t * Whether a reading can't be trusted to show the next change, as on a file system whose timestamps tick\n\t\t\t * too coarsely to tell a write just after the stat from the one before it. Such a reading is recorded as\n\t\t\t * matching no other, so the probe counts as moved at its next read. Given the absolute path it was read from\n\t\t\t */\n\t\t\treadonly isRacy?: (stat: NonNullable<GitDirStat>, path: string) => boolean;\n\t\t},\n\t) {}\n\n\tasync poll(): Promise<void> {\n\t\tconst probes = [...this.getProbes()];\n\t\tconst forgotten = new Set<string>();\n\t\tthis.forgottenDuringPolls.add(forgotten);\n\t\tconst readings = await Promise.all(probes.map(p => this.read(p.path)));\n\t\tthis.forgottenDuringPolls.delete(forgotten);\n\n\t\tconst seen = new Set<string>();\n\t\tconst moved: GitDirProbe[] = [];\n\t\tfor (let i = 0; i < probes.length; i++) {\n\t\t\tconst probe = probes[i];\n\t\t\tseen.add(probe.path);\n\n\t\t\tconst reading = readings[i];\n\t\t\tif (reading == null || forgotten.has(probe.path)) continue;\n\n\t\t\tconst previous = this.signatures.get(probe.path);\n\t\t\tthis.signatures.set(probe.path, reading);\n\t\t\tif (previous != null && previous !== reading) {\n\t\t\t\tmoved.push(probe);\n\t\t\t}\n\t\t}\n\n\t\t// A probe that left the set starts over if it comes back\n\t\tfor (const path of this.signatures.keys()) {\n\t\t\tif (!seen.has(path)) {\n\t\t\t\tthis.signatures.delete(path);\n\t\t\t}\n\t\t}\n\n\t\tfor (const probe of moved) {\n\t\t\tfor (const path of probe.emitAs ?? [probe.path]) {\n\t\t\t\tthis.onMoved({ path: joinPaths(this.basePath, path), reason: 'change' }, probe);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The watcher reported `path` itself, so the next poll records the probes it touched (the path, a ref's lock file\n\t * standing for the ref, the directories above it, and the probes emitted as it, like `logs/HEAD` as `HEAD`, which\n\t * the watcher never sees) without reporting them again.\n\t */\n\tforget(path: string): void {\n\t\tif (!isDescendant(path, this.basePath)) return;\n\n\t\tlet relativePath = relative(this.basePath, path);\n\t\tif (relativePath.endsWith('.lock')) {\n\t\t\trelativePath = relativePath.substring(0, relativePath.length - 5);\n\t\t}\n\n\t\tfor (let p = relativePath; p.length > 0; p = p.substring(0, Math.max(0, p.lastIndexOf('/')))) {\n\t\t\tthis.clearSignature(p);\n\t\t}\n\n\t\tfor (const probePath of this.probesByEmittedPath.get(relativePath) ?? []) {\n\t\t\tthis.clearSignature(probePath);\n\t\t}\n\t}\n\n\tprivate clearSignature(path: string): void {\n\t\tthis.signatures.delete(path);\n\t\tthis.stats.invalidate(joinPaths(this.basePath, path));\n\t\tfor (const forgotten of this.forgottenDuringPolls) {\n\t\t\tforgotten.add(path);\n\t\t}\n\t}\n\n\tprivate async read(path: string): Promise<string | undefined> {\n\t\ttry {\n\t\t\tconst absolutePath = joinPaths(this.basePath, path);\n\t\t\tconst stat = await this.stats.stat(absolutePath);\n\t\t\tif (stat == null) return 'missing';\n\n\t\t\tconst signature = `${stat.mtime}:${stat.size}`;\n\t\t\treturn this.options?.isRacy?.(stat, absolutePath) ? `${signature}:racy:${++this.racyReadings}` : signature;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n}\n"],"mappings":";;AAKA,MAAM,wBAAwB;AAC9B,MAAM,2BAA2B;AACjC,MAAM,yBAAyB;;;;;;;;;;;;AA4B/B,IAAa,eAAb,MAAuD;CAyBjC;CAxBrB,0BAA2B,IAAI,IAAgB;;CAE/C,yBAA0B,IAAI,IAAgB;;CAE9C,0BAA2B,IAAI,IAA+B;;CAE9D,UAA2C,CAAC;;;;;CAK5C,wBAAyB,IAAI,IAAiC;CAC9D;CACA;CACA;CACA;CACA,UAAkB;CAClB,aAAqB;;CAErB,MAAc;CACd,aAAqB;CACrB,YAAoB;CACpB,WAAmB;CAEnB,YAAY,SAAuC;EAA9B,KAAA,UAAA;EACpB,KAAK,aAAa,QAAQ,cAAc;EACxC,KAAK,gBAAgB,QAAQ,iBAAiB;CAC/C;CAEA,CAAC,OAAO,WAAiB;EACxB,KAAK,QAAQ;CACd;CAEA,UAAgB;EACf,KAAK,WAAW;EAChB,KAAK,QAAQ,MAAM;EACnB,KAAK,OAAO,MAAM;EACl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KAAK,eAAe,CAAC;EAGtB,KAAK,MAAM,aAAa,KAAK,oBAAoB,IAAI,YAAY,KAAK,CAAC,GACtE,KAAK,eAAe,SAAS;CAE/B;CAEA,eAAuB,MAAoB;EAC1C,KAAK,WAAW,OAAO,IAAI;EAC3B,KAAK,MAAM,WAAW,UAAU,KAAK,UAAU,IAAI,CAAC;EACpD,KAAK,MAAM,aAAa,KAAK,sBAC5B,UAAU,IAAI,IAAI;CAEpB;CAEA,MAAc,KAAK,MAA2C;EAC7D,IAAI;GACH,MAAM,eAAe,UAAU,KAAK,UAAU,IAAI;GAClD,MAAM,OAAO,MAAM,KAAK,MAAM,KAAK,YAAY;GAC/C,IAAI,QAAQ,MAAM,OAAO;GAEzB,MAAM,YAAY,GAAG,KAAK,MAAM,GAAG,KAAK;GACxC,OAAO,KAAK,SAAS,SAAS,MAAM,YAAY,IAAI,GAAG,UAAU,QAAQ,EAAE,KAAK,iBAAiB;EAClG,QAAQ;GACP;EACD;CACD;AACD"}
@@ -0,0 +1,144 @@
1
+ import { ResourceUsage } from "../../utils/resourceUsage.js";
2
+ import { Cache } from "../cache.js";
3
+ //#region ../git/src/watching/unwatchedCacheValidator.d.ts
4
+ type ProbeStat = {
5
+ readonly mtime: number;
6
+ readonly size: number;
7
+ };
8
+ export interface UnwatchedCacheValidatorOptions {
9
+ readonly cache: Cache;
10
+ /** A path's modification time (ms since the epoch) and size; `undefined` when it doesn't exist */
11
+ readonly stat: (path: string) => Promise<ProbeStat | undefined>;
12
+ /** A directory's entries with their `FileType`s; a rejection whose `code` is `ENOENT` or `FileNotFound` means it isn't there */
13
+ readonly readDirectory: (path: string) => Promise<readonly (readonly [string, number])[]>;
14
+ /** A file's bytes; `undefined` when it doesn't exist. Without it, no worktree is ignored */
15
+ readonly readFile?: (path: string) => Promise<Uint8Array | undefined>;
16
+ /**
17
+ * The absolute, normalized folders whose worktrees core ignores (see `GitProvider.getIgnoredWorktreeRoots`), asked
18
+ * with a `repoPath` whose git dir the cache holds; a worktree in one is left out of the worktree list, so what moves
19
+ * in its admin entry changes nothing cached. A rejection means none is ignored
20
+ */
21
+ readonly getIgnoredWorktreeRoots?: (repoPath: string) => Promise<readonly string[]>;
22
+ /**
23
+ * Caches `repoPath`'s git dir without running git, for a repository nothing resolved one for yet (as when only its
24
+ * branches, remotes or tags were read); whether one is cached. Without it, or when it answers `false`, such a
25
+ * repository isn't validated: a layout git's files alone can't answer for (a bare repository, a submodule, a
26
+ * `--separate-git-dir` checkout, a `core.worktree`) stays unvalidated until a read resolves its git dir. A rejection
27
+ * is a failure to look, retried soon; `false` is a repository its files can't answer for, tried again rarely
28
+ */
29
+ readonly resolveGitDir?: (repoPath: string) => Promise<boolean>;
30
+ /**
31
+ * Whether a `.git` watcher covers `repoPath` and is live (see `RepositoryWatchService.isRepoWatched`): one that is
32
+ * suspended holds what it hears until it resumes, so a repository is unwatched meanwhile, without being announced
33
+ */
34
+ readonly isWatched: (repoPath: string) => boolean;
35
+ /** Milliseconds since the epoch, the clock `stat`'s `mtime` is on. Default: `Date.now` */
36
+ readonly now?: () => number;
37
+ /**
38
+ * How long a read waits for a validation before it's served from the cache as is, and how long a hung file-system
39
+ * call holds back other repositories' validations. Default: 1000
40
+ */
41
+ readonly timeoutMs?: number;
42
+ /**
43
+ * How many of Node's file-system threads (libuv's pool) the validator's calls may hold at once, counting those hung
44
+ * past {@link timeoutMs}; at most two run at once. Default: 2, which leaves a host two of the pool's default four
45
+ */
46
+ readonly maxFsThreads?: number;
47
+ }
48
+ /**
49
+ * Keeps the caches that never expire fresh for repositories no `.git` watcher covers: before such a read, stats the
50
+ * files a watcher would have reported (see {@link UnwatchedCacheValidatorOptions.stat}) and applies what moved to the
51
+ * cache as a watcher event would have. Both a worktree's own git dir and the common one are validated while that
52
+ * worktree is unwatched; while another worktree's watcher covers the common one, what moved there clears only the
53
+ * unwatched worktrees' own entries. A repository whose git dir nothing resolved yet is validated once
54
+ * {@link UnwatchedCacheValidatorOptions.resolveGitDir} resolves one; a repository whose files can't show it is looked at
55
+ * again rarely, and one whose resolution failed within the validation window. A read waits at most
56
+ * {@link UnwatchedCacheValidatorOptions.timeoutMs} for a validation (and a resolution before it); one that outlasts it
57
+ * is left to finish on its own, and the reads meanwhile are served as is.
58
+ */
59
+ export declare class UnwatchedCacheValidator {
60
+ private readonly cache;
61
+ private readonly isWatched;
62
+ private readonly now;
63
+ private readonly timeoutMs;
64
+ private readonly resolveGitDir;
65
+ private readonly gate;
66
+ /** Since it was created; what {@link getResourceUsage} reports */
67
+ private readonly counts;
68
+ private readonly dirOptions;
69
+ /** Keyed by repo path */
70
+ private readonly roots;
71
+ /** Keyed by common path */
72
+ private readonly commons;
73
+ /** Keyed by absolute path; the readings that may be racy, with when each was first read */
74
+ private readonly racyReadings;
75
+ /**
76
+ * Keyed by repo path; one that found nothing is kept, so the reads meanwhile don't retry it: for the window after a
77
+ * failure, for {@link unresolvableRetryMs} after a git dir the files can't show
78
+ */
79
+ private readonly resolutions;
80
+ /** The validation {@link onWatched} ran as a watcher attached, by repo path, which reads wait for while it runs */
81
+ private readonly handoffs;
82
+ /** By the repo path of a watched worktree, what moved in its common git dir that its watcher was left to clear */
83
+ private readonly deferred;
84
+ constructor(options: UnwatchedCacheValidatorOptions);
85
+ /**
86
+ * Whether `stat` of `path` may still show the same file a write in its own second would leave. Only a whole-second
87
+ * mtime can, and only until its second ended: by the mtime's own clock, and by ours since the reading was first
88
+ * seen, whichever comes first
89
+ */
90
+ private isRacy;
91
+ /**
92
+ * Validates what `repoPath`'s reads would be served from, unless a watcher covers it or it was validated within
93
+ * the last 250ms. `undefined` when there's nothing to wait for; otherwise settles once what moved was applied to
94
+ * the cache, or after {@link UnwatchedCacheValidatorOptions.timeoutMs} with the cache as is, whichever is first.
95
+ * Never rejects. A path that can't be read counts as moved as it becomes unreadable and again as it becomes
96
+ * readable; a directory that can't be listed is listed again at the next validation, and what changes deeper inside
97
+ * it goes unseen until it can be.
98
+ */
99
+ validate(repoPath: string): Promise<void> | undefined;
100
+ /**
101
+ * A watcher attached to `repoPath`, so it reports only what changes from now on: validates now what changed since
102
+ * the last validation, whatever the window, and has `repoPath`'s reads wait for it.
103
+ */
104
+ onWatched(repoPath: string): void;
105
+ /**
106
+ * A watcher left `repoPath`, dropping what it held back unreported. What moved in its common git dir that an
107
+ * unwatched sibling's validation left to it is applied now, since that validation took the shared baseline past it;
108
+ * whatever else it dropped is still ahead of its own baselines.
109
+ */
110
+ onUnwatched(repoPath: string): void;
111
+ private run;
112
+ /** Starts validating `repoPath`, or joins the validations in flight; what a read waits for */
113
+ private start;
114
+ /**
115
+ * Resolves the git dir of `repoPath` (through the gate, as one call, keyed by `repoPath` since its common git dir
116
+ * isn't known yet), then validates it as usual within the same wait. That first validation has no baseline.
117
+ */
118
+ private resolveThenValidate;
119
+ private startResolution;
120
+ /**
121
+ * Settles once `waits`' validations do, or once the timeout elapses, latching those still running as slow (and what
122
+ * they started) so the reads after it don't wait for them again
123
+ */
124
+ private waitAtMost;
125
+ /**
126
+ * What validating has cost, for a host to weigh against watching: counts since the validator was created of the
127
+ * validations run, those that cleared something, the reads served as is after their wait timed out, the git dir
128
+ * lookups, and the file-system calls made; and, as of now, the calls stuck on a hung mount and the git dirs kept
129
+ */
130
+ getResourceUsage(): ResourceUsage;
131
+ /** The repository's other worktrees whose watchers cover its common git dir */
132
+ private getCommonWatchers;
133
+ private getTarget;
134
+ private runTargets;
135
+ /**
136
+ * Applies what moved to `repoPath`, and what moved in the common git dir to its other unwatched registered worktrees
137
+ * too, as the common watcher would have told each of them. While another worktree's watcher covers the common git
138
+ * dir, it already cleared the shared entries, so only the worktrees' own are. A watcher covers it only if it watched
139
+ * since before the stats began (`watchedAtStart`)
140
+ */
141
+ private apply;
142
+ }
143
+ //#endregion
144
+ //# sourceMappingURL=unwatchedCacheValidator.d.ts.map