|
1 | 1 | import { execFileSync } from 'node:child_process'; |
2 | 2 | import fs from 'node:fs'; |
3 | 3 | import path from 'node:path'; |
| 4 | +import { coChangeForFiles } from './cochange.js'; |
4 | 5 | import { findCycles } from './cycles.js'; |
5 | 6 | import { findDbPath, openReadonlyOrFail } from './db.js'; |
6 | 7 | import { debug } from './logger.js'; |
@@ -731,34 +732,17 @@ export function diffImpactData(customDbPath, opts = {}) { |
731 | 732 | for (const key of allAffected) affectedFiles.add(key.split(':')[0]); |
732 | 733 |
|
733 | 734 | // Look up historically coupled files from co-change data |
734 | | - const historicallyCoupled = []; |
| 735 | + let historicallyCoupled = []; |
735 | 736 | try { |
736 | 737 | db.prepare('SELECT 1 FROM co_changes LIMIT 1').get(); |
737 | 738 | const changedFilesList = [...changedRanges.keys()]; |
738 | | - const staticFiles = new Set([...changedRanges.keys(), ...affectedFiles]); |
739 | | - const placeholders = changedFilesList.map(() => '?').join(','); |
740 | | - const coRows = db |
741 | | - .prepare( |
742 | | - `SELECT file_a, file_b, commit_count, jaccard |
743 | | - FROM co_changes |
744 | | - WHERE (file_a IN (${placeholders}) OR file_b IN (${placeholders})) |
745 | | - AND jaccard >= 0.3 |
746 | | - ORDER BY jaccard DESC |
747 | | - LIMIT 20`, |
748 | | - ) |
749 | | - .all(...changedFilesList, ...changedFilesList); |
750 | | - for (const row of coRows) { |
751 | | - const partner = changedFilesList.includes(row.file_a) ? row.file_b : row.file_a; |
752 | | - const source = changedFilesList.includes(row.file_a) ? row.file_a : row.file_b; |
753 | | - if (!staticFiles.has(partner) && (!noTests || !isTestFile(partner))) { |
754 | | - historicallyCoupled.push({ |
755 | | - file: partner, |
756 | | - coupledWith: source, |
757 | | - jaccard: row.jaccard, |
758 | | - commitCount: row.commit_count, |
759 | | - }); |
760 | | - } |
761 | | - } |
| 739 | + const coResults = coChangeForFiles(changedFilesList, db, { |
| 740 | + minJaccard: 0.3, |
| 741 | + limit: 20, |
| 742 | + noTests, |
| 743 | + }); |
| 744 | + // Exclude files already found via static analysis |
| 745 | + historicallyCoupled = coResults.filter((r) => !affectedFiles.has(r.file)); |
762 | 746 | } catch { |
763 | 747 | /* co_changes table doesn't exist — skip silently */ |
764 | 748 | } |
|
0 commit comments