(&self, pos: Position<NodeId>)
| 137 | } |
| 138 | |
| 139 | fn find_block(&self, pos: Position<NodeId>) -> PristineResult<GraphNode<NodeId>> { |
| 140 | // Handle ROOT position specially - ROOT is a virtual span that doesn't |
| 141 | // exist in the database. It represents the repository root and is the |
| 142 | // parent of all top-level files and directories. |
| 143 | if pos.change.is_root() { |
| 144 | return Ok(GraphNode::ROOT); |
| 145 | } |
| 146 | |
| 147 | let table = self.txn.open_multimap_table(GRAPH)?; |
| 148 | |
| 149 | let change_id = pos.change.get(); |
| 150 | let target_pos = pos.pos.get(); |
| 151 | |
| 152 | let start_key = encode_vertex(change_id, 0, 0); |
| 153 | let end_key = encode_vertex(change_id, u64::MAX, u64::MAX); |
| 154 | |
| 155 | // Track empty span match as fallback |
| 156 | let mut empty_vertex_match: Option<GraphNode<NodeId>> = None; |
| 157 | |
| 158 | for result in table.range::<&[u8; 24]>(&start_key..=&end_key)? { |
| 159 | let (key, _values) = result?; |
| 160 | let (v_change, v_start, v_end) = decode_vertex(key.value()); |
| 161 | |
| 162 | if v_change != change_id { |
| 163 | continue; |
| 164 | } |
| 165 | |
| 166 | // Check for non-empty span containing this position. |
| 167 | // For edges pointing to content, we want to find the content span |
| 168 | // even if there's an empty inode span at the same start position. |
| 169 | // This is critical for graph traversal: an edge to position 9 should |
| 170 | // find content span V[9:23], not inode span V[9:9]. |
| 171 | if v_start != v_end && v_start <= target_pos && target_pos < v_end { |
| 172 | return Ok(GraphNode { |
| 173 | change: NodeId::new(v_change), |
| 174 | start: ChangePosition::new(v_start), |
| 175 | end: ChangePosition::new(v_end), |
| 176 | }); |
| 177 | } |
| 178 | |
| 179 | // Track empty span at exact position as fallback |
| 180 | if v_start == v_end && v_start == target_pos && empty_vertex_match.is_none() { |
| 181 | empty_vertex_match = Some(GraphNode { |
| 182 | change: NodeId::new(v_change), |
| 183 | start: ChangePosition::new(v_start), |
| 184 | end: ChangePosition::new(v_end), |
| 185 | }); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | // Return empty span if no non-empty span matched |
| 190 | if let Some(found) = empty_vertex_match { |
| 191 | return Ok(found); |
| 192 | } |
| 193 | |
| 194 | Err(PristineError::BlockNotFound { |
| 195 | change: change_id, |
| 196 | pos: target_pos, |
nothing calls this directly
no test coverage detected