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

Method collect_hunk_hashes

atomic-core/src/change/change.rs:590–747  ·  view source on GitHub ↗

Collect all unique hashes referenced by hunks into the hash dedup table. This walks every position, graph node, and introduced_by field in every hunk and registers each `Some(Hash)` in the table.

(
        &self,
        table: &mut format_v3::HashDedupTable,
    )

Source from the content-addressed store, hash-verified

588 /// This walks every position, graph node, and introduced_by field in
589 /// every hunk and registers each `Some(Hash)` in the table.
590 fn collect_hunk_hashes(
591 &self,
592 table: &mut format_v3::HashDedupTable,
593 ) -> Result<(), format_v3::FormatError> {
594 use crate::change::atom::{Atom, EdgeUpdate, Insertion, NewEdge};
595
596 fn collect_position_hash(
597 pos: &crate::Position<Option<Hash>>,
598 table: &mut format_v3::HashDedupTable,
599 ) -> Result<(), format_v3::FormatError> {
600 if let Some(ref h) = pos.change {
601 table.insert(*h.as_bytes())?;
602 }
603 Ok(())
604 }
605
606 fn collect_graph_node_hash(
607 node: &crate::GraphNode<Option<Hash>>,
608 table: &mut format_v3::HashDedupTable,
609 ) -> Result<(), format_v3::FormatError> {
610 if let Some(ref h) = node.change {
611 table.insert(*h.as_bytes())?;
612 }
613 Ok(())
614 }
615
616 fn collect_insertion_hashes(
617 v: &Insertion<Option<Hash>>,
618 table: &mut format_v3::HashDedupTable,
619 ) -> Result<(), format_v3::FormatError> {
620 for p in &v.predecessors {
621 collect_position_hash(p, table)?;
622 }
623 for p in &v.successors {
624 collect_position_hash(p, table)?;
625 }
626 collect_position_hash(&v.inode, table)?;
627 Ok(())
628 }
629
630 fn collect_new_edge_hashes(
631 e: &NewEdge<Option<Hash>>,
632 table: &mut format_v3::HashDedupTable,
633 ) -> Result<(), format_v3::FormatError> {
634 collect_position_hash(&e.from, table)?;
635 collect_graph_node_hash(&e.to, table)?;
636 if let Some(ref h) = e.introduced_by {
637 table.insert(*h.as_bytes())?;
638 }
639 Ok(())
640 }
641
642 fn collect_edge_update_hashes(
643 em: &EdgeUpdate<Option<Hash>>,
644 table: &mut format_v3::HashDedupTable,
645 ) -> Result<(), format_v3::FormatError> {
646 for e in &em.edges {
647 collect_new_edge_hashes(e, table)?;

Callers 1

serializeMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected