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

Function pr_build

src/pipeline/doc_links_php.c:370–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

368}
369
370static void *pr_build(const cbm_doclink_build_in_t *in) {
371 pr_index_t *ix = (pr_index_t *)cbm_calloc(CBM_MEM_CLASS_OTHER, sizeof(*ix));
372 if (!ix) {
373 return NULL;
374 }
375 cbm_arena_init(&ix->arena);
376 ix->project = in->ctx->project_name;
377 ix->nfiles = in->file_count;
378 ix->run_count = in->run_file_count;
379 ix->files =
380 in->file_count
381 ? (pr_file_t *)cbm_arena_calloc(&ix->arena, (size_t)in->file_count * sizeof(pr_file_t))
382 : NULL;
383 ix->run_to_file = (int *)cbm_calloc(CBM_MEM_CLASS_OTHER,
384 (size_t)(in->run_file_count + SKIP_ONE) * sizeof(int));
385 ix->by_path = cbm_ht_create_in(CBM_MEM_CLASS_OTHER, (uint32_t)(in->file_count + SKIP_ONE));
386 bool ok = (!in->file_count || ix->files) && ix->run_to_file && ix->by_path;
387 for (int r = 0; ok && r < in->run_file_count; r++) {
388 ix->run_to_file[r] = CBM_NOT_FOUND;
389 }
390 for (int i = 0; ok && i < in->file_count && !ix->oom; i++) {
391 const cbm_doclink_file_t *src = &in->files[i];
392 pr_file_t *f = &ix->files[i];
393 f->path = src->rel_path;
394 f->module_qn =
395 cbm_fqn_module_source_lang(&ix->arena, ix->project, src->rel_path, CBM_LANG_PHP);
396 f->test = cbm_is_test_file(src->rel_path, CBM_LANG_PHP);
397 ix->oom = ix->oom || !f->module_qn;
398 cbm_ht_set(ix->by_path, src->rel_path, (void *)(uintptr_t)(i + SKIP_ONE));
399 if (src->run_file >= 0 && src->run_file < in->run_file_count) {
400 ix->run_to_file[src->run_file] = i;
401 }
402 if (src->scope) {
403 pr_read_blob(ix, f, i, src->scope);
404 }
405 }
406 ok = ok && !ix->oom && pr_link(ix);
407 if (!ok) {
408 cbm_log_error("doc_links.php.error", "step", "index", "reason", "alloc");
409 pr_destroy(ix);
410 return NULL;
411 }
412 char b[CBM_SZ_3][CBM_SZ_32];
413 snprintf(b[0], sizeof(b[0]), "%d", ix->nfiles);
414 snprintf(b[SKIP_ONE], sizeof(b[SKIP_ONE]), "%d", ix->ntypes);
415 snprintf(b[PAIR_LEN], sizeof(b[PAIR_LEN]), "%d", ix->nfuncs);
416 cbm_log_info("doc_links.php.index", "files", b[0], "types", b[SKIP_ONE], "functions",
417 b[PAIR_LEN]);
418 return ix;
419}
420
421/* ── References ──────────────────────────────────────────────────── */
422

Callers

nothing calls this directly

Calls 10

cbm_callocFunction · 0.85
cbm_arena_callocFunction · 0.85
cbm_ht_create_inFunction · 0.85
cbm_is_test_fileFunction · 0.85
cbm_ht_setFunction · 0.85
pr_linkFunction · 0.85
pr_read_blobFunction · 0.70
pr_destroyFunction · 0.70
cbm_arena_initFunction · 0.50

Tested by

no test coverage detected