Write artifact.json metadata. */
| 720 | |
| 721 | /* Write artifact.json metadata. */ |
| 722 | static int write_metadata(const char *repo_path, const char *project_name, const char *commit, |
| 723 | int nodes, int edges, size_t original_size, size_t compressed_size, |
| 724 | int compression_level, bool reconcile_trusted) { |
| 725 | char ts[CBM_SZ_64]; |
| 726 | iso_timestamp(ts, sizeof(ts)); |
| 727 | |
| 728 | yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL); |
| 729 | yyjson_mut_val *root = yyjson_mut_obj(doc); |
| 730 | yyjson_mut_doc_set_root(doc, root); |
| 731 | |
| 732 | yyjson_mut_obj_add_int(doc, root, "schema_version", CBM_ARTIFACT_SCHEMA_VERSION); |
| 733 | yyjson_mut_obj_add_str(doc, root, "commit", commit); |
| 734 | yyjson_mut_obj_add_str(doc, root, "indexed_at", ts); |
| 735 | yyjson_mut_obj_add_str(doc, root, "project", project_name); |
| 736 | yyjson_mut_obj_add_int(doc, root, "nodes", nodes); |
| 737 | yyjson_mut_obj_add_int(doc, root, "edges", edges); |
| 738 | yyjson_mut_obj_add_uint(doc, root, "original_size", (uint64_t)original_size); |
| 739 | yyjson_mut_obj_add_uint(doc, root, "compressed_size", (uint64_t)compressed_size); |
| 740 | yyjson_mut_obj_add_int(doc, root, "compression_level", compression_level); |
| 741 | /* Optional clean-basis marker: present only when export verified the DB |
| 742 | * matches a clean checked-out tree at `commit` (see cbm_artifact_export). |
| 743 | * Older binaries ignore this unknown field, so no schema_version bump. */ |
| 744 | if (reconcile_trusted) { |
| 745 | yyjson_mut_obj_add_str(doc, root, "reconcile_basis", "git-clean-head"); |
| 746 | } |
| 747 | |
| 748 | size_t json_len = 0; |
| 749 | char *json = yyjson_mut_write(doc, YYJSON_WRITE_PRETTY, &json_len); |
| 750 | yyjson_mut_doc_free(doc); |
| 751 | if (!json) { |
| 752 | return artifact_export_fail("write_metadata", NULL, "json_encode", 0); |
| 753 | } |
| 754 | |
| 755 | char meta_path[CBM_SZ_4K]; |
| 756 | if (!artifact_path(meta_path, sizeof(meta_path), repo_path, CBM_ARTIFACT_META)) { |
| 757 | free(json); |
| 758 | return artifact_export_fail("write_metadata", repo_path, "path_too_long", 0); |
| 759 | } |
| 760 | artifact_file_error_t ioerr; |
| 761 | int rc = write_file_atomic(meta_path, json, json_len, &ioerr); |
| 762 | free(json); |
| 763 | if (rc != 0) { |
| 764 | return artifact_export_fail("write_metadata", meta_path, ioerr.err, ioerr.err_no); |
| 765 | } |
| 766 | return rc; |
| 767 | } |
| 768 | |
| 769 | /* ── .gitattributes setup ────────────────────────────────────────── */ |
| 770 |
no test coverage detected