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

Function arch_clusters

src/store/store.c:7436–7620  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7434}
7435
7436static int arch_clusters(cbm_store_t *s, const char *project, const char *path,
7437 cbm_architecture_info_t *out) {
7438 char norm[CBM_SZ_512];
7439 char like[CBM_SZ_512];
7440 bool scoped = arch_path_prepare(path, norm, sizeof(norm), like, sizeof(like));
7441 char nsqlbuf[ST_SQL_BUF];
7442 const char *nbase = "SELECT id, name, qualified_name, file_path FROM nodes "
7443 "WHERE project=?1 AND label IN (" CBM_SQL_CALLABLE_OR_TYPE_LABELS ")";
7444 if (scoped) {
7445 snprintf(nsqlbuf, sizeof(nsqlbuf), "%s%s ORDER BY id LIMIT ?4", nbase,
7446 arch_path_scope_sql());
7447 } else {
7448 snprintf(nsqlbuf, sizeof(nsqlbuf), "%s ORDER BY id LIMIT ?2", nbase);
7449 }
7450 sqlite3_stmt *st = NULL;
7451 if (sqlite3_prepare_v2(s->db, nsqlbuf, CBM_NOT_FOUND, &st, NULL) != SQLITE_OK) {
7452 return CBM_STORE_OK; /* clusters are best-effort */
7453 }
7454 bind_text(st, SKIP_ONE, project);
7455 if (scoped) {
7456 arch_bind_path_scope(st, ST_COL_2, ST_COL_3, norm, like);
7457 sqlite3_bind_int(st, ST_COL_4, CBM_CLUSTER_NODE_CAP);
7458 } else {
7459 sqlite3_bind_int(st, CBM_SZ_2, CBM_CLUSTER_NODE_CAP);
7460 }
7461 int cap = ST_INIT_CAP_8;
7462 int n = 0;
7463 int64_t *ids = malloc((size_t)cap * sizeof(int64_t));
7464 const char **names = malloc((size_t)cap * sizeof(char *));
7465 const char **qns = malloc((size_t)cap * sizeof(char *));
7466 int scan_rc29;
7467 while ((scan_rc29 = sqlite3_step(st)) == SQLITE_ROW) {
7468 if (n >= cap) {
7469 cap *= ST_GROWTH;
7470 ids = safe_realloc(ids, (size_t)cap * sizeof(int64_t));
7471 names = safe_realloc(names, (size_t)cap * sizeof(char *));
7472 qns = safe_realloc(qns, (size_t)cap * sizeof(char *));
7473 }
7474 ids[n] = sqlite3_column_int64(st, 0);
7475 names[n] = heap_strdup((const char *)sqlite3_column_text(st, SKIP_ONE));
7476 qns[n] = heap_strdup((const char *)sqlite3_column_text(st, CBM_SZ_2));
7477 n++;
7478 }
7479 if (scan_rc29 != SQLITE_DONE) { /* SCANCHK:29:st */
7480 store_set_error_sqlite(s, "row scan aborted");
7481 sqlite3_finalize(st);
7482 for (int ci = 0; ci < n; ci++) {
7483 safe_str_free(&names[ci]);
7484 safe_str_free(&qns[ci]);
7485 }
7486 free(ids);
7487 free((void *)names);
7488 free((void *)qns);
7489 return CBM_STORE_ERR;
7490 }
7491 sqlite3_finalize(st);
7492 if (n < CBM_CLUSTER_MIN_MEMBERS) {
7493 for (int i = 0; i < n; i++) {

Callers 1

Calls 11

arch_path_prepareFunction · 0.85
arch_path_scope_sqlFunction · 0.85
bind_textFunction · 0.85
arch_bind_path_scopeFunction · 0.85
safe_reallocFunction · 0.85
store_set_error_sqliteFunction · 0.85
safe_str_freeFunction · 0.85
cluster_id_indexFunction · 0.85
cbm_leidenFunction · 0.85
cluster_build_oneFunction · 0.85
heap_strdupFunction · 0.70

Tested by

no test coverage detected