Skip to content

Commit 31735f3

Browse files
committed
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.
1 parent e07cc3e commit 31735f3

3 files changed

Lines changed: 45 additions & 85 deletions

File tree

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

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import { makeGitVcsDriverCore } from "./GitVcsDriverCore.ts";
2222
import { VcsDriver, type VcsDriverShape } from "./VcsDriver.ts";
2323
import { nowFreshness } from "./VcsFreshness.ts";
24+
import { chunkPathsForCheckIgnore, splitNullSeparatedPaths } from "./VcsPathUtils.ts";
2425
import { VcsProcess, type VcsProcessShape } from "./VcsProcess.ts";
2526

2627
export interface ExecuteGitInput {
@@ -202,55 +203,13 @@ export class GitVcsDriver extends Context.Service<GitVcsDriver, GitVcsDriverShap
202203
) {}
203204

204205
const WORKSPACE_FILES_MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
205-
const GIT_CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024;
206206
const WORKSPACE_GIT_HARDENED_CONFIG_ARGS = [
207207
"-c",
208208
"core.fsmonitor=false",
209209
"-c",
210210
"core.untrackedCache=false",
211211
] as const;
212212

213-
function splitNullSeparatedPaths(input: string, truncated: boolean): string[] {
214-
const parts = input.split("\0");
215-
if (parts.length === 0) return [];
216-
217-
if (truncated && parts[parts.length - 1]?.length) {
218-
parts.pop();
219-
}
220-
221-
return parts.filter((value) => value.length > 0);
222-
}
223-
224-
function chunkPathsForGitCheckIgnore(relativePaths: ReadonlyArray<string>): string[][] {
225-
const chunks: string[][] = [];
226-
let chunk: string[] = [];
227-
let chunkBytes = 0;
228-
229-
for (const relativePath of relativePaths) {
230-
const relativePathBytes = Buffer.byteLength(relativePath) + 1;
231-
if (chunk.length > 0 && chunkBytes + relativePathBytes > GIT_CHECK_IGNORE_MAX_STDIN_BYTES) {
232-
chunks.push(chunk);
233-
chunk = [];
234-
chunkBytes = 0;
235-
}
236-
237-
chunk.push(relativePath);
238-
chunkBytes += relativePathBytes;
239-
240-
if (chunkBytes >= GIT_CHECK_IGNORE_MAX_STDIN_BYTES) {
241-
chunks.push(chunk);
242-
chunk = [];
243-
chunkBytes = 0;
244-
}
245-
}
246-
247-
if (chunk.length > 0) {
248-
chunks.push(chunk);
249-
}
250-
251-
return chunks;
252-
}
253-
254213
const gitCommand = (
255214
process: VcsProcessShape,
256215
operation: string,
@@ -392,7 +351,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
392351
}
393352

394353
const ignoredPaths = new Set<string>();
395-
const chunks = chunkPathsForGitCheckIgnore(relativePaths);
354+
const chunks = chunkPathsForCheckIgnore(relativePaths);
396355

397356
for (const chunk of chunks) {
398357
const result = yield* gitCommand(

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

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,10 @@ import { Effect, FileSystem, Layer } from "effect";
33
import { VcsOutputDecodeError, VcsProcessExitError } from "@t3tools/contracts";
44
import { VcsDriver, type VcsDriverShape } from "./VcsDriver.ts";
55
import { nowFreshness } from "./VcsFreshness.ts";
6+
import { chunkPathsForCheckIgnore, splitNullSeparatedPaths } from "./VcsPathUtils.ts";
67
import { VcsProcess, type VcsProcessShape } from "./VcsProcess.ts";
78

89
const WORKSPACE_FILES_MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
9-
const CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024;
10-
11-
function splitNullSeparatedPaths(input: string, truncated: boolean): string[] {
12-
const parts = input.split("\0");
13-
if (parts.length === 0) return [];
14-
15-
if (truncated && parts[parts.length - 1]?.length) {
16-
parts.pop();
17-
}
18-
19-
return parts.filter((value) => value.length > 0);
20-
}
2110

2211
function splitLineSeparatedPaths(input: string, truncated: boolean): string[] {
2312
const lines = input.split(/\r?\n/g);
@@ -28,36 +17,6 @@ function splitLineSeparatedPaths(input: string, truncated: boolean): string[] {
2817
return lines.map((line) => line.trim()).filter((line) => line.length > 0);
2918
}
3019

31-
function chunkPathsForCheckIgnore(relativePaths: ReadonlyArray<string>): string[][] {
32-
const chunks: string[][] = [];
33-
let chunk: string[] = [];
34-
let chunkBytes = 0;
35-
36-
for (const relativePath of relativePaths) {
37-
const relativePathBytes = Buffer.byteLength(relativePath) + 1;
38-
if (chunk.length > 0 && chunkBytes + relativePathBytes > CHECK_IGNORE_MAX_STDIN_BYTES) {
39-
chunks.push(chunk);
40-
chunk = [];
41-
chunkBytes = 0;
42-
}
43-
44-
chunk.push(relativePath);
45-
chunkBytes += relativePathBytes;
46-
47-
if (chunkBytes >= CHECK_IGNORE_MAX_STDIN_BYTES) {
48-
chunks.push(chunk);
49-
chunk = [];
50-
chunkBytes = 0;
51-
}
52-
}
53-
54-
if (chunk.length > 0) {
55-
chunks.push(chunk);
56-
}
57-
58-
return chunks;
59-
}
60-
6120
const processCommand = (
6221
process: VcsProcessShape,
6322
command: string,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024;
2+
3+
export function splitNullSeparatedPaths(input: string, truncated: boolean): string[] {
4+
const parts = input.split("\0");
5+
if (parts.length === 0) return [];
6+
7+
if (truncated && parts[parts.length - 1]?.length) {
8+
parts.pop();
9+
}
10+
11+
return parts.filter((value) => value.length > 0);
12+
}
13+
14+
export function chunkPathsForCheckIgnore(relativePaths: ReadonlyArray<string>): string[][] {
15+
const chunks: string[][] = [];
16+
let chunk: string[] = [];
17+
let chunkBytes = 0;
18+
19+
for (const relativePath of relativePaths) {
20+
const relativePathBytes = Buffer.byteLength(relativePath) + 1;
21+
if (chunk.length > 0 && chunkBytes + relativePathBytes > CHECK_IGNORE_MAX_STDIN_BYTES) {
22+
chunks.push(chunk);
23+
chunk = [];
24+
chunkBytes = 0;
25+
}
26+
27+
chunk.push(relativePath);
28+
chunkBytes += relativePathBytes;
29+
30+
if (chunkBytes >= CHECK_IGNORE_MAX_STDIN_BYTES) {
31+
chunks.push(chunk);
32+
chunk = [];
33+
chunkBytes = 0;
34+
}
35+
}
36+
37+
if (chunk.length > 0) {
38+
chunks.push(chunk);
39+
}
40+
41+
return chunks;
42+
}

0 commit comments

Comments
 (0)