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:1910–1968  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1908}
1909
1910static const cbm_gbuf_node_t *resolve_exact_file_node(const cbm_pipeline_ctx_t *ctx,
1911 const char *file_path,
1912 const char *source_file_qn) {
1913 if (!ctx || !file_path || !file_path[0]) {
1914 return NULL;
1915 }
1916
1917 const char *leaf = path_leaf(file_path);
1918 if (!leaf || !leaf[0]) {
1919 return NULL;
1920 }
1921
1922 char stem[PKGMAP_PATH_BUF];
1923 snprintf(stem, sizeof(stem), "%s", leaf);
1924 char *last_dot = strrchr(stem, '.');
1925 if (last_dot && last_dot != stem) {
1926 *last_dot = '\0';
1927 }
1928
1929 const char *names[2] = {stem[0] ? stem : NULL, leaf};
1930 const cbm_gbuf_node_t *best = NULL;
1931 for (int ni = 0; ni < 2; ni++) {
1932 const char *name = names[ni];
1933 if (!name || !name[0]) {
1934 continue;
1935 }
1936
1937 const cbm_gbuf_node_t **hits = NULL;
1938 int hit_count = 0;
1939 if (cbm_gbuf_find_by_name(ctx->gbuf, name, &hits, &hit_count) != 0 || !hits) {
1940 continue;
1941 }
1942
1943 for (int i = 0; i < hit_count; i++) {
1944 const cbm_gbuf_node_t *cand = hits[i];
1945 if (!cand || !cand->file_path) {
1946 continue;
1947 }
1948
1949 /* Tie-breaker: Ensure the candidate's actual file_path ends with the
1950 * specific include path requested (e.g., 'a/util.h' instead of just 'util.h'). */
1951 if (!ends_with(cand->file_path, file_path)) {
1952 continue;
1953 }
1954
1955 if (!cand->label || !import_targetable_label(cand->label)) {
1956 continue;
1957 }
1958 if (source_file_qn && cand->qualified_name &&
1959 strcmp(cand->qualified_name, source_file_qn) == 0) {
1960 continue;
1961 }
1962 if (include_target_outranks(cand, best)) {
1963 best = cand;
1964 }
1965 }
1966 }
1967 return best;

Callers 1

resolve_header_includeFunction · 0.85

Calls 5

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

Tested by

no test coverage detected