MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / getChangedFiles

Method getChangedFiles

src/extraction/index.ts:4330–4428  ·  view source on GitHub ↗

* Get files that have changed since last index. * Uses git status as a fast path when available, falling back to full scan.

()

Source from the content-addressed store, hash-verified

4328 * Uses git status as a fast path when available, falling back to full scan.
4329 */
4330 getChangedFiles(): { added: string[]; modified: string[]; removed: string[] } {
4331 // The commit this index was last brought up to date at. Absent on an index
4332 // built before stamping existed — getGitChangedFiles then declines the fast
4333 // path and the full scan below answers correctly, once, until a sync or a
4334 // full index writes the stamp. (#1829)
4335 let sinceCommit: string | null = null;
4336 try { sinceCommit = this.queries.getMetadata(INDEXED_AT_COMMIT_KEY) ?? null; } catch { /* advisory */ }
4337 const dirtyPaths = this.indexedDirtyPaths(sinceCommit);
4338 const gitChanges = dirtyPaths !== null && canTrustGitFastPath(this.rootDir, sinceCommit)
4339 ? getGitChangedFiles(this.rootDir, sinceCommit)
4340 : null;
4341
4342 if (gitChanges) {
4343 // === Git fast path ===
4344 const added: string[] = [];
4345 const modified: string[] = [];
4346 const removed: string[] = [];
4347
4348 // Git supplies candidates, never the verdict. A committed deletion may
4349 // have been recreated locally; a previously indexed dirty path may have
4350 // vanished from git status after restore. Classify current disk vs DB once.
4351 const candidates = new Set([...gitChanges.deleted, ...gitChanges.modified, ...gitChanges.added, ...dirtyPaths!, ...this.sparseCheckoutChanges(), ...this.includedFileChanges()]);
4352 const scope = this.scopedSyncMatcher();
4353 const overrides = loadExtensionOverrides(this.rootDir);
4354 for (const filePath of candidates) {
4355 const tracked = this.queries.getFileByPath(filePath);
4356 const fullPath = path.join(this.rootDir, filePath);
4357 if (!isSourceFile(filePath, overrides, this.rootDir) || scope.ignores(filePath) || !fs.existsSync(fullPath)) {
4358 if (tracked) removed.push(filePath);
4359 continue;
4360 }
4361 let content: string | null;
4362 try { content = readSourceOrStamp(fullPath); }
4363 catch (error) {
4364 logDebug('Skipping unreadable file while detecting changes', { filePath, error: String(error) });
4365 continue;
4366 }
4367 // A `.ts` that is an MPEG transport stream is not source (#1910), so an
4368 // untracked clip is never pending and a tracked file that became one is gone.
4369 if (content === null) {
4370 if (tracked) removed.push(filePath);
4371 continue;
4372 }
4373 if (!tracked) added.push(filePath);
4374 else if (tracked.contentHash !== hashContent(content)) modified.push(filePath);
4375 }
4376
4377 return { added, modified, removed };
4378 }
4379
4380 // === Fallback: full scan (non-git project or git failure) ===
4381 const currentFiles = new Set(scanDirectory(this.rootDir));
4382 const trackedFiles = this.queries.getAllFiles();
4383
4384 // Build Map for O(1) lookups
4385 const trackedMap = new Map<string, FileRecord>();
4386 for (const f of trackedFiles) {
4387 trackedMap.set(f.path, f);

Callers 2

mainFunction · 0.45

Calls 15

indexedDirtyPathsMethod · 0.95
sparseCheckoutChangesMethod · 0.95
includedFileChangesMethod · 0.95
scopedSyncMatcherMethod · 0.95
loadExtensionOverridesFunction · 0.90
isSourceFileFunction · 0.90
logDebugFunction · 0.90
canTrustGitFastPathFunction · 0.85
getGitChangedFilesFunction · 0.85
readSourceOrStampFunction · 0.85
hashContentFunction · 0.85
scanDirectoryFunction · 0.85

Tested by

no test coverage detected