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

Function create_folder_chain

src/pipeline/pipeline.c:1535–1576  ·  view source on GitHub ↗

Create Project, Folder/Package, and File nodes in the graph buffer. */ Walk directory chain upward, creating Folder nodes and CONTAINS_FOLDER edges. */

Source from the content-addressed store, hash-verified

1533/* Create Project, Folder/Package, and File nodes in the graph buffer. */
1534/* Walk directory chain upward, creating Folder nodes and CONTAINS_FOLDER edges. */
1535static void create_folder_chain(cbm_pipeline_t *p, const cbm_stem_marks_t *marks, const char *dir,
1536 CBMHashTable *seen_dirs) {
1537 char *walk = strdup(dir);
1538 while (walk[0] != '\0' && !cbm_ht_get(seen_dirs, walk)) {
1539 cbm_ht_set(seen_dirs, strdup(walk), intptr_to_ptr(SKIP_ONE));
1540 char folder_buf[CBM_SZ_8K];
1541 const char *folder_qn =
1542 cbm_stem_marks_folder_qn(marks, p->project_name, walk, folder_buf, sizeof(folder_buf));
1543 const char *dir_base = strrchr(walk, '/');
1544 dir_base = dir_base ? dir_base + SKIP_ONE : walk;
1545 cbm_gbuf_upsert_node(p->gbuf, "Folder", dir_base, folder_qn, walk, 0, 0, "{}");
1546
1547 char *pdir = strdup(walk);
1548 char *ps = strrchr(pdir, '/');
1549 if (ps) {
1550 *ps = '\0';
1551 } else {
1552 free(pdir);
1553 pdir = strdup("");
1554 }
1555 const char *pqn;
1556 char pqn_buf[CBM_SZ_8K];
1557 if (pdir[0] == '\0') {
1558 pqn = p->branch_qn ? p->branch_qn : p->project_name;
1559 } else {
1560 pqn = cbm_stem_marks_folder_qn(marks, p->project_name, pdir, pqn_buf, sizeof(pqn_buf));
1561 }
1562 const cbm_gbuf_node_t *fn = folder_qn ? cbm_gbuf_find_by_qn(p->gbuf, folder_qn) : NULL;
1563 const cbm_gbuf_node_t *pn = pqn ? cbm_gbuf_find_by_qn(p->gbuf, pqn) : NULL;
1564 if (fn && pn) {
1565 cbm_gbuf_insert_edge(p->gbuf, pn->id, fn->id, "CONTAINS_FOLDER", "{}");
1566 }
1567 char *up = strrchr(walk, '/');
1568 if (up) {
1569 *up = '\0';
1570 } else {
1571 walk[0] = '\0';
1572 }
1573 free(pdir);
1574 }
1575 free(walk);
1576}
1577
1578static int pass_structure(cbm_pipeline_t *p, const cbm_stem_marks_t *marks,
1579 const cbm_file_info_t *files, int file_count) {

Callers 1

pass_structureFunction · 0.85

Calls 7

cbm_ht_getFunction · 0.85
cbm_ht_setFunction · 0.85
cbm_stem_marks_folder_qnFunction · 0.85
cbm_gbuf_upsert_nodeFunction · 0.85
cbm_gbuf_find_by_qnFunction · 0.85
cbm_gbuf_insert_edgeFunction · 0.85
intptr_to_ptrFunction · 0.70

Tested by

no test coverage detected