(
pristine: &Pristine,
change_store: &ChangeStore,
current_view: &str,
recovered_inode_index: &HashMap<Position<NodeId>, Inode>,
applied_changes: &HashSet<NodeId>,
)
| 147 | } |
| 148 | |
| 149 | fn 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!( |
no test coverage detected