mirror of
https://github.com/stablyai/orca.git
synced 2026-10-30 16:47:34 +00:00
* fix(git): reduce queries and preserve data across execution hosts * fix(ci): exercise pinned Git and serialize mobile dependency entrypoints * fix(relay): preserve fresh diff retries after hung shared reads * test(git): wait for fetch barrier before canceling preparation * fix(i18n): describe index-preserving discard in every locale * fix(git): retain clone diagnostics and allow WSL policy startup * test(git): refresh default-base and branch-safety fixtures
62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
import { isGitReadInterruptedError } from './git-buffer-overflow'
|
|
import { buildDiffResult } from './git-diff-result'
|
|
import { readBlobAtOid, type GitBufferExec } from './git-handler-ops'
|
|
|
|
const FULL_GIT_OBJECT_ID_PATTERN = /^(?:[0-9a-fA-F]{40}|[0-9a-fA-F]{64})$/
|
|
|
|
function assertFullGitObjectId(value: unknown, label: string): asserts value is string {
|
|
if (typeof value !== 'string' || !FULL_GIT_OBJECT_ID_PATTERN.test(value)) {
|
|
throw new Error(`${label} must be a full git object id`)
|
|
}
|
|
}
|
|
|
|
export function isFullGitObjectId(value: unknown): value is string {
|
|
return typeof value === 'string' && FULL_GIT_OBJECT_ID_PATTERN.test(value)
|
|
}
|
|
|
|
export function parseOptionalBranchDiffHeadOid(
|
|
params: Record<string, unknown>
|
|
): string | undefined {
|
|
const { headOid } = params
|
|
// Why: GitBranchCompareSummary.headOid is `string | null`, so a mixed-version
|
|
// client can put an explicit null on the wire. Treat it as unpinned rather
|
|
// than rejecting a request the legacy path would have served.
|
|
if (headOid == null) {
|
|
return undefined
|
|
}
|
|
assertFullGitObjectId(headOid, 'headOid')
|
|
return headOid
|
|
}
|
|
|
|
export async function branchDiffEntryAtPinnedOids(
|
|
gitBuffer: GitBufferExec,
|
|
worktreePath: string,
|
|
baseOid: string,
|
|
headOid: string,
|
|
filePath: string,
|
|
oldPath?: string
|
|
) {
|
|
assertFullGitObjectId(baseOid, 'baseRef')
|
|
assertFullGitObjectId(headOid, 'headOid')
|
|
try {
|
|
const [left, right] = await Promise.all([
|
|
readBlobAtOid(gitBuffer, worktreePath, baseOid, oldPath ?? filePath),
|
|
readBlobAtOid(gitBuffer, worktreePath, headOid, filePath)
|
|
])
|
|
return [buildDiffResult(left.content, right.content, left.isBinary, right.isBinary, filePath)]
|
|
} catch (error) {
|
|
if (isGitReadInterruptedError(error)) {
|
|
throw error
|
|
}
|
|
return [
|
|
{
|
|
kind: 'text' as const,
|
|
originalContent: '',
|
|
modifiedContent: '',
|
|
originalIsBinary: false,
|
|
modifiedIsBinary: false
|
|
}
|
|
]
|
|
}
|
|
}
|