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

Function file_query_chunk

src/store/store.c:6427–6486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6425enum { DEPFILE_CHUNK = 200 };
6426
6427static int file_query_chunk(cbm_store_t *s, const char *const *parts, int nparts, const char *what,
6428 const char *project, const char *const *target_files, int chunk_count,
6429 CBMHashTable *seen, char ***out, int *out_count, int *out_cap) {
6430 char sql[CBM_SZ_8K];
6431 sql[0] = '\0';
6432 if (nparts < 1) {
6433 return CBM_STORE_ERR;
6434 }
6435 int pos = 0;
6436 for (int part = 0; part < nparts; part++) {
6437 if (part > 0) {
6438 for (int i = 0; i < chunk_count; i++) {
6439 pos += snprintf(sql + pos, sizeof(sql) - (size_t)pos, "%s?%d", i ? "," : "",
6440 i + ST_COL_2);
6441 if ((size_t)pos >= sizeof(sql)) {
6442 return CBM_STORE_ERR;
6443 }
6444 }
6445 }
6446 pos += snprintf(sql + pos, sizeof(sql) - (size_t)pos, "%s", parts[part]);
6447 if ((size_t)pos >= sizeof(sql)) {
6448 return CBM_STORE_ERR;
6449 }
6450 }
6451 sqlite3_stmt *stmt = NULL;
6452 if (sqlite3_prepare_v2(s->db, sql, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) {
6453 store_set_error_sqlite(s, what);
6454 return CBM_STORE_ERR;
6455 }
6456 bind_text(stmt, ST_COL_1, project);
6457 for (int i = 0; i < chunk_count; i++) {
6458 bind_text(stmt, i + ST_COL_2, target_files[i]);
6459 }
6460 int step_rc;
6461 while ((step_rc = sqlite3_step(stmt)) == SQLITE_ROW) {
6462 const char *path = (const char *)sqlite3_column_text(stmt, 0);
6463 if (!path || !path[0] || cbm_ht_get(seen, path)) {
6464 continue;
6465 }
6466 if (*out_count >= *out_cap) {
6467 int ncap = *out_cap ? *out_cap * ST_GROWTH : ST_INIT_CAP_8;
6468 char **grown = realloc(*out, (size_t)ncap * sizeof(char *));
6469 if (!grown) {
6470 sqlite3_finalize(stmt);
6471 return CBM_STORE_ERR;
6472 }
6473 *out = grown;
6474 *out_cap = ncap;
6475 }
6476 char *copy = strdup(path);
6477 if (!copy) {
6478 sqlite3_finalize(stmt);
6479 return CBM_STORE_ERR;
6480 }
6481 (*out)[(*out_count)++] = copy;
6482 cbm_ht_set(seen, copy, copy);
6483 }
6484 sqlite3_finalize(stmt);

Callers 1

file_queryFunction · 0.85

Calls 4

store_set_error_sqliteFunction · 0.85
bind_textFunction · 0.85
cbm_ht_getFunction · 0.85
cbm_ht_setFunction · 0.85

Tested by

no test coverage detected