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

Function arch_file_tree

src/store/store.c:4587–4640  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4585}
4586
4587static int arch_file_tree(cbm_store_t *s, const char *project, const char *path,
4588 cbm_architecture_info_t *out) {
4589 char norm[CBM_SZ_512];
4590 char like[CBM_SZ_512];
4591 bool scoped = arch_path_prepare(path, norm, sizeof(norm), like, sizeof(like));
4592 char sqlbuf[ST_SQL_BUF];
4593 const char *base = "SELECT file_path FROM nodes WHERE project=?1 AND label='File'";
4594 if (scoped) {
4595 snprintf(sqlbuf, sizeof(sqlbuf), "%s%s", base, arch_path_scope_sql());
4596 } else {
4597 snprintf(sqlbuf, sizeof(sqlbuf), "%s", base);
4598 }
4599 sqlite3_stmt *stmt = NULL;
4600 if (sqlite3_prepare_v2(s->db, sqlbuf, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) {
4601 store_set_error_sqlite(s, "arch_file_tree");
4602 return CBM_STORE_ERR;
4603 }
4604 bind_text(stmt, SKIP_ONE, project);
4605 if (scoped) {
4606 arch_bind_path_scope(stmt, ST_COL_2, ST_COL_3, norm, like);
4607 }
4608
4609 int fcap = CBM_SZ_32;
4610 int fn = 0;
4611 char **files = malloc(fcap * sizeof(char *));
4612
4613 int dcap = CBM_SZ_64;
4614 int dn = 0;
4615 char **dir_paths = calloc(dcap, sizeof(char *));
4616 int *dir_child_counts = calloc(dcap, sizeof(int));
4617 char ***dir_children = calloc(dcap, sizeof(char **));
4618 int *dir_children_caps = calloc(dcap, sizeof(int));
4619
4620 while (sqlite3_step(stmt) == SQLITE_ROW) {
4621 const char *fp = (const char *)sqlite3_column_text(stmt, 0);
4622 if (!fp) {
4623 continue;
4624 }
4625 if (fn >= fcap) {
4626 fcap *= ST_GROWTH;
4627 files = safe_realloc(files, fcap * sizeof(char *));
4628 }
4629 files[fn++] = heap_strdup(fp);
4630 arch_register_file_dirs(fp, dir_paths, dir_child_counts, dir_children, dir_children_caps,
4631 &dn, dcap);
4632 }
4633 sqlite3_finalize(stmt);
4634
4635 arch_collect_entries(dir_paths, dir_child_counts, dir_children, dn, files, fn, &out->file_tree,
4636 &out->file_tree_count);
4637
4638 arch_free_dirs(dir_paths, dir_child_counts, dir_children, dir_children_caps, dn, files, fn);
4639 return CBM_STORE_OK;
4640}
4641
4642/* ── Louvain community detection ───────────────────────────────── */
4643

Callers 1

Calls 10

arch_path_prepareFunction · 0.85
arch_path_scope_sqlFunction · 0.85
store_set_error_sqliteFunction · 0.85
bind_textFunction · 0.85
arch_bind_path_scopeFunction · 0.85
safe_reallocFunction · 0.85
arch_register_file_dirsFunction · 0.85
arch_collect_entriesFunction · 0.85
arch_free_dirsFunction · 0.85
heap_strdupFunction · 0.70

Tested by

no test coverage detected