Skip to content

Commit 1004268

Browse files
committed
perf(git): batch context-store index writes on isomorphic-git 1.44.2
The store's per-file add/remove loop forced one index write per path; array-form add/remove stage everything inside one acquire and keep the on-error net state (nothing staged) identical via the same reset path. Multiple add failures now surface as MultipleGitError instead of the first error; the surrounding catch is type-agnostic.
1 parent a43b592 commit 1004268

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎bun.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/session/optimized-context-store.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,12 +1332,17 @@ export async function createSessionStores(
13321332
const remove = [...new Set(toRemove)].filter((p) => !add.includes(p));
13331333
extraPaths = [...new Set([...add, ...remove])];
13341334

1335-
for (const filepath of add) {
1336-
await git.add({ fs, dir, filepath });
1335+
// Array-form add/remove stages and unstages in one index write
1336+
// per call (isomorphic-git >= 1.42.7). On a mid-batch add failure
1337+
// the index is left unwritten and the catch below still resets
1338+
// every extraPath, so the all-or-nothing outcome matches the old
1339+
// per-file loop.
1340+
if (add.length > 0) {
1341+
await git.add({ fs, dir, filepath: add });
13371342
}
1338-
for (const filepath of remove) {
1343+
if (remove.length > 0) {
13391344
try {
1340-
await git.remove({ fs, dir, filepath });
1345+
await git.remove({ fs, dir, filepath: remove });
13411346
} catch {
13421347
// Already absent from the index.
13431348
}

0 commit comments

Comments
 (0)