| 805 | /* ── Commit hash extraction ──────────────────────────────────────── */ |
| 806 | |
| 807 | char *cbm_artifact_commit(const char *repo_path) { |
| 808 | if (!repo_path) { |
| 809 | return NULL; |
| 810 | } |
| 811 | |
| 812 | char meta_path[CBM_SZ_4K]; |
| 813 | artifact_path(meta_path, sizeof(meta_path), repo_path, CBM_ARTIFACT_META); |
| 814 | |
| 815 | size_t len = 0; |
| 816 | char *json = read_file_alloc(meta_path, &len); |
| 817 | if (!json) { |
| 818 | return NULL; |
| 819 | } |
| 820 | |
| 821 | yyjson_doc *doc = yyjson_read(json, len, 0); |
| 822 | free(json); |
| 823 | if (!doc) { |
| 824 | return NULL; |
| 825 | } |
| 826 | |
| 827 | yyjson_val *root = yyjson_doc_get_root(doc); |
| 828 | yyjson_val *val = yyjson_obj_get(root, "commit"); |
| 829 | char *result = NULL; |
| 830 | if (val) { |
| 831 | const char *s = yyjson_get_str(val); |
| 832 | if (s && s[0]) { |
| 833 | size_t slen = strlen(s); |
| 834 | result = malloc(slen + ART_NUL); |
| 835 | if (result) { |
| 836 | memcpy(result, s, slen + ART_NUL); |
| 837 | } |
| 838 | } |
| 839 | } |
| 840 | yyjson_doc_free(doc); |
| 841 | return result; |
| 842 | } |
no test coverage detected