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

Function gc_match

src/pipeline/pass_operator.c:1673–1711  ·  view source on GitHub ↗

The one chart directory a value names: the tail itself, or the only chart * directory ending with it. */

Source from the content-addressed store, hash-verified

1671/* The one chart directory a value names: the tail itself, or the only chart
1672 * directory ending with it. */
1673static const gc_chart_t *gc_match(gc_t *g, const gc_val_t *v, char *dir, size_t dir_sz) {
1674 const char *t = v->s;
1675 while (t[0] == '.' && t[SKIP_ONE] == '/') {
1676 t += PAIR_LEN;
1677 }
1678 while (*t == '/') {
1679 t++;
1680 }
1681 snprintf(dir, dir_sz, "%s", t);
1682 size_t dl = strlen(dir);
1683 while (dl && dir[dl - SKIP_ONE] == '/') {
1684 dir[--dl] = '\0';
1685 }
1686 if (!dl) {
1687 return NULL;
1688 }
1689 const char *base = strrchr(dir, '/');
1690 base = base ? base + SKIP_ONE : dir;
1691 const gc_charts_t *list = cbm_ht_get(g->charts, base);
1692 const gc_chart_t *hit = NULL;
1693 for (int i = 0; list && i < list->count; i++) {
1694 atomic_fetch_add_explicit(&g_op_candidates, SKIP_ONE, memory_order_relaxed);
1695 const char *cd = list->items[i].dir; /* "<dir>/Chart.yaml" */
1696 size_t cl = (size_t)(strrchr(cd, '/') - cd);
1697 bool same = cl == dl && strncmp(cd, dir, dl) == 0;
1698 bool tail = cl > dl && cd[cl - dl - SKIP_ONE] == '/' && strncmp(cd + cl - dl, dir, dl) == 0;
1699 if (same || tail) {
1700 if (hit) {
1701 return NULL;
1702 }
1703 hit = &list->items[i];
1704 }
1705 }
1706 if (hit) {
1707 const char *cd = hit->dir;
1708 snprintf(dir, dir_sz, "%.*s", (int)(strrchr(cd, '/') - cd), cd);
1709 }
1710 return hit;
1711}
1712
1713/* The body of the top-level function around `at`, else NULL; *sig: its
1714 * `func` keyword. */

Callers 1

gc_link_sitesFunction · 0.85

Calls 1

cbm_ht_getFunction · 0.85

Tested by

no test coverage detected