perf(commit): reuse split diff parser
This commit is contained in:
@@ -68,6 +68,7 @@ export function createSplitCommitTool(
|
||||
const errors: string[] = [];
|
||||
const warnings: string[] = [];
|
||||
const diffText = await git.diff(cwd, { cached: true });
|
||||
const validateHunksForDiff = git.createHunkSelectionValidator(diffText);
|
||||
|
||||
const commits: SplitCommitGroup[] = params.commits.map((commit, index) => {
|
||||
const scope = commit.scope?.trim() || null;
|
||||
@@ -102,7 +103,7 @@ export function createSplitCommitTool(
|
||||
}
|
||||
warnings.push(...summaryValidation.warnings.map(warning => `Commit ${index + 1}: ${warning}`));
|
||||
warnings.push(...typeValidation.warnings.map(warning => `Commit ${index + 1}: ${warning}`));
|
||||
const hunkValidation = validateHunkSelectors(index, changes, files, diffText);
|
||||
const hunkValidation = validateHunkSelectors(index, changes, files, validateHunksForDiff);
|
||||
warnings.push(...hunkValidation.warnings);
|
||||
errors.push(...hunkValidation.errors);
|
||||
errors.push(...validateDependencies(index, dependencies, params.commits.length));
|
||||
@@ -186,7 +187,7 @@ function validateHunkSelectors(
|
||||
commitIndex: number,
|
||||
changes: SplitCommitGroup["changes"],
|
||||
files: string[],
|
||||
diffText: string,
|
||||
validateHunksForDiff: (changes: SplitCommitGroup["changes"]) => git.HunkSelectionValidationError[],
|
||||
): { errors: string[]; warnings: string[] } {
|
||||
const errors: string[] = [];
|
||||
const warnings: string[] = [];
|
||||
@@ -217,7 +218,7 @@ function validateHunkSelectors(
|
||||
}
|
||||
}
|
||||
if (errors.length === 0) {
|
||||
for (const error of git.validateHunkSelections(diffText, changes)) {
|
||||
for (const error of validateHunksForDiff(changes)) {
|
||||
errors.push(`${prefix}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user