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

Function write_metadata

src/pipeline/artifact.c:321–362  ·  view source on GitHub ↗

Write artifact.json metadata. */

Source from the content-addressed store, hash-verified

319
320/* Write artifact.json metadata. */
321static int write_metadata(const char *repo_path, const char *project_name, int nodes, int edges,
322 size_t original_size, size_t compressed_size, int compression_level) {
323 char commit[CBM_SZ_64] = "";
324 git_head_hash(repo_path, commit, sizeof(commit));
325
326 char ts[CBM_SZ_64];
327 iso_timestamp(ts, sizeof(ts));
328
329 yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
330 yyjson_mut_val *root = yyjson_mut_obj(doc);
331 yyjson_mut_doc_set_root(doc, root);
332
333 yyjson_mut_obj_add_int(doc, root, "schema_version", CBM_ARTIFACT_SCHEMA_VERSION);
334 yyjson_mut_obj_add_str(doc, root, "commit", commit);
335 yyjson_mut_obj_add_str(doc, root, "indexed_at", ts);
336 yyjson_mut_obj_add_str(doc, root, "project", project_name);
337 yyjson_mut_obj_add_int(doc, root, "nodes", nodes);
338 yyjson_mut_obj_add_int(doc, root, "edges", edges);
339 yyjson_mut_obj_add_uint(doc, root, "original_size", (uint64_t)original_size);
340 yyjson_mut_obj_add_uint(doc, root, "compressed_size", (uint64_t)compressed_size);
341 yyjson_mut_obj_add_int(doc, root, "compression_level", compression_level);
342
343 size_t json_len = 0;
344 char *json = yyjson_mut_write(doc, YYJSON_WRITE_PRETTY, &json_len);
345 yyjson_mut_doc_free(doc);
346 if (!json) {
347 return artifact_export_fail("write_metadata", NULL, "json_encode", 0);
348 }
349
350 char meta_path[CBM_SZ_4K];
351 if (!artifact_path(meta_path, sizeof(meta_path), repo_path, CBM_ARTIFACT_META)) {
352 free(json);
353 return artifact_export_fail("write_metadata", repo_path, "path_too_long", 0);
354 }
355 artifact_file_error_t ioerr;
356 int rc = write_file_atomic(meta_path, json, json_len, &ioerr);
357 free(json);
358 if (rc != 0) {
359 return artifact_export_fail("write_metadata", meta_path, ioerr.err, ioerr.err_no);
360 }
361 return rc;
362}
363
364/* ── .gitattributes setup ────────────────────────────────────────── */
365

Callers 1

cbm_artifact_exportFunction · 0.85

Calls 5

git_head_hashFunction · 0.85
iso_timestampFunction · 0.85
artifact_export_failFunction · 0.85
artifact_pathFunction · 0.85
write_file_atomicFunction · 0.85

Tested by

no test coverage detected