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

Function discover_impl

src/discover/discover.c:1107–1257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1105}
1106
1107static cbm_discover_status_t discover_impl(const char *repo_path, const cbm_discover_opts_t *opts,
1108 cbm_file_info_t **out, int *count, char ***excluded_out,
1109 int *excluded_count_out,
1110 cbm_ignored_file_t **ignored_out, int *ignored_count_out,
1111 int *ignored_total_out, bool count_only, int max_files,
1112 uint64_t deadline_ms) {
1113 if (excluded_out) {
1114 *excluded_out = NULL;
1115 }
1116 if (excluded_count_out) {
1117 *excluded_count_out = 0;
1118 }
1119 if (ignored_out) {
1120 *ignored_out = NULL;
1121 }
1122 if (ignored_count_out) {
1123 *ignored_count_out = 0;
1124 }
1125 if (ignored_total_out) {
1126 *ignored_total_out = 0;
1127 }
1128 if (!repo_path || !out || !count || (count_only && max_files < 0)) {
1129 return CBM_DISCOVER_ERROR;
1130 }
1131
1132 *out = NULL;
1133 *count = 0;
1134
1135 /* Verify directory exists */
1136 struct stat st;
1137 if (wide_stat(repo_path, &st) != 0 || !S_ISDIR(st.st_mode)) {
1138 return CBM_DISCOVER_ERROR;
1139 }
1140
1141 /* Load gitignore sources for ordinary repos AND linked worktrees.
1142 * Sources merged in order (later patterns win on conflict):
1143 * 1. <repo>/.gitignore — committed exclusions
1144 * 2. <common>/info/exclude — per-clone exclusions, not committed
1145 * <common> is the git common dir, resolved via resolve_git_common_dir() so a
1146 * worktree (where .git is a gitlink file) reads the shared info/exclude/config
1147 * just like a normal checkout. Both are folded into a single matcher so all
1148 * downstream call paths remain unchanged. Fixes issue #489: OOM on repos whose
1149 * worktrees are excluded only via .git/info/exclude (e.g. Sandcastle). */
1150 cbm_gitignore_t *gitignore = NULL;
1151 char gi_path[CBM_SZ_4K];
1152 struct stat gi_stat;
1153 /* Resolve the git common dir, transparently following a worktree gitlink so the
1154 * .git/info/exclude and core.excludesfile sources are honoured inside linked
1155 * worktrees too (where .git is a file pointing at the shared dir, not a directory). */
1156 char git_common_dir[CBM_SZ_4K];
1157 bool is_git_repo = resolve_git_common_dir(repo_path, git_common_dir, sizeof(git_common_dir));
1158 bool has_git_config = false;
1159 /* Always honour the .gitignore at the indexed-directory root, even when the
1160 * directory is not a git repo root (e.g. indexing a sub-package directly).
1161 * Fixes issue #510: a root .gitignore was silently ignored without .git/. */
1162 snprintf(gi_path, sizeof(gi_path), "%s/.gitignore", repo_path);
1163 gitignore = cbm_gitignore_load(gi_path);
1164 if (is_git_repo) {

Callers 2

cbm_discover_ex2Function · 0.85

Calls 12

wide_statFunction · 0.85
resolve_git_common_dirFunction · 0.85
cbm_gitignore_loadFunction · 0.85
path_joinFunction · 0.85
cbm_gitignore_mergeFunction · 0.85
cbm_gitignore_freeFunction · 0.85
walk_cache_dir_snapshotFunction · 0.85
walk_dirFunction · 0.85
cbm_discover_freeFunction · 0.85

Tested by

no test coverage detected