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

Function tokenize_single_file

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

Tokenize a single file's content. This runs on a rayon worker thread for parallel regeneration.

(path: &str, content: &[u8], skip_binary: bool)

Source from the content-addressed store, hash-verified

610///
611/// This runs on a rayon worker thread for parallel regeneration.
612fn tokenize_single_file(path: &str, content: &[u8], skip_binary: bool) -> FileRegenResult {
613 if content.is_empty() {
614 return FileRegenResult {
615 path: path.to_string(),
616 file_ops: FileOps::create(TrunkId::new(NodeId::new(0), 0), path.to_string(), None),
617 crdt_stats: CrdtBuildStats::default(),
618 skipped: true,
619 error: None,
620 };
621 }
622
623 let encoding = detect_encoding(content);
624
625 if encoding == Encoding::Binary && skip_binary {
626 return FileRegenResult {
627 path: path.to_string(),
628 file_ops: FileOps::create(
629 TrunkId::new(NodeId::new(0), 0),
630 path.to_string(),
631 Some(Encoding::Binary),
632 ),
633 crdt_stats: CrdtBuildStats::default(),
634 skipped: true,
635 error: None,
636 };
637 }
638
639 // Tokenize using the same pipeline as record
640 let placeholder_change_id = NodeId::new(0);
641 let mut builder = CrdtChangeBuilder::new(placeholder_change_id);
642
643 let enc = if encoding == Encoding::Binary {
644 None
645 } else {
646 Some(encoding)
647 };
648
649 builder.add_file_with_content(path, content, enc);
650
651 let result = builder.finish();
652 let crdt_stats = result.stats().clone();
653 let (file_ops_list, _, _) = result.into_parts();
654
655 let file_ops = file_ops_list
656 .into_iter()
657 .next()
658 .map(|builder_ops| builder_ops.into_change_ops())
659 .unwrap_or_else(|| {
660 FileOps::create(
661 TrunkId::new(placeholder_change_id, 0),
662 path.to_string(),
663 enc,
664 )
665 });
666
667 FileRegenResult {
668 path: path.to_string(),
669 file_ops,

Calls 10

add_file_with_contentMethod · 0.80
into_change_opsMethod · 0.80
detect_encodingFunction · 0.70
is_emptyMethod · 0.45
finishMethod · 0.45
cloneMethod · 0.45
statsMethod · 0.45
into_partsMethod · 0.45
nextMethod · 0.45
into_iterMethod · 0.45