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

Function resolve_exact_file_node

src/pipeline/pass_pkgmap.c:1583–1647  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1581}
1582
1583static const cbm_gbuf_node_t *resolve_exact_file_node(const cbm_pipeline_ctx_t *ctx,
1584 const char *file_path,
1585 const char *source_file_qn) {
1586 if (!ctx || !file_path || !file_path[0]) {
1587 return NULL;
1588 }
1589
1590 const char *leaf = path_leaf(file_path);
1591 if (!leaf || !leaf[0]) {
1592 return NULL;
1593 }
1594
1595 char stem[PKGMAP_PATH_BUF];
1596 snprintf(stem, sizeof(stem), "%s", leaf);
1597 char *last_dot = strrchr(stem, '.');
1598 if (last_dot && last_dot != stem) {
1599 *last_dot = '\0';
1600 }
1601
1602 const char *names[2] = {stem[0] ? stem : NULL, leaf};
1603 const cbm_gbuf_node_t *best = NULL;
1604 for (int ni = 0; ni < 2; ni++) {
1605 const char *name = names[ni];
1606 if (!name || !name[0]) {
1607 continue;
1608 }
1609
1610 const cbm_gbuf_node_t **hits = NULL;
1611 int hit_count = 0;
1612 if (cbm_gbuf_find_by_name(ctx->gbuf, name, &hits, &hit_count) != 0 || !hits) {
1613 continue;
1614 }
1615
1616 for (int i = 0; i < hit_count; i++) {
1617 const cbm_gbuf_node_t *cand = hits[i];
1618 if (!cand || !cand->file_path) {
1619 continue;
1620 }
1621
1622 /* Tie-breaker: Ensure the candidate's actual file_path ends with the
1623 * specific include path requested (e.g., 'a/util.h' instead of just 'util.h'). */
1624 if (!ends_with(cand->file_path, file_path)) {
1625 continue;
1626 }
1627
1628 if (!cand->label || !import_targetable_label(cand->label)) {
1629 continue;
1630 }
1631 if (source_file_qn && cand->qualified_name &&
1632 strcmp(cand->qualified_name, source_file_qn) == 0) {
1633 continue;
1634 }
1635 if (strcmp(cand->label, "File") == 0) {
1636 return cand;
1637 }
1638 if (!best) {
1639 best = cand;
1640 }

Callers 1

resolve_header_includeFunction · 0.85

Calls 4

path_leafFunction · 0.85
cbm_gbuf_find_by_nameFunction · 0.85
import_targetable_labelFunction · 0.85
ends_withFunction · 0.70

Tested by

no test coverage detected