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

Function arch_packages

src/store/store.c:6155–6215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6153}
6154
6155static int arch_packages(cbm_store_t *s, const char *project, const char *path,
6156 cbm_architecture_info_t *out) {
6157 char norm[CBM_SZ_512];
6158 char like[CBM_SZ_512];
6159 bool scoped = arch_path_prepare(path, norm, sizeof(norm), like, sizeof(like));
6160 char sqlbuf[ST_SQL_BUF];
6161 const char *base = "SELECT n.name, COUNT(*) as cnt FROM nodes n "
6162 "WHERE n.project=?1 AND n.label='Package'";
6163 if (scoped) {
6164 snprintf(sqlbuf, sizeof(sqlbuf),
6165 "%s AND (n.file_path = ?2 OR n.file_path LIKE ?3) "
6166 "GROUP BY n.name ORDER BY cnt DESC LIMIT 15",
6167 base);
6168 } else {
6169 snprintf(sqlbuf, sizeof(sqlbuf), "%s GROUP BY n.name ORDER BY cnt DESC LIMIT 15", base);
6170 }
6171 sqlite3_stmt *stmt = NULL;
6172 if (sqlite3_prepare_v2(s->db, sqlbuf, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) {
6173 store_set_error_sqlite(s, "arch_packages");
6174 return CBM_STORE_ERR;
6175 }
6176 bind_text(stmt, SKIP_ONE, project);
6177 if (scoped) {
6178 arch_bind_path_scope(stmt, ST_COL_2, ST_COL_3, norm, like);
6179 }
6180
6181 int cap = ST_INIT_CAP_16;
6182 int n = 0;
6183 cbm_package_summary_t *arr = calloc(cap, sizeof(cbm_package_summary_t));
6184 int scan_rc27;
6185 while ((scan_rc27 = sqlite3_step(stmt)) == SQLITE_ROW) {
6186 if (n >= cap) {
6187 cap *= ST_GROWTH;
6188 arr = safe_realloc(arr, cap * sizeof(cbm_package_summary_t));
6189 }
6190 arr[n].name = heap_strdup((const char *)sqlite3_column_text(stmt, 0));
6191 arr[n].node_count = sqlite3_column_int(stmt, SKIP_ONE);
6192 n++;
6193 }
6194 if (scan_rc27 != SQLITE_DONE) { /* SCANCHK:27:stmt */
6195 store_set_error_sqlite(s, "row scan aborted");
6196 sqlite3_finalize(stmt);
6197 out->packages = arr;
6198 out->package_count = n;
6199 return CBM_STORE_ERR;
6200 }
6201 sqlite3_finalize(stmt);
6202
6203 /* Fallback: group by QN segment if no Package nodes */
6204 if (n == 0) {
6205 free(arr);
6206 int rc = arch_packages_from_qn(s, project, path, &arr, &n);
6207 if (rc != CBM_STORE_OK) {
6208 return rc;
6209 }
6210 }
6211
6212 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