MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / store_semantic_sections

Function store_semantic_sections

atomic-repository/src/semantic_regen.rs:679–721  ·  view source on GitHub ↗

Store regenerated semantic sections in the redb CHANGE_SEMANTIC table. This updates the change's metadata to reflect the new semantic section count.

(
    store: &RedbChangeStore,
    hash: &[u8; 32],
    payloads: &[Vec<u8>],
)

Source from the content-addressed store, hash-verified

677///
678/// This updates the change's metadata to reflect the new semantic section count.
679fn store_semantic_sections(
680 store: &RedbChangeStore,
681 hash: &[u8; 32],
682 payloads: &[Vec<u8>],
683) -> RegenResult<()> {
684 // We need direct redb access to write semantic sections without
685 // going through the full import pipeline. Access the database
686 // through the store's public API by doing a save-roundtrip
687 // of the metadata with updated counts.
688 //
689 // For now, use the import path: export the change to V3 bytes,
690 // modify it to include semantic sections, and re-import.
691 // This is not optimal but correct and avoids exposing redb internals.
692 //
693 // TODO: Add a dedicated `store_semantic_sections` method to RedbChangeStore
694 // that writes directly to CHANGE_SEMANTIC without a full re-import.
695
696 // Load the current change
697 let change = store.load_change(hash).map_err(RegenError::from)?;
698
699 // Build a new change with the regenerated semantic ops
700 // The payloads are serialized Vec<FileOps>, but we need to extract them
701 let mut all_file_ops: Vec<FileOps> = Vec::new();
702 for payload in payloads {
703 match postcard::from_bytes::<Vec<FileOps>>(payload) {
704 Ok(ops) => {
705 all_file_ops.extend(ops);
706 }
707 Err(e) => {
708 log::warn!("Failed to deserialize FileOps payload: {}", e);
709 }
710 }
711 }
712
713 // Create a new Change with the semantic ops included
714 let mut updated = change;
715 updated.hashed.file_ops = all_file_ops;
716
717 // Re-save to the store (this will update both graph and semantic sections)
718 store.save_change(&updated).map_err(RegenError::from)?;
719
720 Ok(())
721}
722
723// ═══════════════════════════════════════════════════════════════════════
724// regenerate_all — batch regeneration

Callers 1

regenerate_changeFunction · 0.85

Calls 3

extendMethod · 0.80
load_changeMethod · 0.45
save_changeMethod · 0.45

Tested by

no test coverage detected