Count tracked files via git ls-files */
| 212 | |
| 213 | /* Count tracked files via git ls-files */ |
| 214 | static 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 |
no test coverage detected