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

Function output_file_to_buffer

atomic-core/src/output/repo/file.rs:778–833  ·  view source on GitHub ↗

Output a file to a buffer instead of the working copy. This is useful for testing, previewing, or cases where you want the content in memory rather than written to disk. # Arguments `txn` - Transaction providing graph access `changes` - Change store for retrieving span content `position` - Position in the graph `options` - Output options # Returns A tuple of (content bytes, conflicts). # Err

(
    txn: &T,
    changes: &C,
    position: Position<NodeId>,
    options: FileOutputOptions,
)

Source from the content-addressed store, hash-verified

776/// println!("File content:\n{}", text);
777/// ```
778pub fn output_file_to_buffer<T, C>(
779 txn: &T,
780 changes: &C,
781 position: Position<NodeId>,
782 options: FileOutputOptions,
783) -> Result<(Vec<u8>, Vec<FileConflict>), OutputError>
784where
785 T: GraphTxnT,
786 C: ChangeStore,
787{
788 // Retrieve the alive graph
789 let retrieve_opts = options.to_retrieve_options();
790 let retrieve_result = retrieve_graph(txn, position, retrieve_opts)
791 .map_err(|e| OutputError::Pristine(Box::new(e)))?;
792
793 // Handle empty graph
794 if retrieve_result.graph.is_empty() {
795 return Ok((Vec::new(), Vec::new()));
796 }
797
798 // Compute SCC ordering
799 let mut graph = retrieve_result.graph;
800 let order = compute_order(&mut graph);
801
802 // Create buffer writer
803 let buffer = Vec::new();
804 let mut writer = Writer::new(buffer);
805
806 // Hash function to convert NodeId to Hash using the transaction.
807 // This is required for the ChangeStore to load the correct change file
808 // and retrieve the content bytes for each span.
809 let hash_fn = |node_id: NodeId| txn.get_external(node_id);
810
811 // Attempt semantic merge for any conflicting SCCs
812 let resolved = resolve_conflicts_semantically(txn, changes, &graph, &order)?;
813
814 // Output the graph content (with semantic merge resolution)
815 output_graph_content_resolved(changes, hash_fn, &graph, &order, &mut writer, &resolved)?;
816
817 // Extract buffer
818 let content = writer.into_inner();
819
820 // Extract conflicts from cyclic SCCs (only those NOT resolved by semantic merge)
821 let mut conflicts = Vec::new();
822 let mut conflict_id: u32 = 0;
823 for scc in &order.sccs {
824 if scc.len() > 1 && resolved.get_merged(scc[0]).is_none() {
825 conflict_id += 1;
826 conflicts.push(
827 FileConflict::new(String::new(), FileConflictType::Cyclic).with_id(conflict_id),
828 );
829 }
830 }
831
832 Ok((content, conflicts))
833}
834
835/// Output a file's content to a buffer with explicit retrieve options.

Callers 1

Calls 14

retrieve_graphFunction · 0.85
PristineClass · 0.85
compute_orderFunction · 0.85
to_retrieve_optionsMethod · 0.80
is_noneMethod · 0.80
get_mergedMethod · 0.80
with_idMethod · 0.80
is_emptyMethod · 0.45
get_externalMethod · 0.45
into_innerMethod · 0.45

Tested by

no test coverage detected