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

Function init_baseline

src/watcher/watcher.c:1340–1426  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1338
1339/* Init baseline for a project: check if git, get HEAD, count files */
1340static bool init_baseline(cbm_watcher_t *w, project_state_t *s) {
1341 struct stat st;
1342 if (stat(s->root_path, &st) != 0) {
1343 cbm_log_warn("watcher.root_gone", "project", s->project_name, "path", s->root_path);
1344 s->baseline_done = true;
1345 s->is_git = false;
1346 publish_status(s, false);
1347 return true;
1348 }
1349
1350 watcher_git_status_t repository_status = git_repo_status(w, s);
1351 if (repository_status != WATCHER_GIT_OK && repository_status != WATCHER_GIT_COMMAND_FAILED) {
1352 return false;
1353 }
1354 s->is_git = repository_status == WATCHER_GIT_OK;
1355
1356 /* `rev-parse --git-dir` walks UP, so an ordinary folder that merely happens
1357 * to live under some unrelated repository answers yes. Treating it as a git
1358 * project is what produced the runaway churn: it inherits the ancestor's
1359 * dirty state, which is permanently non-empty and has nothing to do with
1360 * this directory, so every poll looked like a change.
1361 *
1362 * A directory is only really git-managed here if it carries its own .git,
1363 * or the ancestor repository actually tracks something inside it. A
1364 * genuine sub-package of a monorepo passes the second test; a scratch or
1365 * gitignored folder sitting under a repo fails both and is treated as a
1366 * non-git root: NOT polled by default, or polled by its own tree signature
1367 * when the watch_non_git opt-in is on (#1948). Either way the ancestor's
1368 * dirty state never reaches it. */
1369 if (s->is_git && !git_has_own_dot_git(s->root_path)) {
1370 bool tracked = false;
1371 watcher_git_status_t tracked_status = git_tracks_anything_here(w, s, &tracked);
1372 if (tracked_status != WATCHER_GIT_OK && tracked_status != WATCHER_GIT_COMMAND_FAILED) {
1373 return false;
1374 }
1375 if (!tracked) {
1376 s->is_git = false;
1377 cbm_log_info("watcher.nested_non_git", "project", s->project_name, "path",
1378 s->root_path);
1379 }
1380 }
1381
1382 s->baseline_done = true;
1383
1384 if (s->is_git) {
1385 watcher_git_status_t cdup_status = git_repo_cdup(w, s, s->repo_cdup, sizeof(s->repo_cdup));
1386 if (cdup_status != WATCHER_GIT_OK && cdup_status != WATCHER_GIT_COMMAND_FAILED) {
1387 s->baseline_done = false;
1388 return false;
1389 }
1390 watcher_git_status_t head_status = git_head(w, s, s->last_head, sizeof(s->last_head));
1391 if (head_status != WATCHER_GIT_OK && head_status != WATCHER_GIT_COMMAND_FAILED) {
1392 s->baseline_done = false;
1393 return false;
1394 }
1395 /* last_dirty_sig stays 0 ("clean known"): a tree that is ALREADY
1396 * dirty at baseline reindexes once on the first poll — the watcher
1397 * cannot know whether that state made it into the DB (e.g. server

Callers 1

poll_projectFunction · 0.85

Calls 10

publish_statusFunction · 0.85
git_repo_statusFunction · 0.85
git_has_own_dot_gitFunction · 0.85
git_tracks_anything_hereFunction · 0.85
git_repo_cdupFunction · 0.85
git_headFunction · 0.85
git_file_countFunction · 0.85
statClass · 0.70
now_nsFunction · 0.70

Tested by

no test coverage detected