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

Function git_head

src/watcher/watcher.c:601–629  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

599}
600
601static watcher_git_status_t git_head(cbm_watcher_t *w, project_state_t *state, char *out,
602 size_t out_size) {
603 if (!out || out_size < 2) {
604 return WATCHER_GIT_SUPERVISION_FAILED;
605 }
606 out[0] = '\0';
607 const char *argv[] = {"git", "-C", state->root_path, "rev-parse", "HEAD", NULL};
608 watcher_git_output_t output;
609 watcher_git_status_t status = watcher_git_run(w, state, argv, WATCHER_GIT_HEAD_MAX, &output);
610 if (status != WATCHER_GIT_OK) {
611 return status;
612 }
613 FILE *file = cbm_fopen(output.path, "rb");
614 bool read = file && fgets(out, (int)out_size, file) != NULL;
615 int extra = file ? fgetc(file) : EOF;
616 if (file) {
617 read = fclose(file) == 0 && read;
618 }
619 watcher_git_output_cleanup(&output);
620 if (!read || extra != EOF) {
621 out[0] = '\0';
622 return WATCHER_GIT_SUPERVISION_FAILED;
623 }
624 size_t len = strlen(out);
625 while (len > 0 && (out[len - SKIP_ONE] == '\n' || out[len - SKIP_ONE] == '\r')) {
626 out[--len] = '\0';
627 }
628 return len > 0 ? WATCHER_GIT_OK : WATCHER_GIT_COMMAND_FAILED;
629}
630
631/* ── Dirty-state signature (#937) ───────────────────────────────── */
632

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