@gitkraken/core-gitlens 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -1
- package/dist/git/cache.d.ts +31 -0
- package/dist/git/cache.js +101 -30
- package/dist/git/cache.js.map +1 -1
- package/dist/git/context.d.ts +3 -1
- package/dist/git/context.js.map +1 -1
- package/dist/git/errors.d.ts +3 -1
- package/dist/git/errors.js +4 -1
- package/dist/git/errors.js.map +1 -1
- package/dist/git/models/pullRequest.d.ts +90 -1
- package/dist/git/models/pullRequest.js +18 -2
- package/dist/git/models/pullRequest.js.map +1 -1
- package/dist/git/providers/shared/remotes.js +2 -0
- package/dist/git/providers/shared/remotes.js.map +1 -1
- package/dist/git/utils/pullRequest.utils.d.ts +72 -1
- package/dist/git/utils/pullRequest.utils.js +99 -1
- package/dist/git/utils/pullRequest.utils.js.map +1 -1
- package/dist/git/utils/repository.utils.d.ts +6 -0
- package/dist/git/utils/repository.utils.js +14 -2
- package/dist/git/utils/repository.utils.js.map +1 -1
- package/dist/git/watching/gitDirPoller.d.ts +10 -1
- package/dist/git/watching/gitDirPoller.js +9 -3
- package/dist/git/watching/gitDirPoller.js.map +1 -1
- package/dist/git/watching/unwatchedCacheValidator.d.ts +144 -0
- package/dist/git/watching/unwatchedCacheValidator.js +884 -0
- package/dist/git/watching/unwatchedCacheValidator.js.map +1 -0
- package/dist/git/watching/watchGroup.d.ts +2 -0
- package/dist/git/watching/watchGroup.js +4 -8
- package/dist/git/watching/watchGroup.js.map +1 -1
- package/dist/git/watching/watchService.d.ts +23 -0
- package/dist/git/watching/watchService.js +42 -2
- package/dist/git/watching/watchService.js.map +1 -1
- package/dist/git/watching/watchSession.d.ts +2 -0
- package/dist/git/watching/watchSession.js +3 -2
- package/dist/git/watching/watchSession.js.map +1 -1
- package/dist/git-cli/cliGitProvider.js +1 -1
- package/dist/git-cli/cliGitProvider.js.map +1 -1
- package/dist/git-cli/exec/commandClassifier.d.ts +31 -1
- package/dist/git-cli/exec/commandClassifier.js +67 -16
- package/dist/git-cli/exec/commandClassifier.js.map +1 -1
- package/dist/git-cli/exec/git.d.ts +46 -2
- package/dist/git-cli/exec/git.js +80 -7
- package/dist/git-cli/exec/git.js.map +1 -1
- package/dist/git-cli/exec/gitDirResolver.d.ts +11 -0
- package/dist/git-cli/exec/gitDirResolver.js +34 -1
- package/dist/git-cli/exec/gitDirResolver.js.map +1 -1
- package/dist/git-cli/exec/gitQueue.js +2 -28
- package/dist/git-cli/exec/gitQueue.js.map +1 -1
- package/dist/git-cli/providers/branches.d.ts +1 -0
- package/dist/git-cli/providers/branches.js +6 -0
- package/dist/git-cli/providers/branches.js.map +1 -1
- package/dist/git-cli/providers/config.d.ts +13 -1
- package/dist/git-cli/providers/config.js +48 -14
- package/dist/git-cli/providers/config.js.map +1 -1
- package/dist/git-cli/providers/pausedOperations.d.ts +1 -0
- package/dist/git-cli/providers/pausedOperations.js +4 -0
- package/dist/git-cli/providers/pausedOperations.js.map +1 -1
- package/dist/git-cli/providers/revision.js +2 -0
- package/dist/git-cli/providers/revision.js.map +1 -1
- package/dist/git-cli/providers/worktrees.js +2 -0
- package/dist/git-cli/providers/worktrees.js.map +1 -1
- package/dist/git-cli/service.d.ts +25 -1
- package/dist/git-cli/service.js +45 -0
- package/dist/git-cli/service.js.map +1 -1
- package/dist/plus/ai/errors.d.ts +8 -2
- package/dist/plus/ai/errors.js +15 -3
- package/dist/plus/ai/errors.js.map +1 -1
- package/dist/plus/git-github/api/github.d.ts +51 -1
- package/dist/plus/git-github/api/github.js +276 -3
- package/dist/plus/git-github/api/github.js.map +1 -1
- package/dist/plus/git-github/models.d.ts +54 -1
- package/dist/plus/git-github/models.js +48 -3
- package/dist/plus/git-github/models.js.map +1 -1
- package/dist/plus/integrations/fieldPresence.d.ts +6 -1
- package/dist/plus/integrations/fieldPresence.js +19 -9
- package/dist/plus/integrations/fieldPresence.js.map +1 -1
- package/dist/plus/integrations/models/gitHostIntegration.d.ts +26 -1
- package/dist/plus/integrations/models/gitHostIntegration.js +51 -0
- package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
- package/dist/plus/integrations/models/integration.d.ts +15 -2
- package/dist/plus/integrations/models/integration.js.map +1 -1
- package/dist/plus/integrations/providers/github.d.ts +16 -1
- package/dist/plus/integrations/providers/github.js +53 -1
- package/dist/plus/integrations/providers/github.js.map +1 -1
- package/dist/plus/integrations/reads/etag.js +11 -0
- package/dist/plus/integrations/reads/etag.js.map +1 -1
- package/docs/integrations.md +39 -6
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pullRequest.utils.js","names":[],"sources":["../../../../git/src/utils/pullRequest.utils.ts"],"sourcesContent":["import type {\n\tPullRequest,\n\tPullRequestComparisonRefs,\n\tPullRequestRefs,\n\tPullRequestRepositoryIdentityDescriptor,\n\tPullRequestShape,\n\tPullRequestSortField,\n\tPullRequestSorting,\n\tPullRequestStackInfo,\n} from '../models/pullRequest.js';\nimport { serializeMilestone } from './issueOrPullRequest.utils.js';\nimport { shortenRevision } from './revision.utils.js';\n\n/** How many pull requests a merge action affects — unstacked is always 1; a stacked merge lands either\n * just this layer and everything below it (`position`), or the whole stack (`wholeStack`). The one\n * source every merge-confirmation and merge-action label counts from, so they can't drift apart.\n * Takes only the two fields it needs (not the full {@link PullRequestStackInfo}) since callers on the\n * webview side carry narrower serialized stack shapes. */\nexport function getStackedMergeCount(\n\tstack: Pick<PullRequestStackInfo, 'position' | 'size'> | undefined,\n\toptions?: { wholeStack?: boolean },\n): number {\n\tif (stack == null) return 1;\n\treturn options?.wholeStack ? stack.size : stack.position;\n}\n\n/**\n * How each sort field is read off a {@link PullRequestShape}, for the filtered PR search, which MERGES its\n * relationship × state facets in the facade and so has to order the union itself instead of trusting the\n * per-facet server order. Only the fields the shape carries appear — the same rule as `getIssueComparator`, and\n * the reason {@link PullRequestSortField} is just these two.\n */\nconst pullRequestSortValues: Partial<\n\tRecord<PullRequestSortField, (pr: PullRequestShape) => number | Date | string | undefined>\n> = {\n\tcreated: pr => pr.createdDate,\n\tupdated: pr => pr.updatedDate,\n};\n\n/**\n * A comparator for one sort key over normalized pull requests, or `undefined` when the field isn't derivable\n * from a {@link PullRequestShape} — the signal that the key is only honorable on a SINGLE-origin read where the\n * provider already ordered the page. Missing values sort LAST in both directions (partitioned before any\n * arithmetic so two missing values compare equal, exactly as `getIssueComparator` does).\n *\n * Note it orders whatever it is handed. Sorting a page already capped at the result ceiling does not make it the\n * top N.\n */\nexport function getPullRequestComparator(\n\tsort: PullRequestSorting,\n): ((a: PullRequestShape, b: PullRequestShape) => number) | undefined {\n\tconst [field, direction] = sort.split(':') as [PullRequestSortField, 'asc' | 'desc'];\n\tconst getValue = pullRequestSortValues[field];\n\tif (getValue == null) return undefined;\n\n\treturn (a, b) => {\n\t\tconst left = toComparable(getValue(a));\n\t\tconst right = toComparable(getValue(b));\n\t\tif (left == null || right == null) {\n\t\t\tif (left == null && right == null) return 0;\n\n\t\t\treturn left == null ? 1 : -1;\n\t\t}\n\n\t\tconst ordered = left < right ? -1 : left > right ? 1 : 0;\n\t\treturn direction === 'asc' ? ordered : -ordered;\n\t};\n}\n\nfunction toComparable(value: number | Date | string | undefined): number | string | undefined {\n\treturn value instanceof Date ? value.getTime() : value;\n}\n\nexport interface PullRequestUrlIdentity<TProvider extends string = string> {\n\tprovider?: TProvider;\n\n\townerAndRepo?: string;\n\tprNumber: string;\n}\n\nexport function getComparisonRefsForPullRequest(repoPath: string, prRefs: PullRequestRefs): PullRequestComparisonRefs {\n\tconst refs: PullRequestComparisonRefs = {\n\t\trepoPath: repoPath,\n\t\tbase: { ref: prRefs.base.sha, label: `${prRefs.base.branch} (${shortenRevision(prRefs.base.sha)})` },\n\t\thead: { ref: prRefs.head.sha, label: prRefs.head.branch },\n\t};\n\treturn refs;\n}\n\nexport function getPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {\n\tlet prNumber: string | undefined = undefined;\n\n\tlet match = search.match(/(?:\\/)(\\d+)/); // any number starting with \"/\"\n\tif (match != null) {\n\t\tprNumber = match[1];\n\t}\n\n\tif (prNumber == null) {\n\t\tmatch = search.match(/^#?(\\d+)$/); // just a number or with a leading \"#\"\n\t\tif (match != null) {\n\t\t\tprNumber = match[1];\n\t\t}\n\t}\n\n\treturn prNumber == null ? undefined : { ownerAndRepo: undefined, prNumber: prNumber, provider: undefined };\n}\n\n/** A pull request's display number from its url, or `undefined` for a url naming no pull request. Anchors\n * on the provider's pull request path segment (GitHub `pull`, Bitbucket `pull-requests`, GitLab\n * `merge_requests`, Azure `pullrequest`) so a digit-leading owner (`github.com/1Password/x/pull/123`)\n * can't win. */\nexport function getPullRequestNumberFromUrl(url: string): string | undefined {\n\t// No loose fallback: `getPullRequestIdentityFromMaybeUrl` scans for any `/<digits>`, which reads a bare\n\t// repository url like `github.com/1Password/sdk` as pull request #1. Callers that hold a real pull\n\t// request fall back to its id instead, and the one that asks whether a pasted url names a pull request\n\t// needs \"no\" for an answer.\n\treturn url.match(/(?:pull|pull-requests|merge_requests|pullrequest)\\/(\\d+)(?:\\b|\\/|$)/)?.[1];\n}\n\nexport function getRepositoryIdentityForPullRequest(\n\tpr: PullRequest,\n\theadRepo: boolean = true,\n): PullRequestRepositoryIdentityDescriptor {\n\tif (headRepo) {\n\t\treturn {\n\t\t\tremote: {\n\t\t\t\turl: pr.refs?.head?.url,\n\t\t\t\tdomain: pr.provider.domain,\n\t\t\t},\n\t\t\tname: `${pr.refs?.head?.owner ?? pr.repository.owner}/${pr.refs?.head?.repo ?? pr.repository.repo}`,\n\t\t\tprovider: {\n\t\t\t\tid: pr.provider.id,\n\t\t\t\tdomain: pr.provider.domain,\n\t\t\t\trepoDomain: pr.refs?.head?.owner ?? pr.repository.owner,\n\t\t\t\trepoName: pr.refs?.head?.repo ?? pr.repository.repo,\n\t\t\t},\n\t\t};\n\t}\n\n\treturn {\n\t\tremote: {\n\t\t\turl: pr.refs?.base?.url ?? pr.url,\n\t\t\tdomain: pr.provider.domain,\n\t\t},\n\t\tname: `${pr.refs?.base?.owner ?? pr.repository.owner}/${pr.refs?.base?.repo ?? pr.repository.repo}`,\n\t\tprovider: {\n\t\t\tid: pr.provider.id,\n\t\t\tdomain: pr.provider.domain,\n\t\t\trepoDomain: pr.refs?.base?.owner ?? pr.repository.owner,\n\t\t\trepoName: pr.refs?.base?.repo ?? pr.repository.repo,\n\t\t\trepoOwnerDomain: pr.refs?.base?.owner ?? pr.repository.owner,\n\t\t},\n\t};\n}\n\nexport function isMaybeNonSpecificPullRequestSearchUrl(search: string): boolean {\n\treturn getPullRequestIdentityFromMaybeUrl(search) != null;\n}\n\n/**\n * Deliberately leaves `projection` out: this copy drops `filesChanged`, `repository` and the class-only check rollup,\n * commit count and `viewerCanUpdate`, so a tag would have field presence report as fetched what the copy no longer has.\n */\nexport function serializePullRequest(value: PullRequest): PullRequestShape {\n\tconst serialized: PullRequestShape = {\n\t\ttype: value.type,\n\t\tprovider: {\n\t\t\tid: value.provider.id,\n\t\t\tname: value.provider.name,\n\t\t\tdomain: value.provider.domain,\n\t\t\ticon: value.provider.icon,\n\t\t},\n\t\tid: value.id,\n\t\tnodeId: value.nodeId,\n\t\tnumber: value.number,\n\t\ttitle: value.title,\n\t\tbody: value.body,\n\t\turl: value.url,\n\t\tcreatedDate: value.createdDate,\n\t\tupdatedDate: value.updatedDate,\n\t\tclosedDate: value.closedDate,\n\t\tclosed: value.closed,\n\t\tauthor: {\n\t\t\tid: value.author.id,\n\t\t\tname: value.author.name,\n\t\t\tusername: value.author.username,\n\t\t\tavatarUrl: value.author.avatarUrl,\n\t\t\turl: value.author.url,\n\t\t},\n\t\tstate: value.state,\n\t\tmergedDate: value.mergedDate,\n\t\tmergeableState: value.mergeableState,\n\t\trefs: value.refs\n\t\t\t? {\n\t\t\t\t\thead: {\n\t\t\t\t\t\texists: value.refs.head.exists,\n\t\t\t\t\t\towner: value.refs.head.owner,\n\t\t\t\t\t\trepo: value.refs.head.repo,\n\t\t\t\t\t\tsha: value.refs.head.sha,\n\t\t\t\t\t\tbranch: value.refs.head.branch,\n\t\t\t\t\t\turl: value.refs.head.url,\n\t\t\t\t\t\tcloneHttps: value.refs.head.cloneHttps,\n\t\t\t\t\t\tcloneSsh: value.refs.head.cloneSsh,\n\t\t\t\t\t\tisFork: value.refs.head.isFork,\n\t\t\t\t\t},\n\t\t\t\t\tbase: {\n\t\t\t\t\t\texists: value.refs.base.exists,\n\t\t\t\t\t\towner: value.refs.base.owner,\n\t\t\t\t\t\trepo: value.refs.base.repo,\n\t\t\t\t\t\tsha: value.refs.base.sha,\n\t\t\t\t\t\tbranch: value.refs.base.branch,\n\t\t\t\t\t\turl: value.refs.base.url,\n\t\t\t\t\t\tcloneHttps: value.refs.base.cloneHttps,\n\t\t\t\t\t\tcloneSsh: value.refs.base.cloneSsh,\n\t\t\t\t\t\tisFork: value.refs.base.isFork,\n\t\t\t\t\t},\n\t\t\t\t\tisCrossRepository: value.refs.isCrossRepository,\n\t\t\t\t}\n\t\t\t: undefined,\n\t\tisDraft: value.isDraft,\n\t\tadditions: value.additions,\n\t\tdeletions: value.deletions,\n\t\tcommentsCount: value.commentsCount,\n\t\tthumbsUpCount: value.thumbsUpCount,\n\t\treviewDecision: value.reviewDecision,\n\t\treviewRequests: value.reviewRequests,\n\t\tlatestReviews: value.latestReviews,\n\t\tassignees: value.assignees,\n\t\tauthoredByMe: value.authoredByMe,\n\t\tviewer: value.viewer != null ? { id: value.viewer.id, username: value.viewer.username } : undefined,\n\t\tviewerUnresolved: value.viewerUnresolved,\n\t\tmilestone: serializeMilestone(value.milestone),\n\t\tproject: value.project\n\t\t\t? {\n\t\t\t\t\tid: value.project.id,\n\t\t\t\t\tname: value.project.name,\n\t\t\t\t\tresourceId: value.project.resourceId,\n\t\t\t\t\tresourceName: value.project.resourceName,\n\t\t\t\t}\n\t\t\t: undefined,\n\t\tstack: value.stack\n\t\t\t? {\n\t\t\t\t\tid: value.stack.id,\n\t\t\t\t\tnumber: value.stack.number,\n\t\t\t\t\tsize: value.stack.size,\n\t\t\t\t\tposition: value.stack.position,\n\t\t\t\t\tbaseRef: value.stack.baseRef,\n\t\t\t\t}\n\t\t\t: undefined,\n\t};\n\treturn serialized;\n}\n"],"mappings":";;;;;;;;AAkBA,SAAgB,qBACf,OACA,SACS;CACT,IAAI,SAAS,MAAM,OAAO;CAC1B,OAAO,SAAS,aAAa,MAAM,OAAO,MAAM;AACjD;;;;;;;AAQA,MAAM,wBAEF;CACH,UAAS,OAAM,GAAG;CAClB,UAAS,OAAM,GAAG;AACnB;;;;;;;;;;AAWA,SAAgB,yBACf,MACqE;CACrE,MAAM,CAAC,OAAO,aAAa,KAAK,MAAM,GAAG;CACzC,MAAM,WAAW,sBAAsB;CACvC,IAAI,YAAY,MAAM,OAAO,KAAA;CAE7B,QAAQ,GAAG,MAAM;EAChB,MAAM,OAAO,aAAa,SAAS,CAAC,CAAC;EACrC,MAAM,QAAQ,aAAa,SAAS,CAAC,CAAC;EACtC,IAAI,QAAQ,QAAQ,SAAS,MAAM;GAClC,IAAI,QAAQ,QAAQ,SAAS,MAAM,OAAO;GAE1C,OAAO,QAAQ,OAAO,IAAI;EAC3B;EAEA,MAAM,UAAU,OAAO,QAAQ,KAAK,OAAO,QAAQ,IAAI;EACvD,OAAO,cAAc,QAAQ,UAAU,CAAC;CACzC;AACD;AAEA,SAAS,aAAa,OAAwE;CAC7F,OAAO,iBAAiB,OAAO,MAAM,QAAQ,IAAI;AAClD;AASA,SAAgB,gCAAgC,UAAkB,QAAoD;CAMrH,OAAO;EAJI;EACV,MAAM;GAAE,KAAK,OAAO,KAAK;GAAK,OAAO,GAAG,OAAO,KAAK,OAAO,IAAI,gBAAgB,OAAO,KAAK,GAAG,EAAE;EAAG;EACnG,MAAM;GAAE,KAAK,OAAO,KAAK;GAAK,OAAO,OAAO,KAAK;EAAO;CAE/C;AACX;AAEA,SAAgB,mCAAmC,QAAoD;CACt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IACC,KAAA;EACH,SAAS,MAAM;EACf,WAAW,MAAM;EACjB,WAAW,MAAM;EACjB,eAAe,MAAM;EACrB,eAAe,MAAM;EACrB,gBAAgB,MAAM;EACtB,gBAAgB,MAAM;EACtB,eAAe,MAAM;EACrB,WAAW,MAAM;EACjB,cAAc,MAAM;EACpB,QAAQ,MAAM,UAAU,OAAO;GAAE,IAAI,MAAM,OAAO;GAAI,UAAU,MAAM,OAAO;EAAS,IAAI,KAAA;EAC1F,kBAAkB,MAAM;EACxB,WAAW,mBAAmB,MAAM,SAAS;EAC7C,SAAS,MAAM,UACZ;GACA,IAAI,MAAM,QAAQ;GAClB,MAAM,MAAM,QAAQ;GACpB,YAAY,MAAM,QAAQ;GAC1B,cAAc,MAAM,QAAQ;EAC7B,IACC,KAAA;EACH,OAAO,MAAM,QACV;GACA,IAAI,MAAM,MAAM;GAChB,QAAQ,MAAM,MAAM;GACpB,MAAM,MAAM,MAAM;GAClB,UAAU,MAAM,MAAM;GACtB,SAAS,MAAM,MAAM;EACtB,IACC,KAAA;CAEY;AACjB"}
|
|
1
|
+
{"version":3,"file":"pullRequest.utils.js","names":[],"sources":["../../../../git/src/utils/pullRequest.utils.ts"],"sourcesContent":["import * as l10n from '@vscode/l10n';\nimport { fromNow } from '@gitlens/utils/date.js';\nimport type {\n\tPullRequest,\n\tPullRequestComparisonRefs,\n\tPullRequestMergeQueueEntry,\n\tPullRequestRefs,\n\tPullRequestRepositoryIdentityDescriptor,\n\tPullRequestShape,\n\tPullRequestSortField,\n\tPullRequestSorting,\n\tPullRequestStackInfo,\n} from '../models/pullRequest.js';\nimport { PullRequestMergeQueueState } from '../models/pullRequest.js';\nimport { serializeMilestone } from './issueOrPullRequest.utils.js';\nimport { shortenRevision } from './revision.utils.js';\n\n/** How many pull requests a merge action affects — unstacked is always 1; a stacked merge lands either\n * just this layer and everything below it (`position`), or the whole stack (`wholeStack`). The one\n * source every merge-confirmation and merge-action label counts from, so they can't drift apart.\n * Takes only the two fields it needs (not the full {@link PullRequestStackInfo}) since callers on the\n * webview side carry narrower serialized stack shapes. */\nexport function getStackedMergeCount(\n\tstack: Pick<PullRequestStackInfo, 'position' | 'size'> | undefined,\n\toptions?: { wholeStack?: boolean },\n): number {\n\tif (stack == null) return 1;\n\treturn options?.wholeStack ? stack.size : stack.position;\n}\n\n/** Whether an open pull request is waiting in a merge queue. `false` also when the read didn't fetch the queue —\n * check the row's `mergeQueue` field presence before treating that as \"not queued\". Narrows to the shape's own entry\n * type, since webview shapes carry a serialized one, or to {@link PullRequestMergeQueueEntry} for a shape that\n * doesn't declare one (an `IssueOrPullRequest` that is a pull request). */\nexport function isPullRequestInMergeQueue<T extends { readonly state?: string; readonly mergeQueue?: unknown }>(\n\tpr: T,\n): pr is T & {\n\treadonly mergeQueue: 'mergeQueue' extends keyof T ? NonNullable<T['mergeQueue']> : PullRequestMergeQueueEntry;\n} {\n\treturn pr.state === 'opened' && pr.mergeQueue != null;\n}\n\n/** A pull request's state as shown to users: its provider state, except an open pull request waiting in a merge queue is `queued`. */\nexport function getPullRequestDisplayState<S extends string | undefined>(pr: {\n\treadonly state: S;\n\treadonly mergeQueue?: unknown;\n}): S | 'queued' {\n\treturn isPullRequestInMergeQueue(pr) ? 'queued' : pr.state;\n}\n\n/** A pull request's {@link getPullRequestDisplayState display state} paired with its\n * {@link formatPullRequestMergeQueueStatus merge-queue status}, place in line included, which is set only while it's\n * queued — the pair a pull request chip renders. */\nexport function getPullRequestDisplayStatus<S extends string | undefined>(pr: {\n\treadonly state: S;\n\treadonly mergeQueue?: Parameters<typeof formatPullRequestMergeQueueStatus>[0];\n}): { status: S | 'queued'; queueStatus: string | undefined } {\n\treturn isPullRequestInMergeQueue(pr)\n\t\t? { status: 'queued', queueStatus: formatPullRequestMergeQueueStatus(pr.mergeQueue) }\n\t\t: { status: pr.state, queueStatus: undefined };\n}\n\n/**\n * Describes where a queued pull request stands in its merge queue, with its place in line when the provider gave one\n * (\"#2 in the merge queue, checks running\"). Merging and failing entries read the same with or without a place, since\n * the place no longer says anything there. Takes only the fields it reads, and the estimate as a date or a timestamp\n * (ms), since webview shapes carry a serialized entry.\n */\nexport function formatPullRequestMergeQueueStatus(entry: {\n\treadonly state: PullRequestMergeQueueState;\n\treadonly estimatedMergeAt?: Date | number;\n\treadonly position?: number;\n}): string {\n\tconst position = entry.position;\n\n\tlet status: string;\n\tswitch (entry.state) {\n\t\tcase PullRequestMergeQueueState.AwaitingChecks:\n\t\t\tstatus =\n\t\t\t\tposition != null\n\t\t\t\t\t? l10n.t('#{position} in the merge queue, checks running', { position: position })\n\t\t\t\t\t: l10n.t('Queued to merge, checks running');\n\t\t\tbreak;\n\t\tcase PullRequestMergeQueueState.Mergeable:\n\t\t\tstatus =\n\t\t\t\tposition != null\n\t\t\t\t\t? l10n.t('#{position} in the merge queue, next up', { position: position })\n\t\t\t\t\t: l10n.t('Queued to merge, next up');\n\t\t\tbreak;\n\t\tcase PullRequestMergeQueueState.Locked:\n\t\t\t// The merge is already in flight, so an estimate adds nothing\n\t\t\treturn l10n.t('Merging');\n\t\tcase PullRequestMergeQueueState.Unmergeable:\n\t\t\treturn l10n.t('Failing in the merge queue');\n\t\tdefault:\n\t\t\tstatus =\n\t\t\t\tposition != null\n\t\t\t\t\t? l10n.t('#{position} in the merge queue', { position: position })\n\t\t\t\t\t: l10n.t('Queued to merge');\n\t\t\tbreak;\n\t}\n\n\tif (entry.estimatedMergeAt == null) return status;\n\n\t// An estimate already past is wrong, not late news: \"estimated to merge 2 minutes ago\" would only mislead\n\tconst estimatedMergeAt = new Date(entry.estimatedMergeAt).getTime();\n\tif (Number.isNaN(estimatedMergeAt) || estimatedMergeAt <= Date.now()) return status;\n\n\treturn l10n.t('{0}, estimated to merge {1}', status, fromNow(estimatedMergeAt));\n}\n\n/** When a queued pull request joined its merge queue, as the clause that follows its\n * {@link formatPullRequestMergeQueueStatus status} — \"queued 3 hours ago\" — so a status that ends in an estimate\n * doesn't run straight into a bare date. */\nexport function formatPullRequestMergeQueueEnqueuedFromNow(entry: { readonly enqueuedAt: Date | number }): string {\n\treturn l10n.t('queued {0}', fromNow(entry.enqueuedAt));\n}\n\n/** What a `PullRequestMergeQueueRemoval`'s reason says about the pull request: its queue run `failed`, someone\n * removed it (`manual`), or a reason this doesn't recognize (`other`), which the removal's raw reason still names. */\nexport type PullRequestMergeQueueRemovalKind = 'failed' | 'manual' | 'other';\n\n/**\n * Classifies a merge-queue removal's provider reason. Only the reasons seen from GitHub are recognized —\n * `failed_checks` (its queue run failed) and `manual` — matched without regard to case; every other reason is\n * `other` rather than guessed at, so a caller that shows one can fall back to the raw reason.\n */\nexport function getPullRequestMergeQueueRemovalKind(reason: string): PullRequestMergeQueueRemovalKind {\n\tswitch (reason.toLowerCase()) {\n\t\tcase 'failed_checks':\n\t\t\treturn 'failed';\n\t\tcase 'manual':\n\t\t\treturn 'manual';\n\t\tdefault:\n\t\t\treturn 'other';\n\t}\n}\n\n/**\n * Whether a pull request's merge-queue removal (`mergeQueueRemoval`) still describes it: it is set,\n * the pull request is open and not queued, and nothing has touched the pull request since — its update time is no\n * later than the removal, which GitHub's removal doesn't move. Narrows `mergeQueueRemoval` to set.\n *\n * The trade-off: any later update clears it, not only a push that may have fixed the failure, so a comment or a\n * label added after a failed queue run also stops it reading as failing. A provider's timeline can't say whether a\n * push followed the removal (GitHub orders commits by commit date, not push time), and a stale \"failing\" is worse\n * than a missed one. Takes dates or timestamps (ms), since webview shapes carry serialized ones.\n */\nexport function isPullRequestMergeQueueRemovalCurrent<\n\tT extends {\n\t\treadonly state?: string;\n\t\treadonly updatedDate: Date | number;\n\t\treadonly mergeQueue?: unknown;\n\t\treadonly mergeQueueRemoval?: { readonly removedAt: Date | number };\n\t},\n>(pr: T): pr is T & { readonly mergeQueueRemoval: NonNullable<T['mergeQueueRemoval']> } {\n\tif (pr.mergeQueueRemoval == null || pr.state !== 'opened' || pr.mergeQueue != null) return false;\n\n\tconst removedAt = new Date(pr.mergeQueueRemoval.removedAt).getTime();\n\tconst updatedAt = new Date(pr.updatedDate).getTime();\n\tif (Number.isNaN(removedAt) || Number.isNaN(updatedAt)) return false;\n\n\treturn removedAt >= updatedAt;\n}\n\n/**\n * How each sort field is read off a {@link PullRequestShape}, for the filtered PR search, which MERGES its\n * relationship × state facets in the facade and so has to order the union itself instead of trusting the\n * per-facet server order. Only the fields the shape carries appear — the same rule as `getIssueComparator`, and\n * the reason {@link PullRequestSortField} is just these two.\n */\nconst pullRequestSortValues: Partial<\n\tRecord<PullRequestSortField, (pr: PullRequestShape) => number | Date | string | undefined>\n> = {\n\tcreated: pr => pr.createdDate,\n\tupdated: pr => pr.updatedDate,\n};\n\n/**\n * A comparator for one sort key over normalized pull requests, or `undefined` when the field isn't derivable\n * from a {@link PullRequestShape} — the signal that the key is only honorable on a SINGLE-origin read where the\n * provider already ordered the page. Missing values sort LAST in both directions (partitioned before any\n * arithmetic so two missing values compare equal, exactly as `getIssueComparator` does).\n *\n * Note it orders whatever it is handed. Sorting a page already capped at the result ceiling does not make it the\n * top N.\n */\nexport function getPullRequestComparator(\n\tsort: PullRequestSorting,\n): ((a: PullRequestShape, b: PullRequestShape) => number) | undefined {\n\tconst [field, direction] = sort.split(':') as [PullRequestSortField, 'asc' | 'desc'];\n\tconst getValue = pullRequestSortValues[field];\n\tif (getValue == null) return undefined;\n\n\treturn (a, b) => {\n\t\tconst left = toComparable(getValue(a));\n\t\tconst right = toComparable(getValue(b));\n\t\tif (left == null || right == null) {\n\t\t\tif (left == null && right == null) return 0;\n\n\t\t\treturn left == null ? 1 : -1;\n\t\t}\n\n\t\tconst ordered = left < right ? -1 : left > right ? 1 : 0;\n\t\treturn direction === 'asc' ? ordered : -ordered;\n\t};\n}\n\nfunction toComparable(value: number | Date | string | undefined): number | string | undefined {\n\treturn value instanceof Date ? value.getTime() : value;\n}\n\nexport interface PullRequestUrlIdentity<TProvider extends string = string> {\n\tprovider?: TProvider;\n\n\townerAndRepo?: string;\n\tprNumber: string;\n}\n\nexport function getComparisonRefsForPullRequest(repoPath: string, prRefs: PullRequestRefs): PullRequestComparisonRefs {\n\tconst refs: PullRequestComparisonRefs = {\n\t\trepoPath: repoPath,\n\t\tbase: { ref: prRefs.base.sha, label: `${prRefs.base.branch} (${shortenRevision(prRefs.base.sha)})` },\n\t\thead: { ref: prRefs.head.sha, label: prRefs.head.branch },\n\t};\n\treturn refs;\n}\n\nexport function getPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {\n\tlet prNumber: string | undefined = undefined;\n\n\tlet match = search.match(/(?:\\/)(\\d+)/); // any number starting with \"/\"\n\tif (match != null) {\n\t\tprNumber = match[1];\n\t}\n\n\tif (prNumber == null) {\n\t\tmatch = search.match(/^#?(\\d+)$/); // just a number or with a leading \"#\"\n\t\tif (match != null) {\n\t\t\tprNumber = match[1];\n\t\t}\n\t}\n\n\treturn prNumber == null ? undefined : { ownerAndRepo: undefined, prNumber: prNumber, provider: undefined };\n}\n\n/** A pull request's display number from its url, or `undefined` for a url naming no pull request. Anchors\n * on the provider's pull request path segment (GitHub `pull`, Bitbucket `pull-requests`, GitLab\n * `merge_requests`, Azure `pullrequest`) so a digit-leading owner (`github.com/1Password/x/pull/123`)\n * can't win. */\nexport function getPullRequestNumberFromUrl(url: string): string | undefined {\n\t// No loose fallback: `getPullRequestIdentityFromMaybeUrl` scans for any `/<digits>`, which reads a bare\n\t// repository url like `github.com/1Password/sdk` as pull request #1. Callers that hold a real pull\n\t// request fall back to its id instead, and the one that asks whether a pasted url names a pull request\n\t// needs \"no\" for an answer.\n\treturn url.match(/(?:pull|pull-requests|merge_requests|pullrequest)\\/(\\d+)(?:\\b|\\/|$)/)?.[1];\n}\n\nexport function getRepositoryIdentityForPullRequest(\n\tpr: PullRequest,\n\theadRepo: boolean = true,\n): PullRequestRepositoryIdentityDescriptor {\n\tif (headRepo) {\n\t\treturn {\n\t\t\tremote: {\n\t\t\t\turl: pr.refs?.head?.url,\n\t\t\t\tdomain: pr.provider.domain,\n\t\t\t},\n\t\t\tname: `${pr.refs?.head?.owner ?? pr.repository.owner}/${pr.refs?.head?.repo ?? pr.repository.repo}`,\n\t\t\tprovider: {\n\t\t\t\tid: pr.provider.id,\n\t\t\t\tdomain: pr.provider.domain,\n\t\t\t\trepoDomain: pr.refs?.head?.owner ?? pr.repository.owner,\n\t\t\t\trepoName: pr.refs?.head?.repo ?? pr.repository.repo,\n\t\t\t},\n\t\t};\n\t}\n\n\treturn {\n\t\tremote: {\n\t\t\turl: pr.refs?.base?.url ?? pr.url,\n\t\t\tdomain: pr.provider.domain,\n\t\t},\n\t\tname: `${pr.refs?.base?.owner ?? pr.repository.owner}/${pr.refs?.base?.repo ?? pr.repository.repo}`,\n\t\tprovider: {\n\t\t\tid: pr.provider.id,\n\t\t\tdomain: pr.provider.domain,\n\t\t\trepoDomain: pr.refs?.base?.owner ?? pr.repository.owner,\n\t\t\trepoName: pr.refs?.base?.repo ?? pr.repository.repo,\n\t\t\trepoOwnerDomain: pr.refs?.base?.owner ?? pr.repository.owner,\n\t\t},\n\t};\n}\n\nexport function isMaybeNonSpecificPullRequestSearchUrl(search: string): boolean {\n\treturn getPullRequestIdentityFromMaybeUrl(search) != null;\n}\n\n/**\n * Deliberately leaves `projection` out: this copy drops `filesChanged`, `repository` and the class-only check rollup,\n * commit count and `viewerCanUpdate`, so a tag would have field presence report as fetched what the copy no longer has.\n */\nexport function serializePullRequest(value: PullRequest): PullRequestShape {\n\tconst serialized: PullRequestShape = {\n\t\ttype: value.type,\n\t\tprovider: {\n\t\t\tid: value.provider.id,\n\t\t\tname: value.provider.name,\n\t\t\tdomain: value.provider.domain,\n\t\t\ticon: value.provider.icon,\n\t\t},\n\t\tid: value.id,\n\t\tnodeId: value.nodeId,\n\t\tnumber: value.number,\n\t\ttitle: value.title,\n\t\tbody: value.body,\n\t\turl: value.url,\n\t\tcreatedDate: value.createdDate,\n\t\tupdatedDate: value.updatedDate,\n\t\tclosedDate: value.closedDate,\n\t\tclosed: value.closed,\n\t\tauthor: {\n\t\t\tid: value.author.id,\n\t\t\tname: value.author.name,\n\t\t\tusername: value.author.username,\n\t\t\tavatarUrl: value.author.avatarUrl,\n\t\t\turl: value.author.url,\n\t\t},\n\t\tstate: value.state,\n\t\tmergedDate: value.mergedDate,\n\t\tmergeableState: value.mergeableState,\n\t\trefs: value.refs\n\t\t\t? {\n\t\t\t\t\thead: {\n\t\t\t\t\t\texists: value.refs.head.exists,\n\t\t\t\t\t\towner: value.refs.head.owner,\n\t\t\t\t\t\trepo: value.refs.head.repo,\n\t\t\t\t\t\tsha: value.refs.head.sha,\n\t\t\t\t\t\tbranch: value.refs.head.branch,\n\t\t\t\t\t\turl: value.refs.head.url,\n\t\t\t\t\t\tcloneHttps: value.refs.head.cloneHttps,\n\t\t\t\t\t\tcloneSsh: value.refs.head.cloneSsh,\n\t\t\t\t\t\tisFork: value.refs.head.isFork,\n\t\t\t\t\t},\n\t\t\t\t\tbase: {\n\t\t\t\t\t\texists: value.refs.base.exists,\n\t\t\t\t\t\towner: value.refs.base.owner,\n\t\t\t\t\t\trepo: value.refs.base.repo,\n\t\t\t\t\t\tsha: value.refs.base.sha,\n\t\t\t\t\t\tbranch: value.refs.base.branch,\n\t\t\t\t\t\turl: value.refs.base.url,\n\t\t\t\t\t\tcloneHttps: value.refs.base.cloneHttps,\n\t\t\t\t\t\tcloneSsh: value.refs.base.cloneSsh,\n\t\t\t\t\t\tisFork: value.refs.base.isFork,\n\t\t\t\t\t},\n\t\t\t\t\tisCrossRepository: value.refs.isCrossRepository,\n\t\t\t\t}\n\t\t\t: undefined,\n\t\tisDraft: value.isDraft,\n\t\tadditions: value.additions,\n\t\tdeletions: value.deletions,\n\t\tcommentsCount: value.commentsCount,\n\t\tthumbsUpCount: value.thumbsUpCount,\n\t\treviewDecision: value.reviewDecision,\n\t\treviewRequests: value.reviewRequests,\n\t\tlatestReviews: value.latestReviews,\n\t\tassignees: value.assignees,\n\t\tauthoredByMe: value.authoredByMe,\n\t\tviewer: value.viewer != null ? { id: value.viewer.id, username: value.viewer.username } : undefined,\n\t\tviewerUnresolved: value.viewerUnresolved,\n\t\tmilestone: serializeMilestone(value.milestone),\n\t\tproject: value.project\n\t\t\t? {\n\t\t\t\t\tid: value.project.id,\n\t\t\t\t\tname: value.project.name,\n\t\t\t\t\tresourceId: value.project.resourceId,\n\t\t\t\t\tresourceName: value.project.resourceName,\n\t\t\t\t}\n\t\t\t: undefined,\n\t\tstack: value.stack\n\t\t\t? {\n\t\t\t\t\tid: value.stack.id,\n\t\t\t\t\tnumber: value.stack.number,\n\t\t\t\t\tsize: value.stack.size,\n\t\t\t\t\tposition: value.stack.position,\n\t\t\t\t\tbaseRef: value.stack.baseRef,\n\t\t\t\t}\n\t\t\t: undefined,\n\t\tmergeQueue: value.mergeQueue\n\t\t\t? {\n\t\t\t\t\tstate: value.mergeQueue.state,\n\t\t\t\t\tenqueuedAt: value.mergeQueue.enqueuedAt,\n\t\t\t\t\testimatedMergeAt: value.mergeQueue.estimatedMergeAt,\n\t\t\t\t\turl: value.mergeQueue.url,\n\t\t\t\t\tposition: value.mergeQueue.position,\n\t\t\t\t}\n\t\t\t: undefined,\n\t\tmergeQueueRequired: value.mergeQueueRequired,\n\t\tmergeQueueRemoval: value.mergeQueueRemoval\n\t\t\t? { reason: value.mergeQueueRemoval.reason, removedAt: value.mergeQueueRemoval.removedAt }\n\t\t\t: undefined,\n\t};\n\treturn serialized;\n}\n"],"mappings":";;;;;;;;;;;AAsBA,SAAgB,qBACf,OACA,SACS;CACT,IAAI,SAAS,MAAM,OAAO;CAC1B,OAAO,SAAS,aAAa,MAAM,OAAO,MAAM;AACjD;;;;;AAMA,SAAgB,0BACf,IAGC;CACD,OAAO,GAAG,UAAU,YAAY,GAAG,cAAc;AAClD;;AAGA,SAAgB,2BAAyD,IAGxD;CAChB,OAAO,0BAA0B,EAAE,IAAI,WAAW,GAAG;AACtD;;;;AAKA,SAAgB,4BAA0D,IAGZ;CAC7D,OAAO,0BAA0B,EAAE,IAChC;EAA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gBAAgB,MAAM;EACtB,eAAe,MAAM;EACrB,WAAW,MAAM;EACjB,cAAc,MAAM;EACpB,QAAQ,MAAM,UAAU,OAAO;GAAE,IAAI,MAAM,OAAO;GAAI,UAAU,MAAM,OAAO;EAAS,IAAI,KAAA;EAC1F,kBAAkB,MAAM;EACxB,WAAW,mBAAmB,MAAM,SAAS;EAC7C,SAAS,MAAM,UACZ;GACA,IAAI,MAAM,QAAQ;GAClB,MAAM,MAAM,QAAQ;GACpB,YAAY,MAAM,QAAQ;GAC1B,cAAc,MAAM,QAAQ;EAC7B,IACC,KAAA;EACH,OAAO,MAAM,QACV;GACA,IAAI,MAAM,MAAM;GAChB,QAAQ,MAAM,MAAM;GACpB,MAAM,MAAM,MAAM;GAClB,UAAU,MAAM,MAAM;GACtB,SAAS,MAAM,MAAM;EACtB,IACC,KAAA;EACH,YAAY,MAAM,aACf;GACA,OAAO,MAAM,WAAW;GACxB,YAAY,MAAM,WAAW;GAC7B,kBAAkB,MAAM,WAAW;GACnC,KAAK,MAAM,WAAW;GACtB,UAAU,MAAM,WAAW;EAC5B,IACC,KAAA;EACH,oBAAoB,MAAM;EAC1B,mBAAmB,MAAM,oBACtB;GAAE,QAAQ,MAAM,kBAAkB;GAAQ,WAAW,MAAM,kBAAkB;EAAU,IACvF,KAAA;CAEY;AACjB"}
|
|
@@ -13,5 +13,11 @@ export declare function parseWorktreeAdminPath(relativePath: string): {
|
|
|
13
13
|
} | undefined;
|
|
14
14
|
/** The admin id of the linked worktree whose git dir is `gitDirPath`: the `<id>` of `<commonGitDirPath>/worktrees/<id>` */
|
|
15
15
|
export declare function getWorktreeAdminId(gitDirPath: string, commonGitDirPath: string): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the linked worktree whose admin entry is `adminDir` lies under one of `ignoredRoots` (see
|
|
18
|
+
* `GitProvider.getIgnoredWorktreeRoots`), from the content of the entry's `gitdir` file; `undefined` when that names no
|
|
19
|
+
* worktree's `.git`, as when it couldn't be read
|
|
20
|
+
*/
|
|
21
|
+
export declare function isIgnoredWorktreeEntry(adminDir: string, gitdir: Uint8Array | undefined, ignoredRoots: readonly string[]): boolean | undefined;
|
|
16
22
|
//#endregion
|
|
17
23
|
//# sourceMappingURL=repository.utils.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isDescendant, normalizePath, relative } from "../../utils/path.js";
|
|
1
|
+
import { dirname, isAbsolute, isDescendant, joinPaths, normalizePath, relative } from "../../utils/path.js";
|
|
2
2
|
//#region ../git/src/utils/repository.utils.ts
|
|
3
3
|
function getRepositoryOrWorktreePath(uri) {
|
|
4
4
|
return uri.scheme === "file" ? normalizePath(uri.fsPath) : uri.toString();
|
|
@@ -33,7 +33,19 @@ function getWorktreeAdminId(gitDirPath, commonGitDirPath) {
|
|
|
33
33
|
const entry = parseWorktreeAdminPath(relative(commonGitDirPath, gitDirPath));
|
|
34
34
|
return entry != null && entry.file == null ? entry.id : void 0;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Whether the linked worktree whose admin entry is `adminDir` lies under one of `ignoredRoots` (see
|
|
38
|
+
* `GitProvider.getIgnoredWorktreeRoots`), from the content of the entry's `gitdir` file; `undefined` when that names no
|
|
39
|
+
* worktree's `.git`, as when it couldn't be read
|
|
40
|
+
*/
|
|
41
|
+
function isIgnoredWorktreeEntry(adminDir, gitdir, ignoredRoots) {
|
|
42
|
+
const dotGit = gitdir != null ? new TextDecoder().decode(gitdir).trim() : "";
|
|
43
|
+
const dotGitPath = dotGit ? normalizePath(isAbsolute(dotGit) ? dotGit : joinPaths(adminDir, dotGit)) : "";
|
|
44
|
+
if (!dotGitPath.endsWith("/.git")) return void 0;
|
|
45
|
+
const worktreePath = dirname(dotGitPath);
|
|
46
|
+
return ignoredRoots.some((root) => isDescendant(worktreePath, root));
|
|
47
|
+
}
|
|
36
48
|
//#endregion
|
|
37
|
-
export { getCommonRepositoryPath, getCommonRepositoryUri, getRepositoryOrWorktreePath, getWorktreeAdminId, parseWorktreeAdminPath };
|
|
49
|
+
export { getCommonRepositoryPath, getCommonRepositoryUri, getRepositoryOrWorktreePath, getWorktreeAdminId, isIgnoredWorktreeEntry, parseWorktreeAdminPath };
|
|
38
50
|
|
|
39
51
|
//# sourceMappingURL=repository.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.utils.js","names":[],"sources":["../../../../git/src/utils/repository.utils.ts"],"sourcesContent":["import { isDescendant, normalizePath, relative } from '@gitlens/utils/path.js';\nimport type { Uri } from '@gitlens/utils/uri.js';\n\nexport function getRepositoryOrWorktreePath(uri: Uri): string {\n\treturn uri.scheme === 'file' ? normalizePath(uri.fsPath) : uri.toString();\n}\n\nexport function getCommonRepositoryPath(commonUri: Uri): string {\n\tconst uri = getCommonRepositoryUri(commonUri);\n\treturn getRepositoryOrWorktreePath(uri);\n}\n\nexport function getCommonRepositoryUri(commonUri: Uri): Uri {\n\tif (commonUri?.path.endsWith('/.git')) {\n\t\treturn commonUri.with({ path: commonUri.path.substring(0, commonUri.path.length - 5) });\n\t}\n\treturn commonUri;\n}\n\n/**\n * A path relative to the common `.git` directory that is a linked worktree's admin entry, `worktrees/<id>`, or a file\n * in it: its admin id, and the file's path within the entry (`undefined` for the entry itself)\n */\nexport function parseWorktreeAdminPath(\n\trelativePath: string,\n): { readonly id: string; readonly file: string | undefined } | undefined {\n\tif (relativePath.length <= 10 || !relativePath.startsWith('worktrees/')) return undefined;\n\n\tconst idEnd = relativePath.indexOf('/', 10);\n\tif (idEnd === -1) return { id: relativePath.substring(10), file: undefined };\n\tif (idEnd === 10) return undefined;\n\n\treturn { id: relativePath.substring(10, idEnd), file: relativePath.substring(idEnd + 1) };\n}\n\n/** The admin id of the linked worktree whose git dir is `gitDirPath`: the `<id>` of `<commonGitDirPath>/worktrees/<id>` */\nexport function getWorktreeAdminId(gitDirPath: string, commonGitDirPath: string): string | undefined {\n\tif (!isDescendant(gitDirPath, commonGitDirPath)) return undefined;\n\n\tconst entry = parseWorktreeAdminPath(relative(commonGitDirPath, gitDirPath));\n\treturn entry != null && entry.file == null ? entry.id : undefined;\n}\n"],"mappings":";;AAGA,SAAgB,4BAA4B,KAAkB;CAC7D,OAAO,IAAI,WAAW,SAAS,cAAc,IAAI,MAAM,IAAI,IAAI,SAAS;AACzE;AAEA,SAAgB,wBAAwB,WAAwB;CAE/D,OAAO,4BADK,uBAAuB,SACE,CAAC;AACvC;AAEA,SAAgB,uBAAuB,WAAqB;CAC3D,IAAI,WAAW,KAAK,SAAS,OAAO,GACnC,OAAO,UAAU,KAAK,EAAE,MAAM,UAAU,KAAK,UAAU,GAAG,UAAU,KAAK,SAAS,CAAC,EAAE,CAAC;CAEvF,OAAO;AACR;;;;;AAMA,SAAgB,uBACf,cACyE;CACzE,IAAI,aAAa,UAAU,MAAM,CAAC,aAAa,WAAW,YAAY,GAAG,OAAO,KAAA;CAEhF,MAAM,QAAQ,aAAa,QAAQ,KAAK,EAAE;CAC1C,IAAI,UAAU,IAAI,OAAO;EAAE,IAAI,aAAa,UAAU,EAAE;EAAG,MAAM,KAAA;CAAU;CAC3E,IAAI,UAAU,IAAI,OAAO,KAAA;CAEzB,OAAO;EAAE,IAAI,aAAa,UAAU,IAAI,KAAK;EAAG,MAAM,aAAa,UAAU,QAAQ,CAAC;CAAE;AACzF;;AAGA,SAAgB,mBAAmB,YAAoB,kBAA8C;CACpG,IAAI,CAAC,aAAa,YAAY,gBAAgB,GAAG,OAAO,KAAA;CAExD,MAAM,QAAQ,uBAAuB,SAAS,kBAAkB,UAAU,CAAC;CAC3E,OAAO,SAAS,QAAQ,MAAM,QAAQ,OAAO,MAAM,KAAK,KAAA;AACzD"}
|
|
1
|
+
{"version":3,"file":"repository.utils.js","names":[],"sources":["../../../../git/src/utils/repository.utils.ts"],"sourcesContent":["import { dirname, isAbsolute, isDescendant, joinPaths, normalizePath, relative } from '@gitlens/utils/path.js';\nimport type { Uri } from '@gitlens/utils/uri.js';\n\nexport function getRepositoryOrWorktreePath(uri: Uri): string {\n\treturn uri.scheme === 'file' ? normalizePath(uri.fsPath) : uri.toString();\n}\n\nexport function getCommonRepositoryPath(commonUri: Uri): string {\n\tconst uri = getCommonRepositoryUri(commonUri);\n\treturn getRepositoryOrWorktreePath(uri);\n}\n\nexport function getCommonRepositoryUri(commonUri: Uri): Uri {\n\tif (commonUri?.path.endsWith('/.git')) {\n\t\treturn commonUri.with({ path: commonUri.path.substring(0, commonUri.path.length - 5) });\n\t}\n\treturn commonUri;\n}\n\n/**\n * A path relative to the common `.git` directory that is a linked worktree's admin entry, `worktrees/<id>`, or a file\n * in it: its admin id, and the file's path within the entry (`undefined` for the entry itself)\n */\nexport function parseWorktreeAdminPath(\n\trelativePath: string,\n): { readonly id: string; readonly file: string | undefined } | undefined {\n\tif (relativePath.length <= 10 || !relativePath.startsWith('worktrees/')) return undefined;\n\n\tconst idEnd = relativePath.indexOf('/', 10);\n\tif (idEnd === -1) return { id: relativePath.substring(10), file: undefined };\n\tif (idEnd === 10) return undefined;\n\n\treturn { id: relativePath.substring(10, idEnd), file: relativePath.substring(idEnd + 1) };\n}\n\n/** The admin id of the linked worktree whose git dir is `gitDirPath`: the `<id>` of `<commonGitDirPath>/worktrees/<id>` */\nexport function getWorktreeAdminId(gitDirPath: string, commonGitDirPath: string): string | undefined {\n\tif (!isDescendant(gitDirPath, commonGitDirPath)) return undefined;\n\n\tconst entry = parseWorktreeAdminPath(relative(commonGitDirPath, gitDirPath));\n\treturn entry != null && entry.file == null ? entry.id : undefined;\n}\n\n/**\n * Whether the linked worktree whose admin entry is `adminDir` lies under one of `ignoredRoots` (see\n * `GitProvider.getIgnoredWorktreeRoots`), from the content of the entry's `gitdir` file; `undefined` when that names no\n * worktree's `.git`, as when it couldn't be read\n */\nexport function isIgnoredWorktreeEntry(\n\tadminDir: string,\n\tgitdir: Uint8Array | undefined,\n\tignoredRoots: readonly string[],\n): boolean | undefined {\n\t// Git writes the path of the worktree's `.git` file, relative to the entry under `worktree.useRelativePaths`\n\tconst dotGit = gitdir != null ? new TextDecoder().decode(gitdir).trim() : '';\n\tconst dotGitPath = dotGit ? normalizePath(isAbsolute(dotGit) ? dotGit : joinPaths(adminDir, dotGit)) : '';\n\tif (!dotGitPath.endsWith('/.git')) return undefined;\n\n\tconst worktreePath = dirname(dotGitPath);\n\treturn ignoredRoots.some(root => isDescendant(worktreePath, root));\n}\n"],"mappings":";;AAGA,SAAgB,4BAA4B,KAAkB;CAC7D,OAAO,IAAI,WAAW,SAAS,cAAc,IAAI,MAAM,IAAI,IAAI,SAAS;AACzE;AAEA,SAAgB,wBAAwB,WAAwB;CAE/D,OAAO,4BADK,uBAAuB,SACE,CAAC;AACvC;AAEA,SAAgB,uBAAuB,WAAqB;CAC3D,IAAI,WAAW,KAAK,SAAS,OAAO,GACnC,OAAO,UAAU,KAAK,EAAE,MAAM,UAAU,KAAK,UAAU,GAAG,UAAU,KAAK,SAAS,CAAC,EAAE,CAAC;CAEvF,OAAO;AACR;;;;;AAMA,SAAgB,uBACf,cACyE;CACzE,IAAI,aAAa,UAAU,MAAM,CAAC,aAAa,WAAW,YAAY,GAAG,OAAO,KAAA;CAEhF,MAAM,QAAQ,aAAa,QAAQ,KAAK,EAAE;CAC1C,IAAI,UAAU,IAAI,OAAO;EAAE,IAAI,aAAa,UAAU,EAAE;EAAG,MAAM,KAAA;CAAU;CAC3E,IAAI,UAAU,IAAI,OAAO,KAAA;CAEzB,OAAO;EAAE,IAAI,aAAa,UAAU,IAAI,KAAK;EAAG,MAAM,aAAa,UAAU,QAAQ,CAAC;CAAE;AACzF;;AAGA,SAAgB,mBAAmB,YAAoB,kBAA8C;CACpG,IAAI,CAAC,aAAa,YAAY,gBAAgB,GAAG,OAAO,KAAA;CAExD,MAAM,QAAQ,uBAAuB,SAAS,kBAAkB,UAAU,CAAC;CAC3E,OAAO,SAAS,QAAQ,MAAM,QAAQ,OAAO,MAAM,KAAK,KAAA;AACzD;;;;;;AAOA,SAAgB,uBACf,UACA,QACA,cACsB;CAEtB,MAAM,SAAS,UAAU,OAAO,IAAI,YAAY,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,KAAK,IAAI;CAC1E,MAAM,aAAa,SAAS,cAAc,WAAW,MAAM,IAAI,SAAS,UAAU,UAAU,MAAM,CAAC,IAAI;CACvG,IAAI,CAAC,WAAW,SAAS,OAAO,GAAG,OAAO,KAAA;CAE1C,MAAM,eAAe,QAAQ,UAAU;CACvC,OAAO,aAAa,MAAK,SAAQ,aAAa,cAAc,IAAI,CAAC;AAClE"}
|
|
@@ -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
|
-
|
|
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
|
|
257
|
-
|
|
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,I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B,KAAK,MAAM,QAAQ,MAAM,UAAU,CAAC,MAAM,IAAI,GAC7C,KAAK,QAAQ;GAAE,MAAM,UAAU,KAAK,UAAU,IAAI;GAAG,QAAQ;EAAS,GAAG,KAAK;CAGjF;;;;;;CAOA,OAAO,MAAoB;EAC1B,IAAI,CAAC,aAAa,MAAM,KAAK,QAAQ,GAAG;EAExC,IAAI,eAAe,SAAS,KAAK,UAAU,IAAI;EAC/C,IAAI,aAAa,SAAS,OAAO,GAChC,eAAe,aAAa,UAAU,GAAG,aAAa,SAAS,CAAC;EAGjE,KAAK,IAAI,IAAI,cAAc,EAAE,SAAS,GAAG,IAAI,EAAE,UAAU,GAAG,KAAK,IAAI,GAAG,EAAE,YAAY,GAAG,CAAC,CAAC,GAC1F,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,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;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,GACxB,qBAAqB,KAAK,WAAW,CAAC;EAEvC,KAAK,WAAW;CACjB;CAEA,OAAO,QAA0B;EAChC,KAAK,OAAO,OAAO,MAAM;EACzB,IAAI,CAAC,KAAK,QAAQ,OAAO,MAAM,KAAK,KAAK,QAAQ,SAAS,GAAG;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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
|