MCPcopy Create free account
hub / github.com/promptfoo/promptfoo / processDiff

Function processDiff

src/codeScan/git/diffProcessor.ts:452–511  ·  view source on GitHub ↗
(
  repoPath: string,
  base: string,
  compare: string = 'HEAD',
)

Source from the content-addressed store, hash-verified

450}
451
452export async function processDiff(
453 repoPath: string,
454 base: string,
455 compare: string = 'HEAD',
456): Promise<FileRecord[]> {
457 try {
458 // Step 1: Discover changed files
459 let files = await discoverChangedFiles(repoPath, base, compare);
460
461 if (files.length === 0) {
462 return files;
463 }
464
465 // Step 2: Filter denylist (early exit)
466 files = filterDenylist(files);
467
468 // Count remaining files
469 const remainingAfterDenylist = files.filter((f) => !f.skipReason).length;
470 if (remainingAfterDenylist === 0) {
471 return files;
472 }
473
474 // Step 3: Collect blob sizes and filter large files
475 const sizeMap = await collectBlobSizes(repoPath, files);
476 files = attachBlobSizesAndFilter(files, sizeMap);
477
478 // Count remaining files
479 const remainingAfterSizeFilter = files.filter((f) => !f.skipReason).length;
480 if (remainingAfterSizeFilter === 0) {
481 return files;
482 }
483
484 // Step 4: Determine text/binary status
485 files = await determineTextStatus(repoPath, files);
486
487 // Count remaining files
488 const remainingAfterBinaryFilter = files.filter((f) => !f.skipReason).length;
489 if (remainingAfterBinaryFilter === 0) {
490 return files;
491 }
492
493 // Step 5: Generate per-file patches
494 files = await generatePatches(repoPath, base, compare, files);
495
496 // Final count
497 const finalIncludedFiles = files.filter((f) => !f.skipReason && f.patch).length;
498 if (finalIncludedFiles === 0) {
499 return files;
500 }
501
502 return files;
503 } catch (error) {
504 if (error instanceof DiffProcessorError) {
505 throw error;
506 }
507 throw new DiffProcessorError(
508 `Failed to process diff: ${error instanceof Error ? error.message : String(error)}`,
509 );

Callers 1

executeScanFunction · 0.90

Calls 6

discoverChangedFilesFunction · 0.85
filterDenylistFunction · 0.85
collectBlobSizesFunction · 0.85
attachBlobSizesAndFilterFunction · 0.85
determineTextStatusFunction · 0.85
generatePatchesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…