| 1576 | } |
| 1577 | |
| 1578 | static int pass_structure(cbm_pipeline_t *p, const cbm_stem_marks_t *marks, |
| 1579 | const cbm_file_info_t *files, int file_count) { |
| 1580 | cbm_log_info("pass.start", "pass", "structure", "files", itoa_buf(file_count)); |
| 1581 | |
| 1582 | /* Project node */ |
| 1583 | cbm_gbuf_upsert_node(p->gbuf, "Project", p->project_name, p->project_name, NULL, 0, 0, "{}"); |
| 1584 | const char *branch_qn = p->branch_qn ? p->branch_qn : p->project_name; |
| 1585 | const char *branch_name = p->git_ctx.branch ? p->git_ctx.branch : "working-tree"; |
| 1586 | char branch_props[CBM_SZ_2K]; |
| 1587 | const char *branch_props_json = p->frozen ? p->frozen->git_props : "{}"; |
| 1588 | if (!p->frozen && |
| 1589 | cbm_git_context_props_json(&p->git_ctx, branch_props, sizeof(branch_props)) > 0) { |
| 1590 | branch_props_json = branch_props; |
| 1591 | } |
| 1592 | if (p->branch_qn) { |
| 1593 | int64_t branch_id = cbm_gbuf_upsert_node(p->gbuf, "Branch", branch_name, branch_qn, NULL, 0, |
| 1594 | 0, branch_props_json); |
| 1595 | const cbm_gbuf_node_t *project_node = cbm_gbuf_find_by_qn(p->gbuf, p->project_name); |
| 1596 | if (project_node && branch_id > 0) { |
| 1597 | cbm_gbuf_insert_edge(p->gbuf, project_node->id, branch_id, "HAS_BRANCH", |
| 1598 | branch_props_json); |
| 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | /* Collect unique directories and create Folder/Package nodes */ |
| 1603 | CBMHashTable *seen_dirs = cbm_ht_create(CBM_SZ_256); |
| 1604 | |
| 1605 | for (int i = 0; i < file_count; i++) { |
| 1606 | const char *rel = files[i].rel_path; |
| 1607 | if (!rel) { |
| 1608 | continue; |
| 1609 | } |
| 1610 | |
| 1611 | /* Create File node */ |
| 1612 | char *file_qn = cbm_pipeline_fqn_compute(p->project_name, rel, "__file__"); |
| 1613 | /* Extract basename */ |
| 1614 | const char *slash = strrchr(rel, '/'); |
| 1615 | const char *basename = slash ? slash + SKIP_ONE : rel; |
| 1616 | |
| 1617 | char props[CBM_SZ_256]; |
| 1618 | const char *ext = strrchr(basename, '.'); |
| 1619 | snprintf(props, sizeof(props), "{\"extension\":\"%s\"}", ext ? ext : ""); |
| 1620 | |
| 1621 | const char *qualified_name = file_qn; |
| 1622 | const char *file_path = rel; |
| 1623 | cbm_gbuf_upsert_node(p->gbuf, "File", basename, qualified_name, file_path, 0, 0, props); |
| 1624 | |
| 1625 | /* CONTAINS_FILE edge: parent dir -> file */ |
| 1626 | char *dir = strdup(rel); |
| 1627 | char *last_slash = strrchr(dir, '/'); |
| 1628 | if (last_slash) { |
| 1629 | { |
| 1630 | *last_slash = '\0'; |
| 1631 | } |
| 1632 | } else { |
| 1633 | free(dir); |
| 1634 | dir = strdup(""); |
| 1635 | } |
no test coverage detected