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

Function dk_hub_components

src/pipeline/pass_docker.c:2003–2044  ·  view source on GitHub ↗

Components of a repository built from several Dockerfiles: each build * tag without the tags' common prefix / suffix (otel's latest-frontend, * latest-cart -> frontend, cart). A component built from exactly one * Dockerfile, holding no unknown part, is kept (comps[k] non-NULL); each * build edge's comp is set. Returns the number of component slots (0: * none kept). */

Source from the content-addressed store, hash-verified

2001 * build edge's comp is set. Returns the number of component slots (0:
2002 * none kept). */
2003static int dk_hub_components(CBMArena *a, dk_hub_edges_t *b, size_t pre, size_t suf,
2004 const char ***comps) {
2005 const char **names = cbm_arena_alloc(a, (size_t)b->n * sizeof(*names));
2006 int64_t *dfs = cbm_arena_alloc(a, (size_t)b->n * sizeof(*dfs));
2007 CBMHashTable *index = cbm_ht_create(0); /* component -> slot + 1 */
2008 int nc = 0;
2009 for (int i = 0; names && dfs && index && i < b->n; i++) {
2010 const char *t = b->v[i].tag;
2011 size_t tl = strlen(t);
2012 const char *c = tl > pre + suf ? cbm_arena_strndup(a, t + pre, tl - pre - suf) : NULL;
2013 if (!c || strpbrk(c, "$*{}()`\"\\")) {
2014 continue;
2015 }
2016 int k = (int)(intptr_t)cbm_ht_get(index, c) - SKIP_ONE;
2017 if (k < 0) {
2018 k = nc++;
2019 names[k] = c;
2020 dfs[k] = b->v[i].tgt;
2021 cbm_ht_set(index, c, (void *)(intptr_t)(k + SKIP_ONE));
2022 } else if (names[k] && dfs[k] != b->v[i].tgt) {
2023 names[k] = NULL; /* one name, two Dockerfiles: no identity */
2024 }
2025 b->v[i].comp = k;
2026 }
2027 if (index) {
2028 cbm_ht_free(index);
2029 }
2030 if (!names || !dfs) {
2031 return 0;
2032 }
2033 int kept = 0;
2034 for (int k = 0; k < nc; k++) {
2035 kept += names[k] ? SKIP_ONE : 0;
2036 }
2037 for (int i = 0; i < b->n; i++) {
2038 if (b->v[i].comp >= 0 && !names[b->v[i].comp]) {
2039 b->v[i].comp = -1;
2040 }
2041 }
2042 *comps = names;
2043 return kept ? nc : 0;
2044}
2045
2046/* The component a reference's tag names: the longest kept one occurring in
2047 * it as whole parts; -1 for none, or for two of that length. */

Callers 1

dk_hub_repoFunction · 0.85

Calls 6

cbm_ht_createFunction · 0.85
cbm_ht_getFunction · 0.85
cbm_ht_setFunction · 0.85
cbm_ht_freeFunction · 0.85
cbm_arena_allocFunction · 0.50
cbm_arena_strndupFunction · 0.50

Tested by

no test coverage detected