Extract duplicated VCS path utilities into shared VcsPathUtils module

Move splitNullSeparatedPaths and chunkPathsForCheckIgnore from both
GitVcsDriver.ts and JjVcsDriver.ts into a shared VcsPathUtils.ts module
to eliminate code duplication and prevent future drift.
This commit is contained in:
Cursor Agent committed 2026-05-02 09:06:51 +00:00
1 parent e07cc3e3ae
commit 31735f3ec7
3 files changed
+45 -85

No files matched your search

+2 -43
View File
@@ -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<GitVcsDriver, GitVcsDriverShap
) {}
const WORKSPACE_FILES_MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
const GIT_CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024;
const WORKSPACE_GIT_HARDENED_CONFIG_ARGS = [
"-c",
"core.fsmonitor=false",
@@ -210,47 +210,6 @@ const WORKSPACE_GIT_HARDENED_CONFIG_ARGS = [
"core.untrackedCache=false",
] as const;
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 chunkPathsForGitCheckIgnore(relativePaths: ReadonlyArray<string>): 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<string>();
const chunks = chunkPathsForGitCheckIgnore(relativePaths);
const chunks = chunkPathsForCheckIgnore(relativePaths);
for (const chunk of chunks) {
const result = yield* gitCommand(
+1 -42
View File
@@ -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>): 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,
+42
View File
@@ -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>): 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;
}