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

Function arch_packages

src/store/store.c:6248–6308  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6246}
6247
6248static int arch_packages(cbm_store_t *s, const char *project, const char *path,
6249 cbm_architecture_info_t *out) {
6250 char norm[CBM_SZ_512];
6251 char like[CBM_SZ_512];
6252 bool scoped = arch_path_prepare(path, norm, sizeof(norm), like, sizeof(like));
6253 char sqlbuf[ST_SQL_BUF];
6254 const char *base = "SELECT n.name, COUNT(*) as cnt FROM nodes n "
6255 "WHERE n.project=?1 AND n.label='Package'";
6256 if (scoped) {
6257 snprintf(sqlbuf, sizeof(sqlbuf),
6258 "%s AND (n.file_path = ?2 OR n.file_path LIKE ?3) "
6259 "GROUP BY n.name ORDER BY cnt DESC LIMIT 15",
6260 base);
6261 } else {
6262 snprintf(sqlbuf, sizeof(sqlbuf), "%s GROUP BY n.name ORDER BY cnt DESC LIMIT 15", base);
6263 }
6264 sqlite3_stmt *stmt = NULL;
6265 if (sqlite3_prepare_v2(s->db, sqlbuf, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) {
6266 store_set_error_sqlite(s, "arch_packages");
6267 return CBM_STORE_ERR;
6268 }
6269 bind_text(stmt, SKIP_ONE, project);
6270 if (scoped) {
6271 arch_bind_path_scope(stmt, ST_COL_2, ST_COL_3, norm, like);
6272 }
6273
6274 int cap = ST_INIT_CAP_16;
6275 int n = 0;
6276 cbm_package_summary_t *arr = calloc(cap, sizeof(cbm_package_summary_t));
6277 int scan_rc27;
6278 while ((scan_rc27 = sqlite3_step(stmt)) == SQLITE_ROW) {
6279 if (n >= cap) {
6280 cap *= ST_GROWTH;
6281 arr = safe_realloc(arr, cap * sizeof(cbm_package_summary_t));
6282 }
6283 arr[n].name = heap_strdup((const char *)sqlite3_column_text(stmt, 0));
6284 arr[n].node_count = sqlite3_column_int(stmt, SKIP_ONE);
6285 n++;
6286 }
6287 if (scan_rc27 != SQLITE_DONE) { /* SCANCHK:27:stmt */
6288 store_set_error_sqlite(s, "row scan aborted");
6289 sqlite3_finalize(stmt);
6290 out->packages = arr;
6291 out->package_count = n;
6292 return CBM_STORE_ERR;
6293 }
6294 sqlite3_finalize(stmt);
6295
6296 /* Fallback: group by QN segment if no Package nodes */
6297 if (n == 0) {
6298 free(arr);
6299 int rc = arch_packages_from_qn(s, project, path, &arr, &n);
6300 if (rc != CBM_STORE_OK) {
6301 return rc;
6302 }
6303 }
6304
6305 out->packages = arr;

Callers 1

Calls 7

arch_path_prepareFunction · 0.85
store_set_error_sqliteFunction · 0.85
bind_textFunction · 0.85
arch_bind_path_scopeFunction · 0.85
safe_reallocFunction · 0.85
arch_packages_from_qnFunction · 0.85
heap_strdupFunction · 0.70

Tested by

no test coverage detected