fix(cli): parallelize git diff for untracked files in review

Sequential git diff --no-index per untracked file was slow in repos
with many untracked files (e.g. after build or codegen). Run all
diffs concurrently with Promise.all.
This commit is contained in:
Alex Alecu
2026-04-15 11:56:48 +03:00
parent bab81482a9
commit 543660bc8d
@@ -376,13 +376,18 @@ export namespace Review {
const untracked = await $`git ls-files --others --exclude-standard -z`.cwd(Instance.directory).quiet().nothrow()
if (untracked.exitCode === 0) {
const paths = untracked.stdout.toString().split("\0").filter(Boolean)
for (const p of paths) {
// --no-index exits 1 when files differ, which is expected
const fd = await $`git -c core.quotepath=false diff --no-index -- /dev/null ${p}`
.cwd(Instance.directory)
.quiet()
.nothrow()
const out = fd.stdout.toString()
// Run diffs in parallel — sequential spawns are slow with many untracked files
const diffs = await Promise.all(
paths.map((p) =>
// --no-index exits 1 when files differ, which is expected
$`git -c core.quotepath=false diff --no-index -- /dev/null ${p}`
.cwd(Instance.directory)
.quiet()
.nothrow()
.then((fd) => fd.stdout.toString()),
),
)
for (const out of diffs) {
if (out) raw += out
}
}