Files
orca/src/main/git/source-control/branch-diff.ts
T
Neil d6918c7a1d fix(remote-files): cap search replies, say when a diff is too large, and measure a 100 MB read on WSL (#34882)
Follow-ups from the large-file audit (E7):

- files.search had no byte budget: a result past the remote reply cap failed outright with
  reply_too_large. It now keeps the whole files that fit and marks the result truncated, as
  files.listAll and searchPaths already do. Local callers stay uncapped.
- A diff side past the 10 MiB read cap came back as binary, so the diff said "Binary file
  changed" for a large text file. Blob reads mark it `tooLarge`, the binary diff result carries an
  optional `tooLarge`, and both diff views say "File too large to diff". Older clients ignore the
  field and keep the binary view. buildDiffResult builds its binary sides without a cast.
- The real-WSL lane pages a 100 MB file over the plain distro's shared control socket in the
  editor's 384 KiB chunks and records the time, chunk count and orcad's VmHWM. Record-only: it
  asserts nothing, and a failure is recorded in the receipt.
2026-10-28 02:01:16 -07:00

69 lines
1.9 KiB
TypeScript

import type { GitDiffResult } from '../../../shared/git-diff-compare-types'
import { stableInFlightKey } from '../../../shared/in-flight-promise-dedupe'
import type { GitRuntimeOptions } from '../git-runtime-options'
import { gitRuntimeOptionsKey } from './git-runtime-options-cache-key'
import { gitDiffReadDedupe } from './git-read-cache-invalidation'
import { buildDiffResult } from './diff-result'
import { readGitBlobAtOidPath } from './git-blob-read'
export async function getBranchDiff(
worktreePath: string,
args: {
headOid: string
mergeBase: string
filePath: string
oldPath?: string
},
options: GitRuntimeOptions = {}
): Promise<GitDiffResult> {
return gitDiffReadDedupe.run(
stableInFlightKey([
'branchDiff',
worktreePath,
args.headOid,
args.mergeBase,
args.filePath,
args.oldPath ?? null,
...gitRuntimeOptionsKey(options)
]),
() => loadBranchDiff(worktreePath, args, options)
)
}
async function loadBranchDiff(
worktreePath: string,
args: {
headOid: string
mergeBase: string
filePath: string
oldPath?: string
},
options: GitRuntimeOptions
): Promise<GitDiffResult> {
try {
const leftPath = args.oldPath ?? args.filePath
// Read independent blobs concurrently to avoid doubling diff latency.
const [leftBlob, rightBlob] = await Promise.all([
readGitBlobAtOidPath(worktreePath, args.mergeBase, leftPath, options),
readGitBlobAtOidPath(worktreePath, args.headOid, args.filePath, options)
])
return buildDiffResult(
leftBlob.content,
rightBlob.content,
leftBlob.isBinary,
rightBlob.isBinary,
args.filePath,
leftBlob.tooLarge === true || rightBlob.tooLarge === true
)
} catch {
return {
kind: 'text',
originalContent: '',
modifiedContent: '',
originalIsBinary: false,
modifiedIsBinary: false
}
}
}