Init baseline for a project: check if git, get HEAD, count files */
| 484 | |
| 485 | /* Init baseline for a project: check if git, get HEAD, count files */ |
| 486 | static void init_baseline(project_state_t *s) { |
| 487 | struct stat st; |
| 488 | if (stat(s->root_path, &st) != 0) { |
| 489 | cbm_log_warn("watcher.root_gone", "project", s->project_name, "path", s->root_path); |
| 490 | s->baseline_done = true; |
| 491 | s->is_git = false; |
| 492 | return; |
| 493 | } |
| 494 | |
| 495 | s->is_git = is_git_repo(s->root_path); |
| 496 | s->baseline_done = true; |
| 497 | |
| 498 | if (s->is_git) { |
| 499 | git_head(s->root_path, s->last_head, sizeof(s->last_head)); |
| 500 | s->file_count = git_file_count(s->root_path); |
| 501 | s->interval_ms = cbm_watcher_poll_interval_ms(s->file_count); |
| 502 | cbm_log_info("watcher.baseline", "project", s->project_name, "strategy", "git", "files", |
| 503 | s->file_count > 0 ? "yes" : "0"); |
| 504 | } else { |
| 505 | cbm_log_info("watcher.baseline", "project", s->project_name, "strategy", "none"); |
| 506 | } |
| 507 | |
| 508 | s->next_poll_ns = now_ns() + ((int64_t)s->interval_ms * US_PER_MS); |
| 509 | } |
| 510 | |
| 511 | /* Check if a project has changes. Returns true if reindex needed. */ |
| 512 | static bool check_changes(project_state_t *s) { |
no test coverage detected