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

Function build_import_map

src/pipeline/pass_parallel.c:529–576  ·  view source on GitHub ↗

Build import map from graph buffer IMPORTS edges (read-only access to gbuf). */

Source from the content-addressed store, hash-verified

527
528/* Build import map from graph buffer IMPORTS edges (read-only access to gbuf). */
529static int build_import_map(const cbm_gbuf_t *gbuf, const char *project_name, const char *rel_path,
530 const char ***out_keys, const char ***out_vals, int *out_count) {
531 *out_keys = NULL;
532 *out_vals = NULL;
533 *out_count = 0;
534
535 char *file_qn = cbm_pipeline_fqn_compute(project_name, rel_path, "__file__");
536 const cbm_gbuf_node_t *file_node = cbm_gbuf_find_by_qn(gbuf, file_qn);
537 free(file_qn);
538 if (!file_node) {
539 return 0;
540 }
541
542 const cbm_gbuf_edge_t **edges = NULL;
543 int edge_count = 0;
544 int rc =
545 cbm_gbuf_find_edges_by_source_type(gbuf, file_node->id, "IMPORTS", &edges, &edge_count);
546 if (rc != 0 || edge_count == 0) {
547 return 0;
548 }
549
550 const char **keys = calloc(edge_count, sizeof(const char *));
551 const char **vals = calloc(edge_count, sizeof(const char *));
552 int count = 0;
553
554 for (int i = 0; i < edge_count; i++) {
555 const cbm_gbuf_edge_t *e = edges[i];
556 const cbm_gbuf_node_t *target = cbm_gbuf_find_by_id(gbuf, e->target_id);
557 if (!target || !e->properties_json) {
558 continue;
559 }
560 const char *start = strstr(e->properties_json, "\"local_name\":\"");
561 if (start) {
562 start += strlen("\"local_name\":\"");
563 const char *end = strchr(start, '"');
564 if (end && end > start) {
565 keys[count] = cbm_strndup(start, end - start);
566 vals[count] = target->qualified_name;
567 count++;
568 }
569 }
570 }
571
572 *out_keys = keys;
573 *out_vals = vals;
574 *out_count = count;
575 return 0;
576}
577
578static void free_import_map(const char **keys, const char **vals, int count) {
579 if (keys) {

Callers 1

resolve_workerFunction · 0.70

Calls 5

cbm_pipeline_fqn_computeFunction · 0.85
cbm_gbuf_find_by_qnFunction · 0.85
cbm_gbuf_find_by_idFunction · 0.85
cbm_strndupFunction · 0.85

Tested by

no test coverage detected