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

Function kust_inline_facts

internal/cbm/extract_k8s.c:344–391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

342static const char KUST_DOC_END[] = "---";
343
344static void kust_inline_facts(CBMExtractCtx *ctx, const char *text, CBMK8sFact base) {
345 CBMArena *a = ctx->arena;
346 CBMK8sFact f = base;
347 int top = -1; /* indent of the document's keys */
348 int meta = -1; /* indent of metadata's keys, -1: not inside metadata */
349 bool in_meta = false;
350 for (const char *p = text; p;) {
351 const char *eol = strchr(p, '\n');
352 size_t len = eol ? (size_t)(eol - p) : strlen(p);
353 size_t b = strspn(p, " ");
354 bool doc_end = b + strlen(KUST_DOC_END) <= len &&
355 strncmp(p + b, KUST_DOC_END, strlen(KUST_DOC_END)) == 0;
356 int ind = 0;
357 char key[K8S_BUF_SIZE];
358 char val[K8S_BUF_SIZE];
359 if (!doc_end && kust_line(p, len, &ind, key, sizeof(key), val, sizeof(val))) {
360 if (top < 0) {
361 top = ind;
362 }
363 if (ind == top) {
364 in_meta = strcmp(key, "metadata") == 0 && !val[0];
365 meta = -1;
366 if (strcmp(key, "kind") == 0 && val[0]) {
367 f.kind = cbm_arena_strdup(a, val);
368 } else if (strcmp(key, "apiVersion") == 0 && val[0]) {
369 const char *slash = strchr(val, '/');
370 f.group = slash ? cbm_arena_strndup(a, val, (size_t)(slash - val)) : "core";
371 }
372 } else if (in_meta && ind > top) {
373 meta = meta < 0 ? ind : meta;
374 if (ind == meta && strcmp(key, "name") == 0 && val[0]) {
375 f.name = cbm_arena_strdup(a, val);
376 } else if (ind == meta && strcmp(key, "namespace") == 0 && val[0]) {
377 f.ns = cbm_arena_strdup(a, val);
378 }
379 }
380 }
381 if (doc_end || !eol) {
382 if (f.kind && f.name) {
383 cbm_k8sfact_push(&ctx->result->k8s_facts, a, f);
384 }
385 f = base;
386 top = -1;
387 in_meta = false;
388 }
389 p = eol ? eol + SKIP_ONE : NULL;
390 }
391}
392
393// The mapping entries of a kustomization's `patches` list.
394static void emit_kustomize_patches(CBMExtractCtx *ctx, TSNode seq) {

Callers 1

emit_kustomize_patchesFunction · 0.85

Calls 4

kust_lineFunction · 0.85
cbm_k8sfact_pushFunction · 0.85
cbm_arena_strdupFunction · 0.70
cbm_arena_strndupFunction · 0.70

Tested by

no test coverage detected