From 7a32d9a29f1980a4e9825afc48321bf0ccfd4952 Mon Sep 17 00:00:00 2001 From: Andrew Hundt Date: Wed, 1 Jul 2026 22:48:45 -0400 Subject: [PATCH] refactor(git): reuse portable existence checks Replace existence-only stat() probes in git context resolution and watcher baseline initialization with cbm_file_exists(). This removes direct sys/stat dependencies from those files without changing behavior: both paths only needed to know whether the root path exists before attempting git snapshot/command handling. Validation: make -f Makefile.cbm cbm; CBM_ONLY_SUITE=pipeline,tool_consolidation,mcp ./build/c/test-runner; scripts/check-source-safety.sh; git diff --check. Signed-off-by: Andrew Hundt --- src/git/git_context.c | 5 ++--- src/watcher/watcher.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/git/git_context.c b/src/git/git_context.c index a84c260aa..dad0917ba 100644 --- a/src/git/git_context.c +++ b/src/git/git_context.c @@ -3,6 +3,7 @@ #include "git/git_command.h" #include "foundation/compat.h" +#include "foundation/platform.h" #include "foundation/str_util.h" #include @@ -10,7 +11,6 @@ #include #include #include -#include static bool path_is_absolute(const char *path) { if (!path || !path[0]) { @@ -138,8 +138,7 @@ int cbm_git_context_resolve(const char *path, cbm_git_context_t *out) { return CBM_NOT_FOUND; } - struct stat st; - out->root_exists = (stat(path, &st) == 0); + out->root_exists = cbm_file_exists(path); if (!out->root_exists) { return 0; } diff --git a/src/watcher/watcher.c b/src/watcher/watcher.c index 83261808a..ff070d4cb 100644 --- a/src/watcher/watcher.c +++ b/src/watcher/watcher.c @@ -26,6 +26,7 @@ #include "foundation/compat.h" #include "foundation/compat_thread.h" #include "foundation/compat_fs.h" +#include "foundation/platform.h" #include "foundation/str_util.h" #include @@ -33,7 +34,6 @@ #include #include #include -#include /* ── Constants ─────────────────────────────────────────────────── */ @@ -258,8 +258,7 @@ int cbm_watcher_watch_count(cbm_watcher_t *w) { /* Init baseline for a project: check if git, get HEAD, count files */ static void init_baseline(project_state_t *s, const cbm_watcher_t *w) { - struct stat st; - if (stat(s->root_path, &st) != 0) { + if (!cbm_file_exists(s->root_path)) { cbm_log_warn("watcher.root_gone", "project", s->project_name, "path", s->root_path); s->baseline_done = true; s->is_git = false;