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

Function git_file_count

src/watcher/watcher.c:659–695  ·  view source on GitHub ↗

Count tracked files via git ls-files */

Source from the content-addressed store, hash-verified

657
658/* Count tracked files via git ls-files */
659static watcher_git_status_t git_file_count(cbm_watcher_t *w, project_state_t *state,
660 int *count_out) {
661 if (!count_out) {
662 return WATCHER_GIT_SUPERVISION_FAILED;
663 }
664 *count_out = 0;
665 const char *argv[] = {"git", "-C", state->root_path, "ls-files", "-z", NULL};
666 watcher_git_output_t output;
667 watcher_git_status_t status = watcher_git_run(w, state, argv, WATCHER_GIT_OUTPUT_MAX, &output);
668 if (status != WATCHER_GIT_OK) {
669 return status;
670 }
671 FILE *fp = cbm_fopen(output.path, "rb");
672 if (!fp) {
673 watcher_git_output_cleanup(&output);
674 return WATCHER_GIT_SUPERVISION_FAILED;
675 }
676
677 /* NUL mode is unambiguous even for tracked filenames containing newlines. */
678 int count = 0;
679 char buf[CBM_SZ_1K];
680 size_t n;
681 while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) {
682 for (size_t i = 0; i < n; i++) {
683 if (buf[i] == '\0' && count < INT_MAX) {
684 count++;
685 }
686 }
687 }
688 if (ferror(fp) || fclose(fp) != 0) {
689 watcher_git_output_cleanup(&output);
690 return WATCHER_GIT_SUPERVISION_FAILED;
691 }
692 watcher_git_output_cleanup(&output);
693 *count_out = count;
694 return WATCHER_GIT_OK;
695}
696
697/* ── Project state lifecycle ────────────────────────────────────── */
698

Callers 2

init_baselineFunction · 0.85
poll_projectFunction · 0.85

Calls 3

watcher_git_runFunction · 0.85
cbm_fopenFunction · 0.85

Tested by

no test coverage detected