Skip to content

Commit e962326

Browse files
fix: filter false-positive "changed" files in incremental detection (#17)
getChangedFiles unions git-diff with git-status, but uncommitted files reported by `git status --porcelain` reappear on every run even when their content hash already matches the index. This caused misleading "Incremental: 1 changed" logs and unnecessary read+hash work inside indexFiles on every invocation. Compare content hashes in getChangedFiles itself so only truly modified files enter the changed list.
1 parent b5c2570 commit e962326

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@stainless-code/codemap": patch
3+
---
4+
5+
Fix incremental detection reporting unchanged files as "changed" on every run when the working tree has uncommitted modifications. `getChangedFiles` now compares content hashes against the index before including candidates, so only truly modified files enter the indexing pipeline.

src/application/index-engine.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,28 @@ export function getChangedFiles(db: CodemapDatabase): {
126126
.filter(Boolean)
127127
.map((line: string) => line.slice(3).trim());
128128

129-
const indexedPaths = new Set(getAllFileHashes(db).keys());
130-
const allChanged = [...new Set([...diffFiles, ...statusFiles])].filter(
129+
const existingHashes = getAllFileHashes(db);
130+
const allCandidates = [...new Set([...diffFiles, ...statusFiles])].filter(
131131
(f) => {
132132
const ext = extname(f);
133-
return ext in LANG_MAP || indexedPaths.has(f);
133+
return ext in LANG_MAP || existingHashes.has(f);
134134
},
135135
);
136136

137137
const changed: string[] = [];
138138
const deleted: string[] = [];
139139

140-
for (const f of allChanged) {
140+
for (const f of allCandidates) {
141+
const absPath = join(getProjectRoot(), f);
142+
let source: string;
141143
try {
142-
statSync(join(getProjectRoot(), f));
143-
changed.push(f);
144+
source = readFileSync(absPath, "utf-8");
144145
} catch {
145146
deleted.push(f);
147+
continue;
148+
}
149+
if (existingHashes.get(f) !== hashContent(source)) {
150+
changed.push(f);
146151
}
147152
}
148153

0 commit comments

Comments
 (0)