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 <ATHundt@gmail.com>
This commit is contained in:
Andrew Hundt
2026-07-01 22:48:45 -04:00
parent c4f492b871
commit 7a32d9a29f
2 changed files with 4 additions and 6 deletions
+2 -3
View File
@@ -3,6 +3,7 @@
#include "git/git_command.h"
#include "foundation/compat.h"
#include "foundation/platform.h"
#include "foundation/str_util.h"
#include <ctype.h>
@@ -10,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
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;
}
+2 -3
View File
@@ -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 <stdio.h>
@@ -33,7 +34,6 @@
#include <string.h>
#include <time.h>
#include <stdatomic.h>
#include <sys/stat.h>
/* ── 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;