@gitkraken/core-gitlens 0.68.0 → 0.70.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 (72) hide show
  1. package/CHANGELOG.md +29 -1
  2. package/dist/git/providers/diff.d.ts +10 -1
  3. package/dist/git/providers/status.d.ts +2 -0
  4. package/dist/git/service.d.ts +5 -1
  5. package/dist/git/service.js +8 -4
  6. package/dist/git/service.js.map +1 -1
  7. package/dist/git/watching/worktreeSummary.d.ts +9 -0
  8. package/dist/git/watching/worktreeSummary.js +17 -5
  9. package/dist/git/watching/worktreeSummary.js.map +1 -1
  10. package/dist/git-cli/cliGitProvider.d.ts +8 -1
  11. package/dist/git-cli/cliGitProvider.js +14 -3
  12. package/dist/git-cli/cliGitProvider.js.map +1 -1
  13. package/dist/git-cli/exec/exec.d.ts +2 -2
  14. package/dist/git-cli/exec/exec.js +2 -2
  15. package/dist/git-cli/exec/git.js +4 -3
  16. package/dist/git-cli/exec/git.js.map +1 -1
  17. package/dist/git-cli/exec/indexRefresh.d.ts +38 -6
  18. package/dist/git-cli/exec/indexRefresh.js +84 -3
  19. package/dist/git-cli/exec/indexRefresh.js.map +1 -1
  20. package/dist/git-cli/providers/diff.d.ts +4 -1
  21. package/dist/git-cli/providers/diff.js +17 -1
  22. package/dist/git-cli/providers/diff.js.map +1 -1
  23. package/dist/git-cli/providers/status.d.ts +4 -0
  24. package/dist/git-cli/providers/status.js +113 -16
  25. package/dist/git-cli/providers/status.js.map +1 -1
  26. package/dist/git-cli/service.d.ts +13 -1
  27. package/dist/git-cli/service.js +1 -0
  28. package/dist/git-cli/service.js.map +1 -1
  29. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +1 -1
  30. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -1
  31. package/dist/plus/integrations/index.d.ts +2 -1
  32. package/dist/plus/integrations/index.js +9 -0
  33. package/dist/plus/integrations/index.js.map +1 -1
  34. package/dist/plus/integrations/integrationService.d.ts +15 -0
  35. package/dist/plus/integrations/integrationService.js +35 -4
  36. package/dist/plus/integrations/integrationService.js.map +1 -1
  37. package/dist/plus/integrations/manager.d.ts +6 -0
  38. package/dist/plus/integrations/models/asanaTaskWrites.d.ts +155 -0
  39. package/dist/plus/integrations/models/asanaTaskWrites.js +0 -0
  40. package/dist/plus/integrations/models/issuesIntegration.d.ts +6 -1
  41. package/dist/plus/integrations/models/issuesIntegration.js +25 -0
  42. package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
  43. package/dist/plus/integrations/providers/asana.d.ts +3 -1
  44. package/dist/plus/integrations/providers/asana.js +10 -0
  45. package/dist/plus/integrations/providers/asana.js.map +1 -1
  46. package/dist/plus/integrations/providers/asanaTaskWriteTransport.d.ts +40 -0
  47. package/dist/plus/integrations/providers/asanaTaskWriteTransport.js +122 -0
  48. package/dist/plus/integrations/providers/asanaTaskWriteTransport.js.map +1 -0
  49. package/dist/plus/integrations/providers/asanaTaskWrites.d.ts +38 -0
  50. package/dist/plus/integrations/providers/asanaTaskWrites.js +521 -0
  51. package/dist/plus/integrations/providers/asanaTaskWrites.js.map +1 -0
  52. package/dist/plus/integrations/providers/trello.js +6 -23
  53. package/dist/plus/integrations/providers/trello.js.map +1 -1
  54. package/dist/plus/integrations/providers/trelloCardWriteTransport.d.ts +3 -4
  55. package/dist/plus/integrations/providers/trelloCardWriteTransport.js +19 -40
  56. package/dist/plus/integrations/providers/trelloCardWriteTransport.js.map +1 -1
  57. package/dist/plus/integrations/providers/utils/writeTransport.d.ts +28 -0
  58. package/dist/plus/integrations/providers/utils/writeTransport.js +60 -0
  59. package/dist/plus/integrations/providers/utils/writeTransport.js.map +1 -0
  60. package/dist/utils/env/browser/platform.d.ts +1 -0
  61. package/dist/utils/env/browser/platform.js +4 -1
  62. package/dist/utils/env/browser/platform.js.map +1 -1
  63. package/dist/utils/env/node/exec.d.ts +1 -0
  64. package/dist/utils/env/node/exec.js +9 -3
  65. package/dist/utils/env/node/exec.js.map +1 -1
  66. package/dist/utils/env/node/platform.d.ts +1 -0
  67. package/dist/utils/env/node/platform.js +4 -1
  68. package/dist/utils/env/node/platform.js.map +1 -1
  69. package/dist/utils/platform.d.ts +2 -2
  70. package/dist/utils/platform.js +2 -2
  71. package/docs/integrations.md +25 -0
  72. package/package.json +1 -1
@@ -6,9 +6,15 @@ export interface IndexRefresherOptions {
6
6
  /** The index file's modified time; `undefined` when it can't be read (no checkout, no index) */
7
7
  statIndexMtimeMs: (checkoutPath: string) => Promise<number | undefined>;
8
8
  /**
9
- * Whether {@link IndexRefresher.refreshAfter} refreshes after core's own writes; off by default, since each refresh is
10
- * a status of the whole checkout, worth it only where that checkout will be read again. {@link IndexRefresher.schedule}
11
- * runs either way.
9
+ * Whether the checkout has a rebase, merge, cherry-pick or revert paused, read without running git; a refresh after
10
+ * a stale read skips such a checkout. Without it, none is taken to be paused.
11
+ */
12
+ hasPausedOperation?: (checkoutPath: string) => Promise<boolean>;
13
+ /**
14
+ * Whether {@link IndexRefresher.refreshAfter} refreshes after core's own writes, and
15
+ * {@link IndexRefresher.scheduleAfterStaleRead} after a status read that found entries git had to re-check; off by
16
+ * default, since each refresh is a status of the whole checkout, worth it only where that checkout will be read
17
+ * again. {@link IndexRefresher.schedule} runs either way.
12
18
  */
13
19
  afterWrites?: boolean;
14
20
  now?: () => number;
@@ -33,9 +39,11 @@ export declare const indexRefreshTimeoutMs: number;
33
39
  * The refresh waits until the clock is in a later second than the index file's: one that rewrote the index in the same
34
40
  * second as the last file written would leave the entries racy all the same. It is a `status`, not `update-index
35
41
  * --refresh`: the latter holds the index lock for the whole re-hash, so a writer in the checkout meanwhile (a reset, a
36
- * first `git add`) would fail with "index.lock exists", whereas a status locks only for the short write at the end and
37
- * skips that write, still exiting 0, when someone else holds the lock. Optional locks are forced on for it because that
38
- * write is the whole point, applied over the inherited environment so a user's own `GIT_OPTIONAL_LOCKS=0` can't defeat it.
42
+ * first `git add`) would fail with "index.lock exists". A status skips its write, still exiting 0, when someone else
43
+ * holds the lock, but a writer starting while the status holds it still fails. Optional locks are forced on for it
44
+ * because that write is the whole point, applied over the inherited environment so a user's own `GIT_OPTIONAL_LOCKS=0`
45
+ * can't defeat it.
46
+ * SEE: strace, git 2.56.1: status takes index.lock after its re-hash and holds it to the end (~20 ms on 11.7k files)
39
47
  *
