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

Function collect_all_dependencies

atomic-repository/src/apply/mod.rs:480–525  ·  view source on GitHub ↗

Collect all dependencies needed to insert a change. This recursively collects all transitive dependencies. # Arguments `txn` - Read transaction `change` - The change to collect dependencies for `available` - Set of available change hashes `max_depth` - Maximum recursion depth # Returns Set of all dependency hashes needed (not including those already applied).

(
    txn: &T,
    change: &Change,
    available: &HashSet<Hash>,
    max_depth: usize,
)

Source from the content-addressed store, hash-verified

478///
479/// Set of all dependency hashes needed (not including those already applied).
480pub fn collect_all_dependencies<T: GraphTxnT>(
481 txn: &T,
482 change: &Change,
483 available: &HashSet<Hash>,
484 max_depth: usize,
485) -> InsertResult<HashSet<Hash>> {
486 let mut needed = HashSet::new();
487 let mut queue: VecDeque<(Hash, usize)> = VecDeque::new();
488 let mut visited = HashSet::new();
489
490 // Start with direct dependencies
491 for dep in change.dependencies() {
492 if !visited.contains(dep) {
493 queue.push_back((*dep, 0));
494 visited.insert(*dep);
495 }
496 }
497
498 while let Some((hash, depth)) = queue.pop_front() {
499 if depth > max_depth {
500 return Err(InsertError::CyclicDependency {
501 message: format!("Maximum dependency depth {} exceeded", max_depth),
502 });
503 }
504
505 // Check if already in repository
506 if txn
507 .get_internal(&hash)
508 .map_err(|e| InsertError::Database(e.to_string()))?
509 .is_some()
510 {
511 continue;
512 }
513
514 // Check if available
515 if available.contains(&hash) {
516 needed.insert(hash);
517 // Note: We'd need the actual change content to recurse further
518 // For now, we assume available changes have their deps satisfied
519 } else {
520 needed.insert(hash);
521 }
522 }
523
524 Ok(needed)
525}

Callers

nothing calls this directly

Calls 4

dependenciesMethod · 0.45
containsMethod · 0.45
insertMethod · 0.45
get_internalMethod · 0.45

Tested by

no test coverage detected