| 115 | } |
| 116 | |
| 117 | fn desired_tree_paths<F>( |
| 118 | ops: &[DeferredTreeOp], |
| 119 | visible_changes: &HashSet<Hash>, |
| 120 | mut depends_on: F, |
| 121 | ) -> Result<HashMap<Position<Hash>, DesiredTreePath>, RepositoryError> |
| 122 | where |
| 123 | F: FnMut(Hash, Hash) -> Result<bool, RepositoryError>, |
| 124 | { |
| 125 | let mut by_inode: HashMap<Position<Hash>, Vec<(usize, &DeferredTreeOp)>> = HashMap::new(); |
| 126 | for (order, op) in ops.iter().enumerate() { |
| 127 | by_inode.entry(op.inode).or_default().push((order, op)); |
| 128 | } |
| 129 | |
| 130 | let mut desired = HashMap::new(); |
| 131 | for (inode, inode_ops) in by_inode { |
| 132 | let baseline = inode_ops |
| 133 | .iter() |
| 134 | .find_map(|(_, op)| op.baseline_path.clone()); |
| 135 | let mut known_paths: HashSet<String> = inode_ops |
| 136 | .iter() |
| 137 | .filter_map(|(_, op)| op.baseline_path.clone()) |
| 138 | .collect(); |
| 139 | let mut directory = None; |
| 140 | for (_, op) in &inode_ops { |
| 141 | if let DeferredTreeAction::Set { path } = &op.action { |
| 142 | known_paths.insert(path.clone()); |
| 143 | } |
| 144 | if let Some(candidate) = op.directory { |
| 145 | if directory.is_some_and(|existing| existing != candidate) { |
| 146 | return Err(RepositoryError::InvalidOperation { |
| 147 | message: format!( |
| 148 | "tree projection metadata changes inode {} from file to directory", |
| 149 | inode.pos.get() |
| 150 | ), |
| 151 | }); |
| 152 | } |
| 153 | directory = Some(candidate); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | let visible: Vec<(usize, &DeferredTreeOp)> = inode_ops |
| 158 | .into_iter() |
| 159 | .filter(|(_, op)| visible_changes.contains(&op.change)) |
| 160 | .collect(); |
| 161 | let mut maximal = Vec::new(); |
| 162 | for (index, candidate) in &visible { |
| 163 | let mut superseded = false; |
| 164 | for (other_index, other) in &visible { |
| 165 | if index == other_index { |
| 166 | continue; |
| 167 | } |
| 168 | if (candidate.change == other.change && other_index > index) |
| 169 | || (candidate.change != other.change |
| 170 | && depends_on(other.change, candidate.change)?) |
| 171 | { |
| 172 | superseded = true; |
| 173 | break; |
| 174 | } |