(&self, pos: Position<NodeId>)
| 279 | } |
| 280 | |
| 281 | fn find_block(&self, pos: Position<NodeId>) -> PristineResult<GraphNode<NodeId>> { |
| 282 | // Handle ROOT position specially - ROOT is a virtual span that doesn't |
| 283 | // exist in the database. It represents the repository root and is the |
| 284 | // parent of all top-level files and directories. |
| 285 | if pos.change.is_root() { |
| 286 | return Ok(GraphNode::ROOT); |
| 287 | } |
| 288 | |
| 289 | let table = self.txn.open_multimap_table(GRAPH)?; |
| 290 | |
| 291 | let change_id = pos.change.get(); |
| 292 | let target_pos = pos.pos.get(); |
| 293 | |
| 294 | // Binary-search candidates instead of scanning every vertex of the |
| 295 | // change (the historical full-range scan made each call |
| 296 | // O(change vertices); within one change the non-empty hunks are |
| 297 | // DISJOINT ranges of that change's contents buffer, so the containing |
| 298 | // vertex is the LAST vertex key ≤ (pos, u64::MAX) and the |
| 299 | // empty-vertex fallback is an exact-key lookup — review ::15, |
| 300 | // 2026-09-16). Semantics identical to the scan, including the |
| 301 | // inode/content start ambiguity (AGENTS.md "Position Ambiguity"). |
| 302 | let upper = encode_vertex(change_id, target_pos, u64::MAX); |
| 303 | if let Some((v_change, v_start, v_end)) = table |
| 304 | .range::<&[u8; 24]>(&encode_vertex(change_id, 0, 0)..=&upper)? |
| 305 | .next_back() |
| 306 | .transpose()? |
| 307 | .map(|(key, _values)| decode_vertex(key.value())) |
| 308 | { |
| 309 | if v_change == change_id |
| 310 | && v_start != v_end |
| 311 | && v_start <= target_pos |
| 312 | && target_pos < v_end |
| 313 | { |
| 314 | return Ok(GraphNode { |
| 315 | change: NodeId::new(change_id), |
| 316 | start: ChangePosition::new(v_start), |
| 317 | end: ChangePosition::new(v_end), |
| 318 | }); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | // Empty-vertex fallback: the exact key (change, pos, pos). |
| 323 | let empty_key = encode_vertex(change_id, target_pos, target_pos); |
| 324 | if try_is_present(table.get(&empty_key)?)? { |
| 325 | return Ok(GraphNode { |
| 326 | change: NodeId::new(change_id), |
| 327 | start: ChangePosition::new(target_pos), |
| 328 | end: ChangePosition::new(target_pos), |
| 329 | }); |
| 330 | } |
| 331 | |
| 332 | Err(PristineError::BlockNotFound { |
| 333 | change: change_id, |
| 334 | pos: target_pos, |
| 335 | }) |
| 336 | } |
| 337 | |
| 338 | fn find_block_end(&self, pos: Position<NodeId>) -> PristineResult<GraphNode<NodeId>> { |
nothing calls this directly
no test coverage detected