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

Function lang_index_files

tests/test_lang_contract.c:109–140  ·  view source on GitHub ↗

Write each fixture file into a fresh temp project, index it via the MCP * production flow (discover -> extract -> registry -> resolve -> dump), and open * the resulting graph DB. Returns the store (NULL on any failure). */

Source from the content-addressed store, hash-verified

107 * production flow (discover -> extract -> registry -> resolve -> dump), and open
108 * the resulting graph DB. Returns the store (NULL on any failure). */
109static cbm_store_t *lang_index_files(LangProj *lp, const LangFile *files, int nfiles) {
110 memset(lp, 0, sizeof(*lp));
111 snprintf(lp->tmpdir, sizeof(lp->tmpdir), "/tmp/cbm_lc_XXXXXX");
112 if (!cbm_mkdtemp(lp->tmpdir)) {
113 return NULL;
114 }
115 lc_to_fwd_slashes(lp->tmpdir);
116 for (int i = 0; i < nfiles; i++) {
117 char path[700];
118 snprintf(path, sizeof(path), "%s/%s", lp->tmpdir, files[i].name);
119 /* Create parent directories if the fixture name embeds subdirs.
120 * Use mkdir_p (not mkdir) so multi-level paths like
121 * "pkg/validation/x.go" create every intermediate directory. */
122 char *slash = strrchr(path, '/');
123 if (slash && slash > path + strlen(lp->tmpdir)) {
124 *slash = '\0';
125 cbm_mkdir_p(path, 0755);
126 *slash = '/';
127 }
128 /* Binary mode: keep fixture line endings exactly as written ("\n").
129 * Windows text mode rewrites "\n"→"\r\n", which makes line-ending-
130 * sensitive grammars under-extract (below_min / calls_breadth). */
131 FILE *f = fopen(path, "wb");
132 if (!f) {
133 return NULL;
134 }
135 fputs(files[i].content, f);
136 fclose(f);
137 }
138
139 return lang_open_indexed(lp);
140}
141
142/* Convenience: index a single fixture file. */
143static cbm_store_t *lang_index(LangProj *lp, const char *filename, const char *content) {

Callers 5

lang_indexFunction · 0.85
lang_metricsFunction · 0.85
edge_presentFunction · 0.85
index_parallel_fixtureFunction · 0.85

Calls 5

cbm_mkdtempFunction · 0.85
lc_to_fwd_slashesFunction · 0.85
cbm_mkdir_pFunction · 0.85
fopenFunction · 0.85
lang_open_indexedFunction · 0.85

Tested by

no test coverage detected