mirror of
https://github.com/stablyai/orca.git
synced 2026-10-28 16:02:55 +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>
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { gitExecFileAsync } from './runner'
|
|
|
|
type GitExecOptions = {
|
|
wslDistro?: string
|
|
}
|
|
|
|
/**
|
|
* Returns the probed commit oid, or null when the ref does not resolve.
|
|
*
|
|
* Why expose the oid: the probe already prints it, and callers that then need the
|
|
* same ref's oid were re-spawning `rev-parse` for a value this call threw away.
|
|
*/
|
|
export async function resolveWorktreeBaseCommitOid(
|
|
repoPath: string,
|
|
qualifiedRef: string,
|
|
options: GitExecOptions = {}
|
|
): Promise<string | null> {
|
|
try {
|
|
const { stdout } = await gitExecFileAsync(
|
|
['rev-parse', '--verify', '--quiet', `${qualifiedRef}^{commit}`],
|
|
{
|
|
cwd: repoPath,
|
|
...options
|
|
}
|
|
)
|
|
const oid = stdout.trim()
|
|
return oid.length > 0 ? oid : null
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export async function hasWorktreeBaseCommitRef(
|
|
repoPath: string,
|
|
qualifiedRef: string,
|
|
options: GitExecOptions = {}
|
|
): Promise<boolean> {
|
|
return (await resolveWorktreeBaseCommitOid(repoPath, qualifiedRef, options)) !== null
|
|
}
|