* Build hot files cache by analyzing recent commits. * Tries to use local git user's commits first, falls back to all authors.
(repoDir: string)
| 2376 | * Tries to use local git user's commits first, falls back to all authors. |
| 2377 | */ |
| 2378 | async function buildHotFilesCache(repoDir: string): Promise<Record<string, number>> { |
| 2379 | // 1. Get local git user email |
| 2380 | const emailResult = await execGit(["config", "user.email"], repoDir) |
| 2381 | const userEmail = emailResult.success ? emailResult.stdout.trim() : null |
| 2382 | |
| 2383 | // 2. Try commits by author first (if we have an email) |
| 2384 | let logResult: { success: boolean; stdout: string } = { success: false, stdout: "" } |
| 2385 | if (userEmail) { |
| 2386 | logResult = await execGit(["log", `--author=${userEmail}`, "-n", "100", "--name-only", "--pretty=format:"], repoDir) |
| 2387 | } |
| 2388 | |
| 2389 | // 3. Count lines to see if we got enough commits |
| 2390 | const authorLines = logResult.stdout.split("\n").filter((line) => line.trim()) |
| 2391 | |
| 2392 | // 4. Fallback to all authors if < 10 file entries from user's commits |
| 2393 | if (authorLines.length < 10) { |
| 2394 | logResult = await execGit(["log", "-n", "100", "--name-only", "--pretty=format:"], repoDir) |
| 2395 | } |
| 2396 | |
| 2397 | // 5. Count file occurrences |
| 2398 | const fileCounts: Record<string, number> = {} |
| 2399 | for (const line of logResult.stdout.split("\n")) { |
| 2400 | const file = line.trim() |
| 2401 | // Skip empty lines and commit metadata |
| 2402 | if (file && !file.startsWith("commit ") && !file.startsWith("Author:") && !file.startsWith("Date:")) { |
| 2403 | fileCounts[file] = (fileCounts[file] || 0) + 1 |
| 2404 | } |
| 2405 | } |
| 2406 | |
| 2407 | return fileCounts |
| 2408 | } |
| 2409 | |
| 2410 | export const __test__ = { |
| 2411 | finalizeFilePatchResponse, |
no test coverage detected