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

Function git_file_count

src/watcher/watcher.c:214–236  ·  view source on GitHub ↗

Count tracked files via git ls-files */

Source from the content-addressed store, hash-verified

212
213/* Count tracked files via git ls-files */
214static int git_file_count(const char *root_path) {
215 char cmd[CBM_SZ_1K];
216 snprintf(cmd, sizeof(cmd), "git -C \"%s\" ls-files 2>%s", root_path, WATCHER_NULDEV);
217 FILE *fp = cbm_popen(cmd, "r");
218 if (!fp) {
219 return 0;
220 }
221
222 /* Count newlines (one tracked file per line). `wc -l` is unavailable on
223 * Windows, so count in C, robust to paths longer than the read buffer. */
224 int count = 0;
225 char buf[CBM_SZ_1K];
226 size_t n;
227 while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) {
228 for (size_t i = 0; i < n; i++) {
229 if (buf[i] == '\n') {
230 count++;
231 }
232 }
233 }
234 cbm_pclose(fp);
235 return count;
236}
237
238/* ── Project state lifecycle ────────────────────────────────────── */
239

Callers 2

init_baselineFunction · 0.85
poll_projectFunction · 0.85

Calls 2

cbm_popenFunction · 0.85
cbm_pcloseFunction · 0.85

Tested by

no test coverage detected