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

Function collect_tree

atomic-core/src/output/repo/tree.rs:783–857  ·  view source on GitHub ↗

Collect children from the tree under a given path. This function traverses the TREE table to find all files and directories under the specified parent path, applying the given options for filtering. # Arguments `txn` - Transaction providing tree access `parent_path` - Path to start from (empty for root) `options` - Collection options # Returns A `TreeCollectResult` containing all matching ite

(
    txn: &T,
    parent_path: &str,
    options: TreeCollectOptions,
)

Source from the content-addressed store, hash-verified

781/// let src_result = collect_tree(&txn, "", options)?;
782/// ```
783pub fn collect_tree<T: TreeTxnT + GraphTxnT>(
784 txn: &T,
785 parent_path: &str,
786 options: TreeCollectOptions,
787) -> Result<TreeCollectResult, PristineError> {
788 let mut result = TreeCollectResult::new();
789
790 // Track directories we've seen to avoid duplicates
791 let mut seen_directories: HashSet<String> = HashSet::new();
792
793 // Iterate over all tree entries
794 for entry in txn.iter_tree()? {
795 let (path, inode) = entry?;
796
797 // Skip if path doesn't start with parent_path
798 if !parent_path.is_empty() && !path.starts_with(parent_path) {
799 continue;
800 }
801
802 // Check filters
803 if !options.should_include(&path) {
804 result.record_skipped();
805 continue;
806 }
807
808 // Check depth
809 if options.exceeds_depth(&path) {
810 result.record_skipped();
811 continue;
812 }
813
814 // Collect parent directories if needed
815 if options.collect_directories {
816 let mut current = String::new();
817 for component in path.split('/') {
818 if !current.is_empty() {
819 current.push('/');
820 }
821 current.push_str(component);
822
823 // Don't add the file itself as a directory
824 if current == path {
825 break;
826 }
827
828 // Check if we should include this directory
829 if !seen_directories.contains(&current)
830 && options.should_include(&current)
831 && !options.exceeds_depth(&current)
832 {
833 seen_directories.insert(current.clone());
834 // We don't have the inode for intermediate directories
835 // In a full implementation, we'd look this up
836 result.add_directory(TreeItem::directory(&current, Inode::ROOT));
837 }
838 }
839 }
840

Callers 3

collect_filesFunction · 0.85
collect_directoriesFunction · 0.85
collect_childrenFunction · 0.85

Calls 13

exceeds_depthMethod · 0.80
iter_treeMethod · 0.45
is_emptyMethod · 0.45
should_includeMethod · 0.45
record_skippedMethod · 0.45
pushMethod · 0.45
containsMethod · 0.45
insertMethod · 0.45
cloneMethod · 0.45
add_directoryMethod · 0.45
inode_positionMethod · 0.45
record_errorMethod · 0.45

Tested by

no test coverage detected