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