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

Function build_view_chain

libatomic/src/daemon/services_sync_remote.rs:159–181  ·  view source on GitHub ↗

The local `build_view_chain` — the ancestor chain, root → leaf, with the cycle guard.

(repo: &Repository, leaf: &str)

Source from the content-addressed store, hash-verified

157/// The local `build_view_chain` — the ancestor chain, root → leaf, with
158/// the cycle guard.
159fn build_view_chain(repo: &Repository, leaf: &str) -> Result<Vec<String>, Status> {
160 let mut chain = vec![leaf.to_string()];
161 let mut visited: HashSet<String> = HashSet::new();
162 visited.insert(leaf.to_string());
163 let mut current = leaf.to_string();
164 loop {
165 let parent = repo
166 .get_view_info(&current)
167 .map_err(|_| domain_status(ErrorCode::View, format!("view '{current}' not found")))?
168 .parent_name;
169 let Some(parent) = parent else { break };
170 if !visited.insert(parent.clone()) {
171 return Err(domain_status(
172 ErrorCode::InvalidArgument,
173 format!("view parent chain contains a cycle at '{parent}'"),
174 ));
175 }
176 chain.push(parent.clone());
177 current = parent;
178 }
179 chain.reverse();
180 Ok(chain)
181}
182
183/// The remote ref advertisement — the local `parse_advertisement`.
184#[derive(Clone)]

Callers 1

push_changes_implFunction · 0.70

Calls 6

domain_statusFunction · 0.85
get_view_infoMethod · 0.80
insertMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45
reverseMethod · 0.45

Tested by

no test coverage detected