mirror of
https://github.com/stablyai/orca.git
synced 2026-09-26 08:02:38 +00:00
* perf(git): overlap getBranchCompare's head-of-chain reads
Four git spawns ran strictly in series before any compare work began:
branch --show-current, the base-ref probe, rev-parse HEAD, and rev-parse <base>.
Three are independent -- compareRef is display-only metadata and HEAD's oid does
not depend on the base ref -- so they now run concurrently. The fourth was
redundant outright: the probe already runs `rev-parse --verify --quiet
<ref>^{commit}` and discarded the oid it printed, which was then re-resolved by a
second spawn. resolveWorktreeBaseCommitOid returns that oid so it can be reused;
hasWorktreeBaseCommitRef now delegates to it, leaving its other 4 callers
untouched.
3.6-3.7x on a short remote base label (192ms -> 52ms), 1.44x on an
already-qualified refs/... base, which skips the probe by design.
Reuse is keyed by ref: resolveWorktreeAddBaseRef returns at its first successful
candidate, so only that ref's oid is ever read back. Peeling is safe because only
refs/heads and refs/remotes candidates reach the probe, where ^{commit} is a
no-op.
No new git features: this removes a spawn rather than adopting an option.
Co-authored-by: Orca <help@stably.ai>
* fix(git): preserve compare semantics across providers
Co-authored-by: Orca <help@stably.ai>
---------
Co-authored-by: Orca <help@stably.ai>
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { readBranchCompareHead } from './git-branch-compare-head'
|
|
|
|
function deferred<T>(): { promise: Promise<T>; resolve: (value: T) => void } {
|
|
let resolve!: (value: T) => void
|
|
const promise = new Promise<T>((innerResolve) => {
|
|
resolve = innerResolve
|
|
})
|
|
return { promise, resolve }
|
|
}
|
|
|
|
describe('readBranchCompareHead', () => {
|
|
it('launches independent head reads before waiting for any result', async () => {
|
|
const compareRef = deferred<string>()
|
|
const baseRef = deferred<string>()
|
|
const headOid = deferred<string>()
|
|
const calls: string[] = []
|
|
|
|
const pending = readBranchCompareHead({
|
|
readCompareRef: () => {
|
|
calls.push('compare-ref')
|
|
return compareRef.promise
|
|
},
|
|
resolveBaseRef: () => {
|
|
calls.push('base-probe')
|
|
return baseRef.promise
|
|
},
|
|
readHeadOid: () => {
|
|
calls.push('head-oid')
|
|
return headOid.promise
|
|
},
|
|
readBaseOid: () => Promise.resolve('base-oid')
|
|
})
|
|
await Promise.resolve()
|
|
|
|
expect(calls).toEqual(['compare-ref', 'base-probe', 'head-oid'])
|
|
|
|
compareRef.resolve('feature')
|
|
baseRef.resolve('refs/remotes/origin/main')
|
|
headOid.resolve('head-oid')
|
|
await expect(pending).resolves.toMatchObject({
|
|
compareRef: 'feature',
|
|
resolvedBaseRef: 'refs/remotes/origin/main',
|
|
headOidResult: { ok: true, oid: 'head-oid' },
|
|
baseOidResult: { ok: true, oid: 'base-oid' }
|
|
})
|
|
})
|
|
})
|