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

Function git_head

src/watcher/watcher.c:540–568  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

538}
539
540static watcher_git_status_t git_head(cbm_watcher_t *w, project_state_t *state, char *out,
541 size_t out_size) {
542 if (!out || out_size < 2) {
543 return WATCHER_GIT_SUPERVISION_FAILED;
544 }
545 out[0] = '\0';
546 const char *argv[] = {"git", "-C", state->root_path, "rev-parse", "HEAD", NULL};
547 watcher_git_output_t output;
548 watcher_git_status_t status = watcher_git_run(w, state, argv, WATCHER_GIT_HEAD_MAX, &output);
549 if (status != WATCHER_GIT_OK) {
550 return status;
551 }
552 FILE *file = cbm_fopen(output.path, "rb");
553 bool read = file && fgets(out, (int)out_size, file) != NULL;
554 int extra = file ? fgetc(file) : EOF;
555 if (file) {
556 read = fclose(file) == 0 && read;
557 }
558 watcher_git_output_cleanup(&output);
559 if (!read || extra != EOF) {
560 out[0] = '\0';
561 return WATCHER_GIT_SUPERVISION_FAILED;
562 }
563 size_t len = strlen(out);
564 while (len > 0 && (out[len - SKIP_ONE] == '\n' || out[len - SKIP_ONE] == '\r')) {
565 out[--len] = '\0';
566 }
567 return len > 0 ? WATCHER_GIT_OK : WATCHER_GIT_COMMAND_FAILED;
568}
569
570/* ── Dirty-state signature (#937) ───────────────────────────────── */
571

Callers 2

init_baselineFunction · 0.85
check_changesFunction · 0.85

Calls 3

watcher_git_runFunction · 0.85
cbm_fopenFunction · 0.85

Tested by

no test coverage detected