Files
orca/src/main/worktree-preparation-refresh-queue.ts
T
Neil 34ae0933e4 fix(worktrees): keep creation fast in large repositories (#24346)
* fix(worktrees): remove repeated scans and keep prepared checkouts fresh

* fix(worktrees): reclaim unlocked fallback preparations safely

* refactor(worktrees): simplify creation ownership and idle maintenance

* fix(git): keep ref maintenance armed after an index-only pass

An idle attempt that found the pack index due but refs still cooling down
returned without rescheduling, so loose refs from the arming fetch waited
for the next write instead of the ref cooldown.
2026-10-01 23:37:05 -07:00

43 lines
1.4 KiB
TypeScript

import { worktreePreparationGit } from './git/worktree-create-git-executor'
import { refreshPreparedWorktreeTip } from './git/worktree-preparation-tip-refresh'
import { WorktreePreparationLockOwnershipError } from './git/worktree-preparation-lock'
import type { PreparationEntry } from './worktree-create-preparation-pool'
import { waitForPromiseWithSignal } from '../shared/abort-signal-reason'
/** Publish the refresh before yielding so a racing create waits for the same checkout. */
export function queuePreparedWorktreeTipRefresh(
entry: PreparationEntry,
retire: () => void,
beforeMaterialization?: Promise<void>
): Promise<void> {
const signal = entry.options.signal
? AbortSignal.any([entry.options.signal, entry.controller.signal])
: entry.controller.signal
const ready = entry.ready.then(async () => {
signal.throwIfAborted()
if (beforeMaterialization) {
await waitForPromiseWithSignal(beforeMaterialization, signal)
}
return worktreePreparationGit.run(() =>
refreshPreparedWorktreeTip(
entry.repoPath,
entry.preparedPath,
entry.canonicalBase,
entry.lockReason,
{
...entry.options,
signal
}
)
)
})
entry.ready = ready
void ready.catch((error: unknown) => {
if (error instanceof WorktreePreparationLockOwnershipError) {
entry.checkoutStarted = false
}
retire()
})
return ready
}