(&self, pos: Position<NodeId>)
| 67 | } |
| 68 | |
| 69 | fn find_block(&self, pos: Position<NodeId>) -> PristineResult<GraphNode<NodeId>> { |
| 70 | // Handle ROOT position specially - ROOT is a virtual span that doesn't |
| 71 | // exist in the database. It represents the repository root and is the |
| 72 | // parent of all top-level files and directories. |
| 73 | if pos.change.is_root() { |
| 74 | return Ok(GraphNode::ROOT); |
| 75 | } |
| 76 | |
| 77 | let table = self.txn.open_multimap_table(GRAPH)?; |
| 78 | |
| 79 | let change_id = pos.change.get(); |
| 80 | let target_pos = pos.pos.get(); |
| 81 | |
| 82 | let start_key = encode_vertex(change_id, 0, 0); |
| 83 | let end_key = encode_vertex(change_id, u64::MAX, u64::MAX); |
| 84 | |
| 85 | // Track empty span match as fallback |
| 86 | let mut empty_vertex_match: Option<GraphNode<NodeId>> = None; |
| 87 | |
| 88 | for result in table.range::<&[u8; 24]>(&start_key..=&end_key)? { |
| 89 | let (key, _values) = result?; |
| 90 | let (v_change, v_start, v_end) = decode_vertex(key.value()); |
| 91 | |
| 92 | if v_change != change_id { |
| 93 | continue; |
| 94 | } |
| 95 | |
| 96 | // Check for non-empty span containing this position. |
| 97 | // For edges pointing to content, we want to find the content span |
| 98 | // even if there's an empty inode span at the same start position. |
| 99 | // This is critical for graph traversal: an edge to position 9 should |
| 100 | // find content span V[9:23], not inode span V[9:9]. |
| 101 | if v_start != v_end && v_start <= target_pos && target_pos < v_end { |
| 102 | return Ok(GraphNode { |
| 103 | change: NodeId::new(v_change), |
| 104 | start: ChangePosition::new(v_start), |
| 105 | end: ChangePosition::new(v_end), |
| 106 | }); |
| 107 | } |
| 108 | |
| 109 | // Track empty span at exact position as fallback |
| 110 | if v_start == v_end && v_start == target_pos && empty_vertex_match.is_none() { |
| 111 | empty_vertex_match = Some(GraphNode { |
| 112 | change: NodeId::new(v_change), |
| 113 | start: ChangePosition::new(v_start), |
| 114 | end: ChangePosition::new(v_end), |
| 115 | }); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // Return empty span if no non-empty span matched |
| 120 | if let Some(found) = empty_vertex_match { |
| 121 | return Ok(found); |
| 122 | } |
| 123 | |
| 124 | Err(PristineError::BlockNotFound { |
| 125 | change: change_id, |
| 126 | pos: target_pos, |
nothing calls this directly
no test coverage detected