| 139 | |
| 140 | impl Repository { |
| 141 | pub(super) fn query_view(&self, view_name: &str) -> Result<QueryView<'_>, RepositoryError> { |
| 142 | let txn = self.pristine.read_txn()?; |
| 143 | let view = txn |
| 144 | .get_view(view_name)? |
| 145 | .ok_or_else(|| RepositoryError::ViewNotFound { |
| 146 | name: view_name.to_string(), |
| 147 | })?; |
| 148 | let visibility = graph_visibility_closure(&txn, &view)?; |
| 149 | let projection = self.project_tree_for_visibility(&txn, &visibility)?; |
| 150 | if !projection.name_conflicts.is_empty() { |
| 151 | return Err(RepositoryError::InvalidOperation { |
| 152 | message: "cannot query a view with unresolved path claims".to_string(), |
| 153 | }); |
| 154 | } |
| 155 | let mut changes = HashSet::new(); |
| 156 | for id in visibility |
| 157 | .iter_dependency_first() |
| 158 | .filter(|id| !id.is_root()) |
| 159 | { |
| 160 | let hash = txn.get_external(*id)?.ok_or_else(|| { |
| 161 | RepositoryError::Database(format!("visible change {id} has no hash")) |
| 162 | })?; |
| 163 | changes.insert(iri::mint_change(&hash)); |
| 164 | } |
| 165 | let project = self.project_id()?; |
| 166 | let views = txn |
| 167 | .resolve_full_view_chain(&view)? |
| 168 | .into_iter() |
| 169 | .map(|view| iri::mint_view(&project, &view.name)) |
| 170 | .collect(); |
| 171 | let rules = IgnoreRules::load_for_enrichment(self.root()); |
| 172 | let mut files = BTreeMap::new(); |
| 173 | for (path, item) in projection.present { |
| 174 | if item.is_directory |
| 175 | || crate::ignore::is_enrichment_internal(Path::new(&path)) |
| 176 | || rules.is_ignored(Path::new(&path), false) |
| 177 | { |
| 178 | continue; |
| 179 | } |
| 180 | let attrs = atomic_core::output::project_inode_attributes( |
| 181 | &txn, |
| 182 | item.position, |
| 183 | visibility.attribute_visibility(), |
| 184 | ) |
| 185 | .map_err(|error| RepositoryError::Database(error.to_string()))?; |
| 186 | if attrs.is_conflicted() { |
| 187 | return Err(RepositoryError::InvalidOperation { |
| 188 | message: format!("cannot query '{path}' with conflicting inode attributes"), |
| 189 | }); |
| 190 | } |
| 191 | // Never follow a symlink into working-copy or external content. |
| 192 | if attrs.materialization.kind != atomic_core::change::InodeKind::Regular { |
| 193 | continue; |
| 194 | } |
| 195 | files.insert(path, (item.inode, item.position)); |
| 196 | } |
| 197 | let nodes = files |
| 198 | .keys() |