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

Function determineTextStatusForFile

src/codeScan/git/diffProcessor.ts:315–362  ·  view source on GitHub ↗

* Determine text/binary status for a single file * Uses 2-tier approach: extension lists first, then blob content analysis for unknown extensions

(repoPath: string, file: FileRecord)

Source from the content-addressed store, hash-verified

313 * Uses 2-tier approach: extension lists first, then blob content analysis for unknown extensions
314 */
315async function determineTextStatusForFile(repoPath: string, file: FileRecord): Promise<FileRecord> {
316 if (file.skipReason) {
317 return file;
318 }
319
320 // Step 1: Check against known text/binary extension lists
321 const extensionType = getExtensionType(file.path);
322
323 if (extensionType === 'text') {
324 return {
325 ...file,
326 isText: true,
327 };
328 }
329
330 if (extensionType === 'binary') {
331 return {
332 ...file,
333 isText: false,
334 skipReason: 'binary',
335 };
336 }
337
338 // Step 2: For unknown extensions, analyze blob content
339 const checkSha = file.shaB || file.shaA;
340 if (!checkSha) {
341 return {
342 ...file,
343 isText: false,
344 skipReason: 'binary',
345 };
346 }
347
348 const textStatus = await isBlobText(repoPath, checkSha);
349
350 if (textStatus) {
351 return {
352 ...file,
353 isText: true,
354 };
355 } else {
356 return {
357 ...file,
358 isText: false,
359 skipReason: 'binary',
360 };
361 }
362}
363
364async function determineTextStatus(repoPath: string, files: FileRecord[]): Promise<FileRecord[]> {
365 return async.mapLimit(files, TEXT_DETECTION_CONCURRENCY, async (file: FileRecord) =>

Callers 1

determineTextStatusFunction · 0.85

Calls 2

getExtensionTypeFunction · 0.85
isBlobTextFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…