fix(cli): limit concurrent git processes for untracked files

This commit is contained in:
Alex Alecu
2026-04-15 14:35:21 +03:00
parent 152e0755aa
commit 1b5832ce3f
+17 -13
View File
@@ -376,19 +376,23 @@ 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)
// 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
// Process in batches to avoid spawning hundreds of git processes
const batch = 20
for (let i = 0; i < paths.length; i += batch) {
const chunk = paths.slice(i, i + batch)
const diffs = await Promise.all(
chunk.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
}
}
}