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

Function collect_tree

atomic-core/src/output/repo/tree.rs:788–867  ·  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

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

Callers 3

collect_filesFunction · 0.85
collect_directoriesFunction · 0.85
collect_childrenFunction · 0.85

Calls 14

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