diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.ts index 9a0d24b98b..c8b1bcfd28 100644 --- a/apps/server/src/vcs/GitVcsDriver.ts +++ b/apps/server/src/vcs/GitVcsDriver.ts @@ -21,6 +21,7 @@ import { import { makeGitVcsDriverCore } from "./GitVcsDriverCore.ts"; import { VcsDriver, type VcsDriverShape } from "./VcsDriver.ts"; import { nowFreshness } from "./VcsFreshness.ts"; +import { chunkPathsForCheckIgnore, splitNullSeparatedPaths } from "./VcsPathUtils.ts"; import { VcsProcess, type VcsProcessShape } from "./VcsProcess.ts"; export interface ExecuteGitInput { @@ -202,7 +203,6 @@ export class GitVcsDriver extends Context.Service value.length > 0); -} - -function chunkPathsForGitCheckIgnore(relativePaths: ReadonlyArray): string[][] { - const chunks: string[][] = []; - let chunk: string[] = []; - let chunkBytes = 0; - - for (const relativePath of relativePaths) { - const relativePathBytes = Buffer.byteLength(relativePath) + 1; - if (chunk.length > 0 && chunkBytes + relativePathBytes > GIT_CHECK_IGNORE_MAX_STDIN_BYTES) { - chunks.push(chunk); - chunk = []; - chunkBytes = 0; - } - - chunk.push(relativePath); - chunkBytes += relativePathBytes; - - if (chunkBytes >= GIT_CHECK_IGNORE_MAX_STDIN_BYTES) { - chunks.push(chunk); - chunk = []; - chunkBytes = 0; - } - } - - if (chunk.length > 0) { - chunks.push(chunk); - } - - return chunks; -} - const gitCommand = ( process: VcsProcessShape, operation: string, @@ -392,7 +351,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( } const ignoredPaths = new Set(); - const chunks = chunkPathsForGitCheckIgnore(relativePaths); + const chunks = chunkPathsForCheckIgnore(relativePaths); for (const chunk of chunks) { const result = yield* gitCommand( diff --git a/apps/server/src/vcs/JjVcsDriver.ts b/apps/server/src/vcs/JjVcsDriver.ts index 052ea36b5f..7831ab283b 100644 --- a/apps/server/src/vcs/JjVcsDriver.ts +++ b/apps/server/src/vcs/JjVcsDriver.ts @@ -3,21 +3,10 @@ import { Effect, FileSystem, Layer } from "effect"; import { VcsOutputDecodeError, VcsProcessExitError } from "@t3tools/contracts"; import { VcsDriver, type VcsDriverShape } from "./VcsDriver.ts"; import { nowFreshness } from "./VcsFreshness.ts"; +import { chunkPathsForCheckIgnore, splitNullSeparatedPaths } from "./VcsPathUtils.ts"; import { VcsProcess, type VcsProcessShape } from "./VcsProcess.ts"; const WORKSPACE_FILES_MAX_OUTPUT_BYTES = 16 * 1024 * 1024; -const CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024; - -function splitNullSeparatedPaths(input: string, truncated: boolean): string[] { - const parts = input.split("\0"); - if (parts.length === 0) return []; - - if (truncated && parts[parts.length - 1]?.length) { - parts.pop(); - } - - return parts.filter((value) => value.length > 0); -} function splitLineSeparatedPaths(input: string, truncated: boolean): string[] { const lines = input.split(/\r?\n/g); @@ -28,36 +17,6 @@ function splitLineSeparatedPaths(input: string, truncated: boolean): string[] { return lines.map((line) => line.trim()).filter((line) => line.length > 0); } -function chunkPathsForCheckIgnore(relativePaths: ReadonlyArray): string[][] { - const chunks: string[][] = []; - let chunk: string[] = []; - let chunkBytes = 0; - - for (const relativePath of relativePaths) { - const relativePathBytes = Buffer.byteLength(relativePath) + 1; - if (chunk.length > 0 && chunkBytes + relativePathBytes > CHECK_IGNORE_MAX_STDIN_BYTES) { - chunks.push(chunk); - chunk = []; - chunkBytes = 0; - } - - chunk.push(relativePath); - chunkBytes += relativePathBytes; - - if (chunkBytes >= CHECK_IGNORE_MAX_STDIN_BYTES) { - chunks.push(chunk); - chunk = []; - chunkBytes = 0; - } - } - - if (chunk.length > 0) { - chunks.push(chunk); - } - - return chunks; -} - const processCommand = ( process: VcsProcessShape, command: string, diff --git a/apps/server/src/vcs/VcsPathUtils.ts b/apps/server/src/vcs/VcsPathUtils.ts new file mode 100644 index 0000000000..6d93cdfa4f --- /dev/null +++ b/apps/server/src/vcs/VcsPathUtils.ts @@ -0,0 +1,42 @@ +const CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024; + +export function splitNullSeparatedPaths(input: string, truncated: boolean): string[] { + const parts = input.split("\0"); + if (parts.length === 0) return []; + + if (truncated && parts[parts.length - 1]?.length) { + parts.pop(); + } + + return parts.filter((value) => value.length > 0); +} + +export function chunkPathsForCheckIgnore(relativePaths: ReadonlyArray): string[][] { + const chunks: string[][] = []; + let chunk: string[] = []; + let chunkBytes = 0; + + for (const relativePath of relativePaths) { + const relativePathBytes = Buffer.byteLength(relativePath) + 1; + if (chunk.length > 0 && chunkBytes + relativePathBytes > CHECK_IGNORE_MAX_STDIN_BYTES) { + chunks.push(chunk); + chunk = []; + chunkBytes = 0; + } + + chunk.push(relativePath); + chunkBytes += relativePathBytes; + + if (chunkBytes >= CHECK_IGNORE_MAX_STDIN_BYTES) { + chunks.push(chunk); + chunk = []; + chunkBytes = 0; + } + } + + if (chunk.length > 0) { + chunks.push(chunk); + } + + return chunks; +}