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

Function prepare_migration

atomic-repository/src/repository/migration.rs:149–362  ·  view source on GitHub ↗
(
    pristine: &Pristine,
    change_store: &ChangeStore,
    current_view: &str,
    recovered_inode_index: &HashMap<Position<NodeId>, Inode>,
    applied_changes: &HashSet<NodeId>,
)

Source from the content-addressed store, hash-verified

147}
148
149fn prepare_migration(
150 pristine: &Pristine,
151 change_store: &ChangeStore,
152 current_view: &str,
153 recovered_inode_index: &HashMap<Position<NodeId>, Inode>,
154 applied_changes: &HashSet<NodeId>,
155) -> Result<MigrationPlan, RepositoryError> {
156 let txn = pristine
157 .read_txn()
158 .map_err(|error| RepositoryError::Database(error.to_string()))?;
159
160 let mut view_names = txn
161 .list_views()
162 .map_err(|error| RepositoryError::Database(error.to_string()))?;
163 view_names.sort();
164 let mut reachable = Vec::new();
165 let mut seen = HashSet::new();
166 for view_name in view_names {
167 let view = txn
168 .get_view(&view_name)
169 .map_err(|error| RepositoryError::Database(error.to_string()))?
170 .ok_or_else(|| RepositoryError::ViewNotFound {
171 name: view_name.clone(),
172 })?;
173 let visibility = graph_visibility_closure(&txn, &view)?;
174 for change_id in visibility.iter_dependency_first().copied() {
175 if !change_id.is_root() && seen.insert(change_id) {
176 reachable.push(change_id);
177 }
178 }
179 }
180
181 for (change_id, _) in txn
182 .list_registered_changes()
183 .map_err(|error| RepositoryError::Database(error.to_string()))?
184 {
185 if !change_id.is_root() && applied_changes.contains(&change_id) && seen.insert(change_id) {
186 reachable.push(change_id);
187 }
188 }
189
190 // Stable dependency-first order independent of view enumeration. A change's
191 // direct dependencies always precede it in every validated closure; use a
192 // small DFS over the reachable union to preserve that invariant globally.
193 let mut ordered = Vec::with_capacity(reachable.len());
194 let mut visiting = HashSet::new();
195 let mut visited = HashSet::new();
196 for change_id in reachable {
197 visit_change(&txn, change_id, &mut visiting, &mut visited, &mut ordered)?;
198 }
199
200 let mut claims = Vec::new();
201 for change_id in ordered {
202 let hash = txn
203 .get_external(change_id)
204 .map_err(|error| RepositoryError::Database(error.to_string()))?
205 .ok_or_else(|| {
206 RepositoryError::Database(format!(

Callers 1

Calls 15

graph_visibility_closureFunction · 0.85
visit_changeFunction · 0.85
read_txnMethod · 0.80
sortMethod · 0.80
iter_dependency_firstMethod · 0.80
contains_keyMethod · 0.80
getMethod · 0.65
list_viewsMethod · 0.45
get_viewMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected