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

Function check_changes

src/watcher/watcher.c:1451–1498  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1449}
1450
1451static bool check_changes(cbm_watcher_t *w, project_state_t *s, bool *changed_out) {
1452 if (!changed_out) {
1453 return false;
1454 }
1455 *changed_out = false;
1456 if (!s->is_git) {
1457 return s->tree_poll ? check_tree_changes(s, changed_out) : true;
1458 }
1459
1460 bool changed = false;
1461
1462 /* Check HEAD movement (commit, checkout, pull) */
1463 s->pending_head[0] = '\0';
1464 char head[CBM_SZ_128] = {0};
1465 watcher_git_status_t head_status = git_head(w, s, head, sizeof(head));
1466 if (head_status == WATCHER_GIT_OK) {
1467 if (s->last_head[0] == '\0') {
1468 /* First observed HEAD: adopt as baseline, not a change. */
1469 snprintf(s->last_head, sizeof(s->last_head), "%s", head);
1470 } else if (strcmp(head, s->last_head) != 0) {
1471 changed = true;
1472 }
1473 snprintf(s->pending_head, sizeof(s->pending_head), "%s", head);
1474 } else if (head_status != WATCHER_GIT_COMMAND_FAILED) {
1475 return false;
1476 }
1477
1478 /* Working tree: reindex only when the DIRTY STATE ITSELF changed —
1479 * a persistently dirty tree polled while idle must not re-trigger
1480 * full reindex/write cycles (#937 write amplification). */
1481 uint64_t sig = 0;
1482 watcher_git_status_t signature_status = git_dirty_signature(w, s, &sig);
1483 if (signature_status == WATCHER_GIT_COMMAND_FAILED) {
1484 /* The repository may have been removed between baseline and poll.
1485 * Preserve committed observations and wait for a later clean probe. */
1486 return true;
1487 }
1488 if (signature_status != WATCHER_GIT_OK) {
1489 return false;
1490 }
1491 if (sig != s->last_dirty_sig) {
1492 changed = true;
1493 }
1494 s->pending_dirty_sig = sig;
1495
1496 *changed_out = changed;
1497 return true;
1498}
1499
1500/* Context for poll_once foreach callback */
1501typedef struct {

Callers 1

poll_projectFunction · 0.85

Calls 3

check_tree_changesFunction · 0.85
git_headFunction · 0.85
git_dirty_signatureFunction · 0.85

Tested by

no test coverage detected