The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 23:15 UTC
perf(server): avoid remote enumeration during status reads (#19802)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
IfkumRfnl committed
Oct 20, 2026 at 08:23 UTC
c1c6be8b87f8723dc147dbd2b7d147a4264bebb0
2 files changed
+34
-7
apps/server/src/vcs/GitVcsDriverCore.test.ts
+13
-4
@@ -3542,14 +3542,16 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
3542
yield* git(cwd, ["symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/trunk"]);
3543
3544
const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
3545
+ const commands: ReadonlyArray<string>[] = [];
3546
let originHeadReads = 0;
3547
let failFirstOriginHead = false;
3548
const spawner = ChildProcessSpawner.make((command) =>
3549
Effect.gen(function* () {
3549
- if (
3550
- ChildProcess.isStandardCommand(command) &&
3551
- command.args.join(" ") === "symbolic-ref refs/remotes/origin/HEAD"
3552
- ) {
3550
+ if (!ChildProcess.isStandardCommand(command)) {
3551
+ return yield* Effect.die("expected a standard Git command");
3552
+ }
3553
+ commands.push(command.args);
3554
+ if (command.args.join(" ") === "symbolic-ref refs/remotes/origin/HEAD") {
3555
originHeadReads++;
3556
if (failFirstOriginHead && originHeadReads === 1) return makeNonRepositoryHandle();
3557
}
@@ -3565,12 +3567,19 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
3567
assert.equal(status.isRepo, true);
3568
assert.equal(status.branch, "feature/remote-status");
3569
assert.equal(status.defaultBranch, "trunk");
3570
+ assert.equal(status.isDefaultBranch, false);
3571
+ assert.equal(status.upstreamRef, "origin/feature/remote-status");
3572
assert.equal(status.hasUpstream, true);
3573
assert.equal(status.aheadCount, 0);
3574
assert.equal(status.behindCount, 0);
3575
assert.equal(status.aheadOfDefaultCount, 1);
3576
assert.notProperty(status, "workingTree");
3577
assert.notProperty(status, "hasWorkingTreeChanges");
3578
+ assert.deepEqual(
3579
+ commands.filter((args) => args.length === 1 && args[0] === "remote"),
3580
+ [],
3581
+ `cached remote status should not enumerate remotes: ${JSON.stringify(commands)}`,
3582
+ );
3583
assert.equal(originHeadReads, 1);
3584
3585
// With no main/master fallback, the retry must resolve trunk to preserve the ahead count.
apps/server/src/vcs/GitVcsDriverCore.ts
+21
-3
@@ -1233,7 +1233,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1233
});
1234
});
1235
1236
- const resolveCurrentUpstream = Effect.fn("resolveCurrentUpstream")(function* (cwd: string) {
1236
+ const readCurrentUpstreamRef = Effect.fn("readCurrentUpstreamRef")(function* (cwd: string) {
1237
const upstreamRef = yield* runGitStdout(
1238
"GitVcsDriver.resolveCurrentUpstream",
1239
cwd,
@@ -1244,6 +1244,17 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1244
if (upstreamRef.length === 0 || upstreamRef === "@{upstream}") {
1245
return null;
1246
}
1247
+ return upstreamRef;
1248
+ });
1249
+
1250
+ const resolveCurrentUpstream = Effect.fn("resolveCurrentUpstream")(function* (
1251
+ cwd: string,
1252
+ knownUpstreamRef?: string,
1253
+ ) {
1254
+ const upstreamRef = knownUpstreamRef ?? (yield* readCurrentUpstreamRef(cwd));
1255
+ if (upstreamRef === null) {
1256
+ return null;
1257
+ }
1258
1259
const remoteNames = yield* runGitStdout("GitVcsDriver.listRemoteNames", cwd, ["remote"]).pipe(
1260
Effect.map(parseRemoteNames),
@@ -1923,8 +1934,15 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1934
const branchValue = branchResult.stdout.trim();
1935
branch = branchValue.length > 0 && branchValue !== "HEAD" ? branchValue : null;
1936
}
1926
- const upstream = yield* resolveCurrentUpstream(cwd);
1927
- const upstreamRef = upstream?.upstreamRef ?? null;
1937
+ const currentUpstreamRef = yield* readCurrentUpstreamRef(cwd);
1938
+ let upstreamRef =
1939
+ currentUpstreamRef === null
1940
+ ? null
1941
+ : (parseUpstreamRefByFirstSeparator(currentUpstreamRef)?.upstreamRef ?? null);
1942
+ // Trimming a remote that starts with Unicode whitespace can leave a leading slash.
1943
+ if (currentUpstreamRef?.startsWith("/")) {
1944
+ upstreamRef = (yield* resolveCurrentUpstream(cwd, currentUpstreamRef))?.upstreamRef ?? null;
1945
+ }
1946
let aheadCount = 0;
1947
let behindCount = 0;
1948