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

Method import_view_snapshot

atomic-core/src/pristine/slice.rs:681–725  ·  view source on GitHub ↗

Write `snapshot` as a view — its own scope, its own parent, its own change log, with the repository's id, state and change count — replacing any view with that name or id. The parent link matters only if something will follow it: a cache that holds `sb` with `parent: dev`, and a `dev` row with dev's real log, reconstructs the union the repository computes. A snapshot written parentless and shared

(&mut self, snapshot: &ViewSnapshotRows)

Source from the content-addressed store, hash-verified

679 /// view's *own* changes and the ancestors arrive beside it in the
680 /// skeleton, not folded into this log.
681 pub fn import_view_snapshot(&mut self, snapshot: &ViewSnapshotRows) -> PristineResult<()> {
682 let state = ViewState {
683 id: snapshot.id,
684 name: snapshot.name.clone(),
685 state: snapshot.state,
686 change_count: snapshot.change_count,
687 kind: snapshot.kind,
688 parent: snapshot.parent,
689 };
690 {
691 let mut views = self.txn.open_table(VIEWS)?;
692 let mut stale = Vec::new();
693 for row in views.iter()? {
694 let (k, v) = row?;
695 let existing = crate::pristine::txn::deserialize_view_state(v.value())?;
696 if existing.id == snapshot.id || k.value() == snapshot.name {
697 stale.push(k.value().to_string());
698 }
699 }
700 for name in stale {
701 views.remove(name.as_str())?;
702 }
703 let bytes = crate::pristine::txn::serialize_view_state(&state);
704 views.insert(snapshot.name.as_str(), bytes.as_slice())?;
705 }
706 let lo = encode_view_seq(snapshot.id, 0);
707 let hi = encode_view_seq(snapshot.id, u64::MAX);
708 {
709 let mut log = self.txn.open_table(VIEW_CHANGES)?;
710 log.retain_in::<&[u8; 16], _>(&lo..=&hi, |_, _| false)?;
711 for (seq, change) in snapshot.visible.iter().enumerate() {
712 log.insert(&encode_view_seq(snapshot.id, seq as u64), *change)?;
713 }
714 }
715 {
716 let mut rev = self.txn.open_table(REV_VIEW_CHANGES)?;
717 rev.retain_in::<&[u8; 16], _>(&lo..=&hi, |_, _| false)?;
718 for (seq, change) in snapshot.visible.iter().enumerate() {
719 rev.insert(&encode_view_seq(snapshot.id, *change), seq as u64)?;
720 }
721 }
722 self.next_view_id
723 .fetch_max(snapshot.id + 1, std::sync::atomic::Ordering::SeqCst);
724 Ok(())
725 }
726}
727
728#[cfg(test)]

Callers 1

Calls 11

deserialize_view_stateFunction · 0.85
serialize_view_stateFunction · 0.85
encode_view_seqFunction · 0.85
valueMethod · 0.80
removeMethod · 0.65
cloneMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45
as_strMethod · 0.45
insertMethod · 0.45
as_sliceMethod · 0.45

Tested by

no test coverage detected