Skip to content

Commit e2cc34f

Browse files
authored
perf(server): skip unused diffs for user-written commit messages (pingdotgg#19605)
1 parent fb9af9e commit e2cc34f

5 files changed

Lines changed: 39 additions & 3 deletions

File tree

‎apps/server/src/git/GitManager.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3804,6 +3804,13 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
38043804
Effect.gen(function* () {
38053805
const repoDir = yield* makeTempDir("t3code-git-manager-");
38063806
yield* initRepo(repoDir);
3807+
// Patch generation would invoke this unavailable converter. A supplied
3808+
// message must commit without generating a patch it will not use.
3809+
NodeFS.writeFileSync(
3810+
NodePath.join(repoDir, ".git/info/attributes"),
3811+
"README.md diff=probe\n",
3812+
);
3813+
yield* runGit(repoDir, ["config", "diff.probe.textconv", "t3-missing-textconv-for-test"]);
38073814
NodeFS.writeFileSync(NodePath.join(repoDir, "README.md"), "hello\ncustom\n");
38083815
let generatedCount = 0;
38093816

‎apps/server/src/git/GitManager.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,12 +2037,14 @@ export const make = Effect.gen(function* () {
20372037
filePaths?: readonly string[];
20382038
settings: SourceControlTextGenerationSettings;
20392039
}) {
2040-
const context = yield* gitCore.prepareCommitContext(input.cwd, input.filePaths);
2040+
const customCommit = parseCustomCommitMessage(input.commitMessage ?? "");
2041+
const context = yield* gitCore.prepareCommitContext(input.cwd, input.filePaths, {
2042+
includePatch: customCommit === null,
2043+
});
20412044
if (!context) {
20422045
return null;
20432046
}
20442047

2045-
const customCommit = parseCustomCommitMessage(input.commitMessage ?? "");
20462048
if (customCommit) {
20472049
return {
20482050
subject: customCommit.subject,

‎apps/server/src/vcs/GitVcsDriver.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ export class GitVcsDriver extends Context.Service<
306306
readonly prepareCommitContext: (
307307
cwd: string,
308308
filePaths?: readonly string[],
309+
options?: { readonly includePatch?: boolean },
309310
) => Effect.Effect<GitPreparedCommitContext | null, GitCommandError>;
310311
readonly commit: (
311312
cwd: string,

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3984,6 +3984,29 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
39843984
});
39853985

39863986
describe("commit context", () => {
3987+
it.effect("can omit the patch while preserving change detection and the real index", () =>
3988+
Effect.gen(function* () {
3989+
const cwd = yield* makeTmpDir();
3990+
yield* initRepoWithCommit(cwd);
3991+
const driver = yield* GitVcsDriver.GitVcsDriver;
3992+
assert.isNull(yield* driver.prepareCommitContext(cwd, undefined, { includePatch: false }));
3993+
yield* writeTextFile(cwd, "selected.txt", "selected content\n");
3994+
yield* writeTextFile(cwd, "other.txt", "other content\n");
3995+
yield* git(cwd, ["add", "other.txt"]);
3996+
const before = yield* git(cwd, ["diff", "--cached"]);
3997+
const summaryOnly = yield* driver.prepareCommitContext(cwd, ["selected.txt"], {
3998+
includePatch: false,
3999+
});
4000+
assert.include(summaryOnly?.stagedSummary ?? "", "selected.txt");
4001+
assert.notInclude(summaryOnly?.stagedSummary ?? "", "other.txt");
4002+
assert.equal(summaryOnly?.stagedPatch, "");
4003+
const full = yield* driver.prepareCommitContext(cwd, ["selected.txt"]);
4004+
assert.equal(full?.stagedSummary, summaryOnly?.stagedSummary);
4005+
assert.include(full?.stagedPatch ?? "", "+selected content");
4006+
assert.equal(yield* git(cwd, ["diff", "--cached"]), before);
4007+
}),
4008+
);
4009+
39874010
it.effect("prepares selected files without staging and commits only those files", () =>
39884011
Effect.gen(function* () {
39894012
const cwd = yield* makeTmpDir();

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2235,7 +2235,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
22352235
});
22362236

22372237
const prepareCommitContext: GitVcsDriver.GitVcsDriver["Service"]["prepareCommitContext"] =
2238-
Effect.fn("prepareCommitContext")(function* (cwd, filePaths) {
2238+
Effect.fn("prepareCommitContext")(function* (cwd, filePaths, options) {
22392239
return yield* Effect.scoped(
22402240
Effect.gen(function* () {
22412241
const indexValue = yield* runGitStdout(
@@ -2288,6 +2288,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
22882288
return null;
22892289
}
22902290

2291+
// A user-supplied message needs change detection, but no patch for generation.
2292+
if (options?.includePatch === false) return { stagedSummary, stagedPatch: "" };
2293+
22912294
const stagedPatch = yield* runGitStdoutWithOptions(
22922295
"GitVcsDriver.prepareCommitContext.stagedPatch",
22932296
cwd,

0 commit comments

Comments
 (0)