MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / init_baseline

Function init_baseline

src/watcher/watcher.c:1049–1093  ·  view source on GitHub ↗

Init baseline for a project: check if git, get HEAD, count files */

Source from the content-addressed store, hash-verified

1047
1048/* Init baseline for a project: check if git, get HEAD, count files */
1049static bool init_baseline(cbm_watcher_t *w, project_state_t *s) {
1050 struct stat st;
1051 if (stat(s->root_path, &st) != 0) {
1052 cbm_log_warn("watcher.root_gone", "project", s->project_name, "path", s->root_path);
1053 s->baseline_done = true;
1054 s->is_git = false;
1055 return true;
1056 }
1057
1058 watcher_git_status_t repository_status = git_repo_status(w, s);
1059 if (repository_status != WATCHER_GIT_OK && repository_status != WATCHER_GIT_COMMAND_FAILED) {
1060 return false;
1061 }
1062 s->is_git = repository_status == WATCHER_GIT_OK;
1063 s->baseline_done = true;
1064
1065 if (s->is_git) {
1066 watcher_git_status_t head_status = git_head(w, s, s->last_head, sizeof(s->last_head));
1067 if (head_status != WATCHER_GIT_OK && head_status != WATCHER_GIT_COMMAND_FAILED) {
1068 s->baseline_done = false;
1069 return false;
1070 }
1071 /* last_dirty_sig stays 0 ("clean known"): a tree that is ALREADY
1072 * dirty at baseline reindexes once on the first poll — the watcher
1073 * cannot know whether that state made it into the DB (e.g. server
1074 * restart with a stale artifact). At-least-once, then the signature
1075 * gates further polls (#937). */
1076 int file_count = 0;
1077 watcher_git_status_t file_count_status = git_file_count(w, s, &file_count);
1078 if (file_count_status != WATCHER_GIT_OK &&
1079 file_count_status != WATCHER_GIT_COMMAND_FAILED) {
1080 s->baseline_done = false;
1081 return false;
1082 }
1083 s->file_count = file_count;
1084 s->interval_ms = cbm_watcher_poll_interval_ms(s->file_count);
1085 cbm_log_info("watcher.baseline", "project", s->project_name, "strategy", "git", "files",
1086 s->file_count > 0 ? "yes" : "0");
1087 } else {
1088 cbm_log_info("watcher.baseline", "project", s->project_name, "strategy", "none");
1089 }
1090
1091 s->next_poll_ns = now_ns() + ((int64_t)s->interval_ms * US_PER_MS);
1092 return true;
1093}
1094
1095/* Check if a project has changes. Returns true if reindex needed.
1096 * Must NOT mutate the committed baselines (last_head, last_dirty_sig):

Callers 1

poll_projectFunction · 0.85

Calls 6

git_repo_statusFunction · 0.85
git_headFunction · 0.85
git_file_countFunction · 0.85
statClass · 0.70
now_nsFunction · 0.70

Tested by

no test coverage detected