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

Function cbm_atlas_tree_json

src/ui/atlas_api.c:168–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166}
167
168char *cbm_atlas_tree_json(cbm_store_t *store, const char *project, const char *path) {
169 if (!store || !project)
170 return NULL;
171 struct sqlite3 *db = cbm_store_get_db(store);
172 if (!db)
173 return NULL;
174 char prefix[CBM_SZ_512];
175 aa_norm_path(path, prefix, sizeof(prefix));
176
177 aa_children_t set;
178 memset(&set, 0, sizeof(set));
179 set.by_name = cbm_ht_create(256);
180 if (!set.by_name)
181 return NULL;
182
183 long long total_symbols = 0;
184 int total_files = 0;
185
186 /* One pass: per-file symbol counts, folded into direct children. */
187 sqlite3_stmt *st = NULL;
188 if (sqlite3_prepare_v2(db,
189 "SELECT file_path, COUNT(*) FROM nodes WHERE project=?1 AND "
190 "file_path IS NOT NULL AND file_path != '' GROUP BY file_path",
191 -1, &st, NULL) != SQLITE_OK) {
192 aa_children_free(&set);
193 return NULL;
194 }
195 sqlite3_bind_text(st, 1, project, -1, SQLITE_STATIC);
196 while (sqlite3_step(st) == SQLITE_ROW) {
197 const char *file = (const char *)sqlite3_column_text(st, 0);
198 long long symbols = sqlite3_column_int64(st, 1);
199 char comp[CBM_SZ_256];
200 bool direct = false;
201 if (!file || !aa_child_component(file, prefix, comp, sizeof(comp), &direct))
202 continue;
203 total_symbols += symbols;
204 total_files++;
205 aa_tree_child_t *child = aa_child(&set, comp, direct);
206 if (!child)
207 continue;
208 child->symbols += symbols;
209 child->files++;
210 int region = cbm_layout_region_for_file(store, project, file, NULL);
211 if (region >= 0) {
212 /* Majority vote, Boyer-Moore style: cheap and order-stable
213 * enough for a display hint. */
214 if (child->region == region)
215 child->region_best++;
216 else if (child->region_best == 0) {
217 child->region = region;
218 child->region_best = 1;
219 } else {
220 child->region_best--;
221 }
222 }
223 }
224 sqlite3_finalize(st);
225

Callers 2

handle_atlas_treeFunction · 0.85
test_ui.cFile · 0.85

Calls 10

cbm_store_get_dbFunction · 0.85
aa_norm_pathFunction · 0.85
cbm_ht_createFunction · 0.85
aa_children_freeFunction · 0.85
aa_child_componentFunction · 0.85
aa_childFunction · 0.85
cbm_ht_getFunction · 0.85

Tested by

no test coverage detected