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

Method plan_tree_projection

atomic-repository/src/repository/deferred_tree.rs:817–958  ·  view source on GitHub ↗
(
        &self,
        txn: &mut atomic_core::pristine::WriteTxn<'_>,
        change_id: NodeId,
        change_hash: Hash,
        change: &Change,
        deleted_paths: &[String],
        preserv

Source from the content-addressed store, hash-verified

815 }
816
817 pub(super) fn plan_tree_projection(
818 &self,
819 txn: &mut atomic_core::pristine::WriteTxn<'_>,
820 change_id: NodeId,
821 change_hash: Hash,
822 change: &Change,
823 deleted_paths: &[String],
824 preserve_existing_tree_paths: bool,
825 ) -> Result<PreparedTreeProjection, RepositoryError> {
826 let ops = collect_tree_ops(&*txn, change_hash, change, deleted_paths, None)?;
827 let mut additions = Vec::<(Position<NodeId>, String, TreeProjectionKind)>::new();
828 for graph_op in change.hunks() {
829 match graph_op {
830 GraphOp::FileAdd {
831 add_inode, path, ..
832 } => additions.push((
833 Position::new(change_id, add_inode.start),
834 path.clone(),
835 TreeProjectionKind::File,
836 )),
837 GraphOp::DirAdd {
838 add_inode, path, ..
839 } => additions.push((
840 Position::new(change_id, add_inode.start),
841 path.clone(),
842 TreeProjectionKind::Directory,
843 )),
844 _ => {}
845 }
846 }
847 let addition_positions: HashSet<Position<NodeId>> =
848 additions.iter().map(|(position, _, _)| *position).collect();
849
850 // Resolve every non-add inode before allocating or mutating derived
851 // indexes. Missing change IDs and reverse inode rows fail closed here.
852 for op in &ops {
853 let internal_change = txn
854 .get_internal(&op.inode.change)
855 .map_err(|error| RepositoryError::Database(error.to_string()))?
856 .ok_or_else(|| RepositoryError::InvalidOperation {
857 message: format!(
858 "tree projection references unknown change {}",
859 op.inode.change.to_base32()
860 ),
861 })?;
862 let position = Position::new(internal_change, op.inode.pos);
863 if addition_positions.contains(&position) {
864 continue;
865 }
866 txn.position_inode(position)
867 .map_err(|error| RepositoryError::Database(error.to_string()))?
868 .ok_or_else(|| RepositoryError::InvalidOperation {
869 message: format!("tree projection position {} has no inode", position),
870 })?;
871 }
872
873 let mut projection_ops = Vec::new();
874 for (position, path, kind) in additions {

Calls 15

collect_tree_opsFunction · 0.85
external_positionFunction · 0.85
planFunction · 0.85
is_noneMethod · 0.80
hunksMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
collectMethod · 0.45
iterMethod · 0.45
get_internalMethod · 0.45
containsMethod · 0.45
position_inodeMethod · 0.45

Tested by

no test coverage detected