Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/server/src/vcs/GitVcsDriverCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,25 @@ it.effect("uses stable diagnostics for every parsed non-repository command", ()
}).pipe(Effect.provide(layer));
});

it.effect(
"returns consistent default branch and origin remote across repeated local status calls",
() =>
Effect.gen(function* () {
const driver = yield* GitVcsDriver.GitVcsDriver;
const cwd = yield* makeTmpDir();
const { initialBranch } = yield* initRepoWithCommit(cwd);

const a = yield* driver.statusDetailsLocal(cwd);
const b = yield* driver.statusDetailsLocal(cwd);

assert.equal(a.isRepo, true);
assert.equal(a.branch, initialBranch);
assert.equal(a.isDefaultBranch, b.isDefaultBranch);
assert.equal(a.hasOriginRemote, b.hasOriginRemote);
assert.equal(a.hasWorkingTreeChanges, false);
}).pipe(Effect.provide(TestLayer)),
);
Comment thread
macroscopeapp[bot] marked this conversation as resolved.
Outdated

it.effect("coalesces concurrent ref pages into one repository snapshot", () =>
Effect.scoped(
Effect.gen(function* () {
Expand Down
48 changes: 35 additions & 13 deletions apps/server/src/vcs/GitVcsDriverCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const LIST_REFS_SNAPSHOT_CACHE_CAPACITY = 64;
const LIST_REFS_SNAPSHOT_CACHE_TTL = Duration.minutes(2);
const LIST_REFS_REFRESH_COALESCE_TTL = Duration.seconds(5);
const LIST_REFS_REFRESH_FAILURE_COOLDOWN = Duration.seconds(30);
const STATUS_DEFAULT_BRANCH_CACHE_TTL = Duration.minutes(5);
const STATUS_ORIGIN_EXISTS_CACHE_TTL = Duration.minutes(5);
const STATUS_UPSTREAM_REFRESH_ENV = Object.freeze({
GCM_INTERACTIVE: "never",
GIT_ASKPASS: "",
Expand Down Expand Up @@ -1119,6 +1121,27 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
return Cache.get(refresh ? repositoryPathsRefreshCache : repositoryPathsCache, cacheKey);
};

const defaultBranchCache = yield* Cache.makeWith(
(cwd: string) => resolveDefaultBranchName(cwd, "origin").pipe(Effect.orElseSucceed(() => null)),
{
capacity: 2_048,
timeToLive: () => STATUS_DEFAULT_BRANCH_CACHE_TTL,
},
);
const originExistsCache = yield* Cache.makeWith(
(cwd: string) => originRemoteExists(cwd).pipe(Effect.orElseSucceed(() => false)),
{
capacity: 2_048,
timeToLive: () => STATUS_ORIGIN_EXISTS_CACHE_TTL,
},
Comment thread
cursor[bot] marked this conversation as resolved.
);
const invalidateStatusStaticCaches = (cwd: string) =>
Effect.gen(function* () {
const cacheKey = normalizeRepositoryPathsCacheKey(cwd);
yield* Cache.invalidate(defaultBranchCache, cacheKey);
yield* Cache.invalidate(originExistsCache, cacheKey);
});
Comment thread
UtkarshUsername marked this conversation as resolved.
Comment thread
macroscopeapp[bot] marked this conversation as resolved.
Comment thread
cursor[bot] marked this conversation as resolved.

const resolveGitCommonDir = Effect.fn("resolveGitCommonDir")(function* (cwd: string) {
const repositoryPaths = yield* resolveRepositoryPaths(cwd);
if (repositoryPaths !== null) {
Expand Down Expand Up @@ -1517,7 +1540,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
});
}

const [numstatStdout, defaultRefResult, hasPrimaryRemote] = yield* Effect.all(
const statusCacheKey = normalizeRepositoryPathsCacheKey(cwd);
const [numstatStdout, defaultBranch, hasPrimaryRemote] = yield* Effect.all(
[
executeGitWithStableDiagnostics(
"GitVcsDriver.statusDetails.numstat",
Expand Down Expand Up @@ -1574,21 +1598,12 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
);
}),
),
executeGit(
"GitVcsDriver.statusDetails.defaultRef",
cwd,
["symbolic-ref", "refs/remotes/origin/HEAD"],
{ allowNonZeroExit: true },
),
originRemoteExists(cwd).pipe(Effect.orElseSucceed(() => false)),
Cache.get(defaultBranchCache, statusCacheKey),
Cache.get(originExistsCache, statusCacheKey),
],
{ concurrency: "unbounded" },
);
const statusStdout = statusResult.stdout;
const defaultBranch =
defaultRefResult.exitCode === 0
? defaultRefResult.stdout.trim().replace(/^refs\/remotes\/origin\//, "")
: null;

let refName: string | null = null;
let upstreamRef: string | null = null;
Expand Down Expand Up @@ -2809,7 +2824,14 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
cwd: string,
effect: Effect.Effect<A, E>,
): Effect.Effect<A, E> =>
effect.pipe(Effect.ensuring(invalidateListRefsSnapshot(cwd).pipe(Effect.ignore)));
effect.pipe(
Effect.ensuring(
Effect.all([
invalidateListRefsSnapshot(cwd).pipe(Effect.ignore),
invalidateStatusStaticCaches(cwd).pipe(Effect.ignore),
]),
),
);
Comment thread
UtkarshUsername marked this conversation as resolved.
Comment thread
UtkarshUsername marked this conversation as resolved.
const initRepoWithListRefsInvalidation: GitVcsDriver.GitVcsDriver["Service"]["initRepo"] = (
input,
) =>
Expand Down
Loading