40
48
  * One queue per checkout: a schedule while the refresh is waiting joins it, since the status hasn't read the tree yet,
41
49
  * and the wait is taken again from the index as that write left it; one while the status runs causes exactly one more
@@ -45,16 +53,38 @@ export declare const indexRefreshTimeoutMs: number;
45
53
  export declare class IndexRefresher {
46
54
  private readonly options;
47
55
  private readonly _entries;
56
+ private readonly _staleReadWaits;
57
+ private readonly _staleReadRefreshedAt;
58
+ private readonly _staleReadRefreshedFor;
48
59
  private _disposed;
49
60
  private readonly _now;
50
61
  private readonly _setTimer;
51
62
  constructor(options: IndexRefresherOptions);
52
63
  /** Cancels the waits and stops anything more from starting; a status already running is left to finish */
53
64
  dispose(): void;
65
+ get afterWrites(): boolean;
54
66
  /** The refresh waiting or running for a checkout, if any */
55
67
  pending(checkoutPath: string): Promise<void> | undefined;
56
68
  /** Starts a refresh of the checkout's index in the background, or joins the one in progress. Never throws. */
57
69
  schedule(checkoutPath: string): void;
70
+ /**
71
+ * Takes a status read's count of the checkout's index entries git had to re-check that a refresh could make trusted
72
+ * (`stale`), and schedules a refresh once 2 seconds pass without another such read, so the refresh's lock doesn't
73
+ * land between a writer's own chained commands. At most one per checkout per 10 seconds: a read whose wait ends
74
+ * sooner is put off to then, dropped only when another refresh of the checkout ends first. When the wait ends, it
75
+ * schedules nothing while the checkout has a paused rebase, merge, cherry-pick or revert (see
76
+ * {@link IndexRefresherOptions.hasPausedOperation}).
77
+ *
78
+ * A read of 0 cancels a waiting refresh. Once a refresh is scheduled after a stale read, a read of no more entries than
79
+ * the fewest counted since schedules nothing until a back-off ends: 30 seconds, doubling with each such refresh up to
80
+ * 30 minutes, and reset only by a read of 0. A read of more is new work and schedules as above. Entries a refresh
81
+ * can't make trusted, such as each clean submodule's, would otherwise refresh the checkout every 10 seconds,
82
+ * while a refresh that failed or found the index locked is still retried. A read while a refresh of the checkout
83
+ * waits or runs (see {@link IndexRefresher.pending}) is ignored, and a wait begun before that refresh ended schedules
84
+ * nothing, since that refresh may make the read's entries trusted. Without {@link IndexRefresherOptions.afterWrites},
85
+ * it schedules nothing. Never throws.
86
+ */
87
+ scheduleAfterStaleRead(checkoutPath: string, stale: number): void;
58
88
  /**
59
89
  * Runs a write, then schedules a refresh when it rewrote the checkout's index, which is the sign that it rewrote
60
90
  * files; a write that touched none (already up to date, a switch to the commit already checked out) leaves the index
@@ -68,6 +98,8 @@ export declare class IndexRefresher {
68
98
  * {@link IndexRefresherOptions.afterWrites}, it only runs the write.
69
99
  */
70
100
  refreshAfter<T>(checkoutPath: string, write: () => Promise<T>): Promise<T>;
101
+ private waitForStaleReads;
102
+ private refreshAfterStaleReads;
71
103
  private scheduleIfIndexRewritten;
72
104
  private run;
73
105
  private refreshOnce;
@@ -7,6 +7,10 @@ import { gitConfigsStatus } from "./git.js";
7
7
  * checkout from ever being refreshed again, for as long as the process lives
8
8
  */
9
9
  const indexRefreshTimeoutMs = 6e5;
10
+ const staleReadQuietMs = 2e3;
11
+ const staleReadRefreshIntervalMs = 1e4;
12
+ const staleReadRepeatMinMs = 3e4;
13
+ const staleReadRepeatMaxMs = 18e5;
10
14
  function setUnrefTimer(fn, ms) {
11
15
  const timer = setTimeout(fn, ms);
12
16
  timer.unref();
@@ -24,9 +28,11 @@ function setUnrefTimer(fn, ms) {
24
28
  * The refresh waits until the clock is in a later second than the index file's: one that rewrote the index in the same
25
29
  * second as the last file written would leave the entries racy all the same. It is a `status`, not `update-index
26
30
  * --refresh`: the latter holds the index lock for the whole re-hash, so a writer in the checkout meanwhile (a reset, a
27
- * first `git add`) would fail with "index.lock exists", whereas a status locks only for the short write at the end and
28
- * skips that write, still exiting 0, when someone else holds the lock. Optional locks are forced on for it because that
29
- * write is the whole point, applied over the inherited environment so a user's own `GIT_OPTIONAL_LOCKS=0` can't defeat it.
31
+ * first `git add`) would fail with "index.lock exists". A status skips its write, still exiting 0, when someone else
32
+ * holds the lock, but a writer starting while the status holds it still fails. Optional locks are forced on for it
33
+ * because that write is the whole point, applied over the inherited environment so a user's own `GIT_OPTIONAL_LOCKS=0`
34
+ * can't defeat it.
35
+ * SEE: strace, git 2.56.1: status takes index.lock after its re-hash and holds it to the end (~20 ms on 11.7k files)
30
36
  *
31
37
  * One queue per checkout: a schedule while the refresh is waiting joins it, since the status hasn't read the tree yet,
32
38
  * and the wait is taken again from the index as that write left it; one while the status runs causes exactly one more
@@ -36,6 +42,9 @@ function setUnrefTimer(fn, ms) {
36
42
  var IndexRefresher = class {
37
43
  options;
38
44
  _entries = /* @__PURE__ */ new Map();
45
+ _staleReadWaits = /* @__PURE__ */ new Map();
46
+ _staleReadRefreshedAt = /* @__PURE__ */ new Map();
47
+ _staleReadRefreshedFor = /* @__PURE__ */ new Map();
39
48
  _disposed = false;
40
49
  _now;
41
50
  _setTimer;
@@ -48,6 +57,11 @@ var IndexRefresher = class {
48
57
  dispose() {
49
58
  this._disposed = true;
50
59
  for (const entry of this._entries.values()) entry.cancelWait?.();
60
+ for (const cancel of this._staleReadWaits.values()) cancel();
61
+ this._staleReadWaits.clear();
62
+ }
63
+ get afterWrites() {
64
+ return this.options.afterWrites === true;
51
65
  }
52
66
  /** The refresh waiting or running for a checkout, if any */
53
67
  pending(checkoutPath) {
@@ -75,6 +89,42 @@ var IndexRefresher = class {
75
89
  else entry.joined = true;
76
90
  }
77
91
  /**
92
+ * Takes a status read's count of the checkout's index entries git had to re-check that a refresh could make trusted
93
+ * (`stale`), and schedules a refresh once 2 seconds pass without another such read, so the refresh's lock doesn't
94
+ * land between a writer's own chained commands. At most one per checkout per 10 seconds: a read whose wait ends
95
+ * sooner is put off to then, dropped only when another refresh of the checkout ends first. When the wait ends, it
96
+ * schedules nothing while the checkout has a paused rebase, merge, cherry-pick or revert (see
97
+ * {@link IndexRefresherOptions.hasPausedOperation}).
98
+ *
99
+ * A read of 0 cancels a waiting refresh. Once a refresh is scheduled after a stale read, a read of no more entries than
100
+ * the fewest counted since schedules nothing until a back-off ends: 30 seconds, doubling with each such refresh up to
101
+ * 30 minutes, and reset only by a read of 0. A read of more is new work and schedules as above. Entries a refresh
102
+ * can't make trusted, such as each clean submodule's, would otherwise refresh the checkout every 10 seconds,
103
+ * while a refresh that failed or found the index locked is still retried. A read while a refresh of the checkout
104
+ * waits or runs (see {@link IndexRefresher.pending}) is ignored, and a wait begun before that refresh ended schedules
105
+ * nothing, since that refresh may make the read's entries trusted. Without {@link IndexRefresherOptions.afterWrites},
106
+ * it schedules nothing. Never throws.
107
+ */
108
+ scheduleAfterStaleRead(checkoutPath, stale) {
109
+ if (!this.options.afterWrites || this._disposed) return;
110
+ const key = normalizePath(checkoutPath);
111
+ if (this._entries.has(key)) return;
112
+ if (stale <= 0) {
113
+ this._staleReadRefreshedFor.delete(key);
114
+ this._staleReadWaits.get(key)?.();
115
+ this._staleReadWaits.delete(key);
116
+ return;
117
+ }
118
+ const last = this._staleReadRefreshedFor.get(key);
119
+ if (last != null && stale <= last.stale) {
120
+ last.stale = stale;
121
+ if (this._now() < last.retryAt) return;
122
+ }
123
+ this._staleReadWaits.get(key)?.();
124
+ this._staleReadWaits.delete(key);
125
+ this.waitForStaleReads(key, checkoutPath, stale, staleReadQuietMs);
126
+ }
127
+ /**
78
128
  * Runs a write, then schedules a refresh when it rewrote the checkout's index, which is the sign that it rewrote
79
129
  * files; a write that touched none (already up to date, a switch to the commit already checked out) leaves the index
80
130
  * alone and schedules none. A write that fails is checked the same way before its error is rethrown untouched: a
@@ -95,6 +145,35 @@ var IndexRefresher = class {
95
145
  await this.scheduleIfIndexRewritten(checkoutPath, startedAt);
96
146
  }
97
147
  }
148
+ waitForStaleReads(key, checkoutPath, stale, ms) {
149
+ this._staleReadWaits.set(key, this._setTimer(() => {
150
+ this._staleReadWaits.delete(key);
151
+ this.refreshAfterStaleReads(key, checkoutPath, stale);
152
+ }, ms));
153
+ }
154
+ async refreshAfterStaleReads(key, checkoutPath, stale) {
155
+ if (this._entries.has(key)) return;
156
+ const refreshedAt = this._staleReadRefreshedAt.get(key);
157
+ const wait = refreshedAt != null ? refreshedAt + staleReadRefreshIntervalMs - this._now() : 0;
158
+ if (wait > 0) {
159
+ this.waitForStaleReads(key, checkoutPath, stale, wait);
160
+ return;
161
+ }
162
+ try {
163
+ if (await this.options.hasPausedOperation?.(checkoutPath)) return;
164
+ if (this._disposed || this._staleReadWaits.has(key) || this._entries.has(key)) return;
165
+ const now = this._now();
166
+ const last = this._staleReadRefreshedFor.get(key);
167
+ const backoffMs = last != null ? Math.min(last.backoffMs * 2, staleReadRepeatMaxMs) : staleReadRepeatMinMs;
168
+ this._staleReadRefreshedAt.set(key, now);
169
+ this._staleReadRefreshedFor.set(key, {
170
+ stale,
171
+ retryAt: now + backoffMs,
172
+ backoffMs
173
+ });
174
+ this.schedule(checkoutPath);
175
+ } catch {}
176
+ }
98
177
  async scheduleIfIndexRewritten(checkoutPath, writeStartedAt) {
99
178
  try {
100
179
  const mtimeMs = await this.options.statIndexMtimeMs(checkoutPath);
@@ -110,6 +189,8 @@ var IndexRefresher = class {
110
189
  } while (entry.again && !this._disposed);
111
190
  } catch {} finally {
112
191
  this._entries.delete(key);
192
+ this._staleReadWaits.get(key)?.();
193
+ this._staleReadWaits.delete(key);
113
194
  }
114
195
  }
115
196
  async refreshOnce(entry) {
@@ -1 +1 @@
1
- {"version":3,"file":"indexRefresh.js","names":[],"sources":["../../../../git-cli/src/exec/indexRefresh.ts"],"sourcesContent":["import { normalizePath } from '@gitlens/utils/path.js';\nimport type { Git } from './git.js';\nimport { gitConfigsStatus } from './git.js';\n\nexport interface IndexRefresherOptions {\n\t/** Runs the refreshing `git status` */\n\tgit: Pick<Git, 'run'>;\n\t/** The index file's modified time; `undefined` when it can't be read (no checkout, no index) */\n\tstatIndexMtimeMs: (checkoutPath: string) => Promise<number | undefined>;\n\t/**\n\t * Whether {@link IndexRefresher.refreshAfter} refreshes after core's own writes; off by default, since each refresh is\n\t * a status of the whole checkout, worth it only where that checkout will be read again. {@link IndexRefresher.schedule}\n\t * runs either way.\n\t */\n\tafterWrites?: boolean;\n\tnow?: () => number;\n\t/** Calls `fn` after `ms` and returns a function that cancels it; the default timer doesn't keep the process alive */\n\tsetTimer?: (fn: () => void, ms: number) => () => void;\n}\n\ninterface Entry {\n\t/** The checkout's path as the first schedule gave it, which the provider's caches are keyed by */\n\treadonly path: string;\n\ttask: Promise<void>;\n\t/** Whether the status has started: a write that lands after that may have missed it */\n\trunning: boolean;\n\t/** Whether another write was scheduled while the status was running */\n\tagain: boolean;\n\t/** Whether another write was scheduled while the refresh waited: it may have stamped the index in a later second */\n\tjoined: boolean;\n\t/** Ends the wait for the clock early, while there is one */\n\tcancelWait: (() => void) | undefined;\n}\n\n/**\n * The refresh's own cap, far past git's default: a status that re-hashes a large checkout can run for minutes and must\n * be allowed to finish, while one stuck on a stalled file system would otherwise hold a git slot, and keep that\n * checkout from ever being refreshed again, for as long as the process lives\n */\nexport const indexRefreshTimeoutMs = 10 * 60 * 1000;\n\nfunction setUnrefTimer(fn: () => void, ms: number): () => void {\n\tconst timer = setTimeout(fn, ms);\n\ttimer.unref();\n\treturn () => clearTimeout(timer);\n}\n\n/**\n * Rewrites a checkout's index once, in the background, after git has written a batch of its files.\n *\n * A write that touches many files (a clone, a worktree add, a branch switch, a fast-forward) stamps them in the same\n * second as the index file, and git compares timestamps at whole-second precision: an entry whose second is not\n * earlier than the index file's is \"racily clean\", so git can't trust it, and every later status or diff re-hashes the\n * file for as long as nothing rewrites the index. Core's own status reads run with `GIT_OPTIONAL_LOCKS=0`, so they\n * never write the refreshed index back.\n *\n * The refresh waits until the clock is in a later second than the index file's: one that rewrote the index in the same\n * second as the last file written would leave the entries racy all the same. It is a `status`, not `update-index\n * --refresh`: the latter holds the index lock for the whole re-hash, so a writer in the checkout meanwhile (a reset, a\n * first `git add`) would fail with \"index.lock exists\", whereas a status locks only for the short write at the end and\n * skips that write, still exiting 0, when someone else holds the lock. Optional locks are forced on for it because that\n * write is the whole point, applied over the inherited environment so a user's own `GIT_OPTIONAL_LOCKS=0` can't defeat it.\n *\n * One queue per checkout: a schedule while the refresh is waiting joins it, since the status hasn't read the tree yet,\n * and the wait is taken again from the index as that write left it; one while the status runs causes exactly one more\n * refresh after it, however many arrive, since the write may have landed after the status read the tree. Nothing here\n * throws, nor does a checkout removed meanwhile.\n */\nexport class IndexRefresher {\n\tprivate readonly _entries = new Map<string, Entry>();\n\tprivate _disposed = false;\n\tprivate readonly _now: () => number;\n\tprivate readonly _setTimer: (fn: () => void, ms: number) => () => void;\n\n\tconstructor(private readonly options: IndexRefresherOptions) {\n\t\tthis._now = options.now ?? Date.now;\n\t\tthis._setTimer = options.setTimer ?? setUnrefTimer;\n\t}\n\n\t/** Cancels the waits and stops anything more from starting; a status already running is left to finish */\n\tdispose(): void {\n\t\tthis._disposed = true;\n\t\tfor (const entry of this._entries.values()) {\n\t\t\tentry.cancelWait?.();\n\t\t}\n\t}\n\n\t/** The refresh waiting or running for a checkout, if any */\n\tpending(checkoutPath: string): Promise<void> | undefined {\n\t\treturn this._entries.get(normalizePath(checkoutPath))?.task;\n\t}\n\n\t/** Starts a refresh of the checkout's index in the background, or joins the one in progress. Never throws. */\n\tschedule(checkoutPath: string): void {\n\t\tif (this._disposed) return;\n\n\t\tconst key = normalizePath(checkoutPath);\n\t\tconst entry = this._entries.get(key);\n\t\tif (entry == null) {\n\t\t\tconst created: Entry = {\n\t\t\t\tpath: checkoutPath,\n\t\t\t\ttask: Promise.resolve(),\n\t\t\t\trunning: false,\n\t\t\t\tagain: false,\n\t\t\t\tjoined: false,\n\t\t\t\tcancelWait: undefined,\n\t\t\t};\n\t\t\tthis._entries.set(key, created);\n\t\t\tcreated.task = this.run(key, created);\n\t\t\treturn;\n\t\t}\n\n\t\tif (entry.running) {\n\t\t\tentry.again = true;\n\t\t} else {\n\t\t\tentry.joined = true;\n\t\t}\n\t}\n\n\t/**\n\t * Runs a write, then schedules a refresh when it rewrote the checkout's index, which is the sign that it rewrote\n\t * files; a write that touched none (already up to date, a switch to the commit already checked out) leaves the index\n\t * alone and schedules none. A write that fails is checked the same way before its error is rethrown untouched: a\n\t * merge or rebase that stops on conflicts has rewritten the clean files and the index first, and those are read the\n\t * most while the conflicts are resolved, whereas a checkout or merge refused outright leaves the index alone and\n\t * schedules none (a stash apply or push rewrites it first, so schedules one even when refused or with nothing to\n\t * save). Only the check is awaited, not the refresh it may schedule.\n\t *\n\t * `checkoutPath` is the checkout the write rewrote, which isn't always the one it ran in. Without\n\t * {@link IndexRefresherOptions.afterWrites}, it only runs the write.\n\t */\n\tasync refreshAfter<T>(checkoutPath: string, write: () => Promise<T>): Promise<T> {\n\t\tif (!this.options.afterWrites) return write();\n\n\t\tconst startedAt = this._now();\n\t\ttry {\n\t\t\treturn await write();\n\t\t} finally {\n\t\t\tawait this.scheduleIfIndexRewritten(checkoutPath, startedAt);\n\t\t}\n\t}\n\n\tprivate async scheduleIfIndexRewritten(checkoutPath: string, writeStartedAt: number): Promise<void> {\n\t\ttry {\n\t\t\tconst mtimeMs = await this.options.statIndexMtimeMs(checkoutPath);\n\t\t\tif (mtimeMs != null && mtimeMs >= Math.floor(writeStartedAt / 1000) * 1000) {\n\t\t\t\tthis.schedule(checkoutPath);\n\t\t\t}\n\t\t} catch {}\n\t}\n\n\tprivate async run(key: string, entry: Entry): Promise<void> {\n\t\ttry {\n\t\t\tdo {\n\t\t\t\tentry.again = false;\n\t\t\t\tentry.running = false;\n\t\t\t\tawait this.refreshOnce(entry);\n\t\t\t} while (entry.again && !this._disposed);\n\t\t} catch {\n\t\t\t// Best-effort: a failed refresh only leaves the entries as untrusted as they were\n\t\t} finally {\n\t\t\tthis._entries.delete(key);\n\t\t}\n\t}\n\n\tprivate async refreshOnce(entry: Entry): Promise<void> {\n\t\tconst checkoutPath = entry.path;\n\t\t// A write that joined while this waited may have stamped the index in a later second than the one waited out\n\t\tdo {\n\t\t\tentry.joined = false;\n\t\t\tconst mtimeMs = await this.options.statIndexMtimeMs(checkoutPath);\n\t\t\tif (mtimeMs == null) return;\n\n\t\t\t// The file system can stamp the index ahead of this clock (a network or VM-shared folder, a clock set back),\n\t\t\t// and waiting for this clock to reach that second could take any time. The file system's own clock was at\n\t\t\t// least at the stamp when the stat read it, so it has passed that second once the rest of the second has gone\n\t\t\t// by since\n\t\t\tconst laterSecondMs = (Math.floor(mtimeMs / 1000) + 1) * 1000;\n\t\t\tconst deadlineMs = Math.min(laterSecondMs, this._now() + laterSecondMs - mtimeMs);\n\t\t\tfor (let wait = deadlineMs - this._now(); wait > 0; wait = deadlineMs - this._now()) {\n\t\t\t\tif (this._disposed) return;\n\n\t\t\t\tawait new Promise<void>(resolve => {\n\t\t\t\t\tconst cancel = this._setTimer(resolve, wait);\n\t\t\t\t\tentry.cancelWait = () => {\n\t\t\t\t\t\tcancel();\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t\tentry.cancelWait = undefined;\n\t\t\t}\n\t\t\tif (this._disposed) return;\n\t\t} while (entry.joined);\n\n\t\tentry.running = true;\n\t\tawait this.options.git.run(\n\t\t\t{\n\t\t\t\tcwd: checkoutPath,\n\t\t\t\t// Skips the rename detection between HEAD and the index, which the refresh doesn't need; older git ignores it\n\t\t\t\tconfigs: [...gitConfigsStatus, '-c', 'status.renames=false'],\n\t\t\t\tenv: { GIT_OPTIONAL_LOCKS: '1' },\n\t\t\t\terrors: 'ignore',\n\t\t\t\tpriority: 'background',\n\t\t\t\tselfMaintenance: true,\n\t\t\t\ttimeout: indexRefreshTimeoutMs,\n\t\t\t},\n\t\t\t'status',\n\t\t\t'--porcelain',\n\t\t\t'-uno',\n\t\t\t// The index refreshes all the same; this only skips the status git runs inside each submodule\n\t\t\t'--ignore-submodules=all',\n\t\t);\n\t}\n}\n\n/** {@link IndexRefresher.refreshAfter}, or only the write when there is no refresher */\nexport function refreshIndexAfter<T>(\n\trefresher: IndexRefresher | undefined,\n\tcheckoutPath: string,\n\twrite: () => Promise<T>,\n): Promise<T> {\n\treturn refresher != null ? refresher.refreshAfter(checkoutPath, write) : write();\n}\n"],"mappings":";;;;;;;;AAuCA,MAAa,wBAAwB;AAErC,SAAS,cAAc,IAAgB,IAAwB;CAC9D,MAAM,QAAQ,WAAW,IAAI,EAAE;CAC/B,MAAM,MAAM;CACZ,aAAa,aAAa,KAAK;AAChC;;;;;;;;;;;;;;;;;;;;;;AAuBA,IAAa,iBAAb,MAA4B;CAME;CAL7B,2BAA4B,IAAI,IAAmB;CACnD,YAAoB;CACpB;CACA;CAEA,YAAY,SAAiD;EAAhC,KAAA,UAAA;EAC5B,KAAK,OAAO,QAAQ,OAAO,KAAK;EAChC,KAAK,YAAY,QAAQ,YAAY;CACtC;;CAGA,UAAgB;EACf,KAAK,YAAY;EACjB,KAAK,MAAM,SAAS,KAAK,SAAS,OAAO,GACxC,MAAM,aAAa;CAErB;;CAGA,QAAQ,cAAiD;EACxD,OAAO,KAAK,SAAS,IAAI,cAAc,YAAY,CAAC,CAAC,EAAE;CACxD;;CAGA,SAAS,cAA4B;EACpC,IAAI,KAAK,WAAW;EAEpB,MAAM,MAAM,cAAc,YAAY;EACtC,MAAM,QAAQ,KAAK,SAAS,IAAI,GAAG;EACnC,IAAI,SAAS,MAAM;GAClB,MAAM,UAAiB;IACtB,MAAM;IACN,MAAM,QAAQ,QAAQ;IACtB,SAAS;IACT,OAAO;IACP,QAAQ;IACR,YAAY,KAAA;GACb;GACA,KAAK,SAAS,IAAI,KAAK,OAAO;GAC9B,QAAQ,OAAO,KAAK,IAAI,KAAK,OAAO;GACpC;EACD;EAEA,IAAI,MAAM,SACT,MAAM,QAAQ;OAEd,MAAM,SAAS;CAEjB;;;;;;;;;;;;;CAcA,MAAM,aAAgB,cAAsB,OAAqC;EAChF,IAAI,CA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,QAAQ,IAAI,IACtB;GACC,KAAK;GAEL,SAAS;IAAC,GAAG;IAAkB;IAAM;GAAsB;GAC3D,KAAK,EAAE,oBAAoB,IAAI;GAC/B,QAAQ;GACR,UAAU;GACV,iBAAiB;GACjB,SAAS;EACV,GACA,UACA,eACA,QAEA,yBACD;CACD;AACD;;AAGA,SAAgB,kBACf,WACA,cACA,OACa;CACb,OAAO,aAAa,OAAO,UAAU,aAAa,cAAc,KAAK,IAAI,MAAM;AAChF"}
1
+ {"version":3,"file":"indexRefresh.js","names":[],"sources":["../../../../git-cli/src/exec/indexRefresh.ts"],"sourcesContent":["import { normalizePath } from '@gitlens/utils/path.js';\nimport type { Git } from './git.js';\nimport { gitConfigsStatus } from './git.js';\n\nexport interface IndexRefresherOptions {\n\t/** Runs the refreshing `git status` */\n\tgit: Pick<Git, 'run'>;\n\t/** The index file's modified time; `undefined` when it can't be read (no checkout, no index) */\n\tstatIndexMtimeMs: (checkoutPath: string) => Promise<number | undefined>;\n\t/**\n\t * Whether the checkout has a rebase, merge, cherry-pick or revert paused, read without running git; a refresh after\n\t * a stale read skips such a checkout. Without it, none is taken to be paused.\n\t */\n\thasPausedOperation?: (checkoutPath: string) => Promise<boolean>;\n\t/**\n\t * Whether {@link IndexRefresher.refreshAfter} refreshes after core's own writes, and\n\t * {@link IndexRefresher.scheduleAfterStaleRead} after a status read that found entries git had to re-check; off by\n\t * default, since each refresh is a status of the whole checkout, worth it only where that checkout will be read\n\t * again. {@link IndexRefresher.schedule} runs either way.\n\t */\n\tafterWrites?: boolean;\n\tnow?: () => number;\n\t/** Calls `fn` after `ms` and returns a function that cancels it; the default timer doesn't keep the process alive */\n\tsetTimer?: (fn: () => void, ms: number) => () => void;\n}\n\ninterface Entry {\n\t/** The checkout's path as the first schedule gave it, which the provider's caches are keyed by */\n\treadonly path: string;\n\ttask: Promise<void>;\n\t/** Whether the status has started: a write that lands after that may have missed it */\n\trunning: boolean;\n\t/** Whether another write was scheduled while the status was running */\n\tagain: boolean;\n\t/** Whether another write was scheduled while the refresh waited: it may have stamped the index in a later second */\n\tjoined: boolean;\n\t/** Ends the wait for the clock early, while there is one */\n\tcancelWait: (() => void) | undefined;\n}\n\n/**\n * The refresh's own cap, far past git's default: a status that re-hashes a large checkout can run for minutes and must\n * be allowed to finish, while one stuck on a stalled file system would otherwise hold a git slot, and keep that\n * checkout from ever being refreshed again, for as long as the process lives\n */\nexport const indexRefreshTimeoutMs = 10 * 60 * 1000;\n\nconst staleReadQuietMs = 2_000;\nconst staleReadRefreshIntervalMs = 10_000;\nconst staleReadRepeatMinMs = 30_000;\nconst staleReadRepeatMaxMs = 30 * 60 * 1000;\n\ninterface StaleReadRefresh {\n\tstale: number;\n\tretryAt: number;\n\tbackoffMs: number;\n}\n\nfunction setUnrefTimer(fn: () => void, ms: number): () => void {\n\tconst timer = setTimeout(fn, ms);\n\ttimer.unref();\n\treturn () => clearTimeout(timer);\n}\n\n/**\n * Rewrites a checkout's index once, in the background, after git has written a batch of its files.\n *\n * A write that touches many files (a clone, a worktree add, a branch switch, a fast-forward) stamps them in the same\n * second as the index file, and git compares timestamps at whole-second precision: an entry whose second is not\n * earlier than the index file's is \"racily clean\", so git can't trust it, and every later status or diff re-hashes the\n * file for as long as nothing rewrites the index. Core's own status reads run with `GIT_OPTIONAL_LOCKS=0`, so they\n * never write the refreshed index back.\n *\n * The refresh waits until the clock is in a later second than the index file's: one that rewrote the index in the same\n * second as the last file written would leave the entries racy all the same. It is a `status`, not `update-index\n * --refresh`: the latter holds the index lock for the whole re-hash, so a writer in the checkout meanwhile (a reset, a\n * first `git add`) would fail with \"index.lock exists\". A status skips its write, still exiting 0, when someone else\n * holds the lock, but a writer starting while the status holds it still fails. Optional locks are forced on for it\n * because that write is the whole point, applied over the inherited environment so a user's own `GIT_OPTIONAL_LOCKS=0`\n * can't defeat it.\n * SEE: strace, git 2.56.1: status takes index.lock after its re-hash and holds it to the end (~20 ms on 11.7k files)\n *\n * One queue per checkout: a schedule while the refresh is waiting joins it, since the status hasn't read the tree yet,\n * and the wait is taken again from the index as that write left it; one while the status runs causes exactly one more\n * refresh after it, however many arrive, since the write may have landed after the status read the tree. Nothing here\n * throws, nor does a checkout removed meanwhile.\n */\nexport class IndexRefresher {\n\tprivate readonly _entries = new Map<string, Entry>();\n\tprivate readonly _staleReadWaits = new Map<string, () => void>();\n\tprivate readonly _staleReadRefreshedAt = new Map<string, number>();\n\tprivate readonly _staleReadRefreshedFor = new Map<string, StaleReadRefresh>();\n\tprivate _disposed = false;\n\tprivate readonly _now: () => number;\n\tprivate readonly _setTimer: (fn: () => void, ms: number) => () => void;\n\n\tconstructor(private readonly options: IndexRefresherOptions) {\n\t\tthis._now = options.now ?? Date.now;\n\t\tthis._setTimer = options.setTimer ?? setUnrefTimer;\n\t}\n\n\t/** Cancels the waits and stops anything more from starting; a status already running is left to finish */\n\tdispose(): void {\n\t\tthis._disposed = true;\n\t\tfor (const entry of this._entries.values()) {\n\t\t\tentry.cancelWait?.();\n\t\t}\n\t\tfor (const cancel of this._staleReadWaits.values()) {\n\t\t\tcancel();\n\t\t}\n\t\tthis._staleReadWaits.clear();\n\t}\n\n\tget afterWrites(): boolean {\n\t\treturn this.options.afterWrites === true;\n\t}\n\n\t/** The refresh waiting or running for a checkout, if any */\n\tpending(checkoutPath: string): Promise<void> | undefined {\n\t\treturn this._entries.get(normalizePath(checkoutPath))?.task;\n\t}\n\n\t/** Starts a refresh of the checkout's index in the background, or joins the one in progress. Never throws. */\n\tschedule(checkoutPath: string): void {\n\t\tif (this._disposed) return;\n\n\t\tconst key = normalizePath(checkoutPath);\n\t\tconst entry = this._entries.get(key);\n\t\tif (entry == null) {\n\t\t\tconst created: Entry = {\n\t\t\t\tpath: checkoutPath,\n\t\t\t\ttask: Promise.resolve(),\n\t\t\t\trunning: false,\n\t\t\t\tagain: false,\n\t\t\t\tjoined: false,\n\t\t\t\tcancelWait: undefined,\n\t\t\t};\n\t\t\tthis._entries.set(key, created);\n\t\t\tcreated.task = this.run(key, created);\n\t\t\treturn;\n\t\t}\n\n\t\tif (entry.running) {\n\t\t\tentry.again = true;\n\t\t} else {\n\t\t\tentry.joined = true;\n\t\t}\n\t}\n\n\t/**\n\t * Takes a status read's count of the checkout's index entries git had to re-check that a refresh could make trusted\n\t * (`stale`), and schedules a refresh once 2 seconds pass without another such read, so the refresh's lock doesn't\n\t * land between a writer's own chained commands. At most one per checkout per 10 seconds: a read whose wait ends\n\t * sooner is put off to then, dropped only when another refresh of the checkout ends first. When the wait ends, it\n\t * schedules nothing while the checkout has a paused rebase, merge, cherry-pick or revert (see\n\t * {@link IndexRefresherOptions.hasPausedOperation}).\n\t *\n\t * A read of 0 cancels a waiting refresh. Once a refresh is scheduled after a stale read, a read of no more entries than\n\t * the fewest counted since schedules nothing until a back-off ends: 30 seconds, doubling with each such refresh up to\n\t * 30 minutes, and reset only by a read of 0. A read of more is new work and schedules as above. Entries a refresh\n\t * can't make trusted, such as each clean submodule's, would otherwise refresh the checkout every 10 seconds,\n\t * while a refresh that failed or found the index locked is still retried. A read while a refresh of the checkout\n\t * waits or runs (see {@link IndexRefresher.pending}) is ignored, and a wait begun before that refresh ended schedules\n\t * nothing, since that refresh may make the read's entries trusted. Without {@link IndexRefresherOptions.afterWrites},\n\t * it schedules nothing. Never throws.\n\t */\n\tscheduleAfterStaleRead(checkoutPath: string, stale: number): void {\n\t\tif (!this.options.afterWrites || this._disposed) return;\n\n\t\tconst key = normalizePath(checkoutPath);\n\t\tif (this._entries.has(key)) return;\n\n\t\tif (stale <= 0) {\n\t\t\tthis._staleReadRefreshedFor.delete(key);\n\t\t\tthis._staleReadWaits.get(key)?.();\n\t\t\tthis._staleReadWaits.delete(key);\n\t\t\treturn;\n\t\t}\n\n\t\tconst last = this._staleReadRefreshedFor.get(key);\n\t\tif (last != null && stale <= last.stale) {\n\t\t\tlast.stale = stale;\n\t\t\tif (this._now() < last.retryAt) return;\n\t\t}\n\n\t\tthis._staleReadWaits.get(key)?.();\n\t\tthis._staleReadWaits.delete(key);\n\n\t\tthis.waitForStaleReads(key, checkoutPath, stale, staleReadQuietMs);\n\t}\n\n\t/**\n\t * Runs a write, then schedules a refresh when it rewrote the checkout's index, which is the sign that it rewrote\n\t * files; a write that touched none (already up to date, a switch to the commit already checked out) leaves the index\n\t * alone and schedules none. A write that fails is checked the same way before its error is rethrown untouched: a\n\t * merge or rebase that stops on conflicts has rewritten the clean files and the index first, and those are read the\n\t * most while the conflicts are resolved, whereas a checkout or merge refused outright leaves the index alone and\n\t * schedules none (a stash apply or push rewrites it first, so schedules one even when refused or with nothing to\n\t * save). Only the check is awaited, not the refresh it may schedule.\n\t *\n\t * `checkoutPath` is the checkout the write rewrote, which isn't always the one it ran in. Without\n\t * {@link IndexRefresherOptions.afterWrites}, it only runs the write.\n\t */\n\tasync refreshAfter<T>(checkoutPath: string, write: () => Promise<T>): Promise<T> {\n\t\tif (!this.options.afterWrites) return write();\n\n\t\tconst startedAt = this._now();\n\t\ttry {\n\t\t\treturn await write();\n\t\t} finally {\n\t\t\tawait this.scheduleIfIndexRewritten(checkoutPath, startedAt);\n\t\t}\n\t}\n\n\tprivate waitForStaleReads(key: string, checkoutPath: string, stale: number, ms: number): void {\n\t\tthis._staleReadWaits.set(\n\t\t\tkey,\n\t\t\tthis._setTimer(() => {\n\t\t\t\tthis._staleReadWaits.delete(key);\n\t\t\t\tvoid this.refreshAfterStaleReads(key, checkoutPath, stale);\n\t\t\t}, ms),\n\t\t);\n\t}\n\n\tprivate async refreshAfterStaleReads(key: string, checkoutPath: string, stale: number): Promise<void> {\n\t\tif (this._entries.has(key)) return;\n\n\t\tconst refreshedAt = this._staleReadRefreshedAt.get(key);\n\t\tconst wait = refreshedAt != null ? refreshedAt + staleReadRefreshIntervalMs - this._now() : 0;\n\t\tif (wait > 0) {\n\t\t\tthis.waitForStaleReads(key, checkoutPath, stale, wait);\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tif (await this.options.hasPausedOperation?.(checkoutPath)) return;\n\t\t\tif (this._disposed || this._staleReadWaits.has(key) || this._entries.has(key)) return;\n\n\t\t\tconst now = this._now();\n\t\t\tconst last = this._staleReadRefreshedFor.get(key);\n\t\t\tconst backoffMs = last != null ? Math.min(last.backoffMs * 2, staleReadRepeatMaxMs) : staleReadRepeatMinMs;\n\t\t\tthis._staleReadRefreshedAt.set(key, now);\n\t\t\tthis._staleReadRefreshedFor.set(key, { stale: stale, retryAt: now + backoffMs, backoffMs: backoffMs });\n\t\t\tthis.schedule(checkoutPath);\n\t\t} catch {}\n\t}\n\n\tprivate async scheduleIfIndexRewritten(checkoutPath: string, writeStartedAt: number): Promise<void> {\n\t\ttry {\n\t\t\tconst mtimeMs = await this.options.statIndexMtimeMs(checkoutPath);\n\t\t\tif (mtimeMs != null && mtimeMs >= Math.floor(writeStartedAt / 1000) * 1000) {\n\t\t\t\tthis.schedule(checkoutPath);\n\t\t\t}\n\t\t} catch {}\n\t}\n\n\tprivate async run(key: string, entry: Entry): Promise<void> {\n\t\ttry {\n\t\t\tdo {\n\t\t\t\tentry.again = false;\n\t\t\t\tentry.running = false;\n\t\t\t\tawait this.refreshOnce(entry);\n\t\t\t} while (entry.again && !this._disposed);\n\t\t} catch {\n\t\t} finally {\n\t\t\tthis._entries.delete(key);\n\t\t\tthis._staleReadWaits.get(key)?.();\n\t\t\tthis._staleReadWaits.delete(key);\n\t\t}\n\t}\n\n\tprivate async refreshOnce(entry: Entry): Promise<void> {\n\t\tconst checkoutPath = entry.path;\n\t\t// A write that joined while this waited may have stamped the index in a later second than the one waited out\n\t\tdo {\n\t\t\tentry.joined = false;\n\t\t\tconst mtimeMs = await this.options.statIndexMtimeMs(checkoutPath);\n\t\t\tif (mtimeMs == null) return;\n\n\t\t\t// The file system can stamp the index ahead of this clock (a network or VM-shared folder, a clock set back),\n\t\t\t// and waiting for this clock to reach that second could take any time. The file system's own clock was at\n\t\t\t// least at the stamp when the stat read it, so it has passed that second once the rest of the second has gone\n\t\t\t// by since\n\t\t\tconst laterSecondMs = (Math.floor(mtimeMs / 1000) + 1) * 1000;\n\t\t\tconst deadlineMs = Math.min(laterSecondMs, this._now() + laterSecondMs - mtimeMs);\n\t\t\tfor (let wait = deadlineMs - this._now(); wait > 0; wait = deadlineMs - this._now()) {\n\t\t\t\tif (this._disposed) return;\n\n\t\t\t\tawait new Promise<void>(resolve => {\n\t\t\t\t\tconst cancel = this._setTimer(resolve, wait);\n\t\t\t\t\tentry.cancelWait = () => {\n\t\t\t\t\t\tcancel();\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t\tentry.cancelWait = undefined;\n\t\t\t}\n\t\t\tif (this._disposed) return;\n\t\t} while (entry.joined);\n\n\t\tentry.running = true;\n\t\tawait this.options.git.run(\n\t\t\t{\n\t\t\t\tcwd: checkoutPath,\n\t\t\t\t// Skips the rename detection between HEAD and the index, which the refresh doesn't need; older git ignores it\n\t\t\t\tconfigs: [...gitConfigsStatus, '-c', 'status.renames=false'],\n\t\t\t\tenv: { GIT_OPTIONAL_LOCKS: '1' },\n\t\t\t\terrors: 'ignore',\n\t\t\t\tpriority: 'background',\n\t\t\t\tselfMaintenance: true,\n\t\t\t\ttimeout: indexRefreshTimeoutMs,\n\t\t\t},\n\t\t\t'status',\n\t\t\t'--porcelain',\n\t\t\t'-uno',\n\t\t\t// The index refreshes all the same; this only skips the status git runs inside each submodule\n\t\t\t'--ignore-submodules=all',\n\t\t);\n\t}\n}\n\n/** {@link IndexRefresher.refreshAfter}, or only the write when there is no refresher */\nexport function refreshIndexAfter<T>(\n\trefresher: IndexRefresher | undefined,\n\tcheckoutPath: string,\n\twrite: () => Promise<T>,\n): Promise<T> {\n\treturn refresher != null ? refresher.refreshAfter(checkoutPath, write) : write();\n}\n"],"mappings":";;;;;;;;AA6CA,MAAa,wBAAwB;AAErC,MAAM,mBAAmB;AACzB,MAAM,6BAA6B;AACnC,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAQ7B,SAAS,cAAc,IAAgB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AChF,KAAK,IAAI,OAAO,aAAa,KAAK,KAAK,GAAG,OAAO,GAAG,OAAO,aAAa,KAAK,KAAK,GAAG;IACpF,IAAI,KAAK,WAAW;IAEpB,MAAM,IAAI,SAAc,YAAW;KAClC,MAAM,SAAS,KAAK,UAAU,SAAS,IAAI;KAC3C,MAAM,mBAAmB;MACxB,OAAO;MACP,QAAQ;KACT;IACD,CAAC;IACD,MAAM,aAAa,KAAA;GACpB;GACA,IAAI,KAAK,WAAW;EACrB,SAAS,MAAM;EAEf,MAAM,UAAU;EAChB,MAAM,KAAK,QAAQ,IAAI,IACtB;GACC,KAAK;GAEL,SAAS;IAAC,GAAG;IAAkB;IAAM;GAAsB;GAC3D,KAAK,EAAE,oBAAoB,IAAI;GAC/B,QAAQ;GACR,UAAU;GACV,iBAAiB;GACjB,SAAS;EACV,GACA,UACA,eACA,QAEA,yBACD;CACD;AACD;;AAGA,SAAgB,kBACf,WACA,cACA,OACa;CACb,OAAO,aAAa,OAAO,UAAU,aAAa,cAAc,KAAK,IAAI,MAAM;AAChF"}
@@ -4,7 +4,7 @@ import { GitRevisionRange, GitRevisionRangeNotation } from "../../git/models/rev
4
4
  import { GitDiff, GitDiffFiles, GitDiffFilter, GitDiffShortStat, ParsedGitDiff, ParsedGitDiffHunks } from "../../git/models/diff.js";
5
5
  import { GitFile } from "../../git/models/file.js";
6
6
  import { GitServiceContext } from "../../git/context.js";
7
- import { GitErrorHandling, GitResult } from "../../git/run.types.js";
7
+ import { GitCommandPriority, GitErrorHandling, GitResult } from "../../git/run.types.js";
8
8
  import { Cache } from "../../git/cache.js";
9
9
  import { DisposableTemporaryGitIndex } from "../../git/providers/staging.js";
10
10
  import { GitDiffSubProvider, NextComparisonUrisResult, PreviousComparisonUrisResult, PreviousRangeComparisonUrisResult } from "../../git/providers/diff.js";
@@ -24,6 +24,9 @@ export declare class DiffGitSubProvider implements GitDiffSubProvider {
24
24
  includeUntracked?: boolean;
25
25
  errors?: GitErrorHandling;
26
26
  }, _cancellation?: AbortSignal): Promise<GitDiffShortStat | undefined>;
27
+ getChangedFilesCountByCommit(repoPath: string, shas: readonly string[], options?: {
28
+ priority?: GitCommandPriority;
29
+ }, cancellation?: AbortSignal): Promise<Map<string, GitDiffShortStat>>;
27
30
  getDiff(repoPath: string, to: string, from?: string, options?: {
28
31
  context?: number;
29
32
  index?: DisposableTemporaryGitIndex;
@@ -9,7 +9,7 @@ import __decorate from "../../_virtual/@oxc-project+runtime/helpers/esm/decorate
9
9
  import { GitError, GitErrors, batchLiteralPathspecs, gitConfigsDiff, gitConfigsLog } from "../exec/git.js";
10
10
  import { fnv1aHash } from "../../utils/hash.js";
11
11
  import { parseGitApplyFiles, parseGitDiff, parseGitDiffNumStatFiles, parseGitDiffShortStat, parseGitFileDiff } from "../../git/parsers/diffParser.js";
12
- import { getShaAndFileRangeLogParser, getShaAndFileSummaryLogParser } from "../parsers/logParser.js";
12
+ import { getShaAndFileRangeLogParser, getShaAndFileSummaryLogParser, getShaAndStatsLogParser } from "../parsers/logParser.js";
13
13
  import { toLiteralPathspecMatcher } from "../../git/utils/fileStatus.utils.js";
14
14
  import { encodeGitLensRevisionUriAuthority } from "../../git/utils/uriAuthority.js";
15
15
  import * as l10n from "@vscode/l10n";
@@ -55,6 +55,21 @@ var DiffGitSubProvider = class {
55
55
  throw ex;
56
56
  }
57
57
  }
58
+ async getChangedFilesCountByCommit(repoPath, shas, options, cancellation) {
59
+ const stats = /* @__PURE__ */ new Map();
60
+ if (!shas.length) return stats;
61
+ const parser = getShaAndStatsLogParser();
62
+ const result = await this.git.run({
63
+ cwd: repoPath,
64
+ configs: [...await this.git.getDiffReadConfigs(), ...gitConfigsLog],
65
+ stdin: shas.join("\n"),
66
+ errors: "throw",
67
+ cancellation,
68
+ ...options?.priority != null ? { priority: options.priority } : void 0
69
+ }, "log", "--no-walk", "--stdin", await this.git.supports("git:log:diff-merges") ? "--diff-merges=first-parent" : "-m", "--first-parent", "--root", "--no-ext-diff", ...parser.arguments, "--");
70
+ for (const entry of parser.parse(result.stdout)) if (!stats.has(entry.sha)) stats.set(entry.sha, entry.stats);
71
+ return stats;
72
+ }
58
73
  async getDiff(repoPath, to, from, options, _cancellation) {
59
74
  const scope = getScopedLogger();
60
75
  const literalPaths = options?.paths;
@@ -686,6 +701,7 @@ var DiffGitSubProvider = class {
686
701
  }
687
702
  };
688
703
  __decorate([debug({ quiet: true })], DiffGitSubProvider.prototype, "getChangedFilesCount", null);
704
+ __decorate([debug({ quiet: true })], DiffGitSubProvider.prototype, "getChangedFilesCountByCommit", null);
689
705
  __decorate([debug({ quiet: true })], DiffGitSubProvider.prototype, "getDiff", null);
690
706
  __decorate([debug({ quiet: true })], DiffGitSubProvider.prototype, "getParsedDiff", null);
691
707
  __decorate([debug({