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

Function git_file_count

src/watcher/watcher.c:837–873  ·  view source on GitHub ↗

Count tracked files via git ls-files */

Source from the content-addressed store, hash-verified

835
836/* Count tracked files via git ls-files */
837static watcher_git_status_t git_file_count(cbm_watcher_t *w, project_state_t *state,
838 int *count_out) {
839 if (!count_out) {
840 return WATCHER_GIT_SUPERVISION_FAILED;
841 }
842 *count_out = 0;
843 const char *argv[] = {"git", "-C", state->root_path, "ls-files", "-z", NULL};
844 watcher_git_output_t output;
845 watcher_git_status_t status = watcher_git_run(w, state, argv, WATCHER_GIT_OUTPUT_MAX, &output);
846 if (status != WATCHER_GIT_OK) {
847 return status;
848 }
849 FILE *fp = cbm_fopen(output.path, "rb");
850 if (!fp) {
851 watcher_git_output_cleanup(&output);
852 return WATCHER_GIT_SUPERVISION_FAILED;
853 }
854
855 /* NUL mode is unambiguous even for tracked filenames containing newlines. */
856 int count = 0;
857 char buf[CBM_SZ_1K];
858 size_t n;
859 while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) {
860 for (size_t i = 0; i < n; i++) {
861 if (buf[i] == '\0' && count < INT_MAX) {
862 count++;
863 }
864 }
865 }
866 if (ferror(fp) || fclose(fp) != 0) {
867 watcher_git_output_cleanup(&output);
868 return WATCHER_GIT_SUPERVISION_FAILED;
869 }
870 watcher_git_output_cleanup(&output);
871 *count_out = count;
872 return WATCHER_GIT_OK;
873}
874
875/* ── Non-git tree signature (#1948) ─────────────────────────────── */
876

Callers 2

init_baselineFunction · 0.85
commit_baselinesFunction · 0.85

Calls 4

watcher_git_runFunction · 0.85
cbm_fopenFunction · 0.85
freadFunction · 0.85

Tested by

no test coverage detected