Retrieve all lines for a file by trunk ID.
(
txn: &mut T,
trunk_id: TrunkId,
options: &RetrievalOptions,
)
| 329 | |
| 330 | /// Retrieve all lines for a file by trunk ID. |
| 331 | pub fn get_file_lines_by_trunk<T: MutTxnT>( |
| 332 | txn: &mut T, |
| 333 | trunk_id: TrunkId, |
| 334 | options: &RetrievalOptions, |
| 335 | ) -> PristineResult<Vec<Line>> { |
| 336 | // Get all branches for this trunk **in file order**. The BRANCH_AFTER |
| 337 | // chain produces top-of-file → bottom-of-file ordering — TRUNK_BRANCHES |
| 338 | // alone gives BranchId sort order, which is wrong for prepended lines |
| 339 | // from later commits. |
| 340 | let branch_ids: Vec<BranchId> = iter_trunk_branches_in_file_order(txn, trunk_id)?; |
| 341 | |
| 342 | let mut lines = Vec::new(); |
| 343 | let mut line_number = 1usize; |
| 344 | |
| 345 | for branch_id in branch_ids { |
| 346 | let branch_key = encode_branch_id(&branch_id); |
| 347 | |
| 348 | // Check line limit |
| 349 | if let Some(max) = options.max_lines { |
| 350 | if lines.len() >= max { |
| 351 | break; |
| 352 | } |
| 353 | } |
| 354 | let branch_data = match txn.get_crdt_branch(&branch_key)? { |
| 355 | Some(data) => data, |
| 356 | None => continue, // Branch not found, skip |
| 357 | }; |
| 358 | |
| 359 | // Skip deleted lines unless requested |
| 360 | if branch_data.state.is_deleted() && !options.include_deleted_lines { |
| 361 | continue; |
| 362 | } |
| 363 | |
| 364 | let mut line = Line::new( |
| 365 | branch_id, |
| 366 | line_number, |
| 367 | branch_data.state, |
| 368 | branch_data.line_hash, |
| 369 | ); |
| 370 | |
| 371 | // Get all leaves for this branch |
| 372 | let leaf_keys: Vec<[u8; 12]> = txn |
| 373 | .iter_branch_leaves(&branch_key)? |
| 374 | .collect::<Result<Vec<_>, _>>()?; |
| 375 | |
| 376 | for leaf_key in leaf_keys { |
| 377 | let leaf_id = decode_leaf_id(&leaf_key); |
| 378 | let leaf_data = match txn.get_crdt_leaf(&leaf_key)? { |
| 379 | Some(data) => data, |
| 380 | None => continue, // Leaf not found, skip |
| 381 | }; |
| 382 | |
| 383 | // Skip deleted tokens unless requested |
| 384 | if leaf_data.state.is_deleted() && !options.include_deleted_tokens { |
| 385 | continue; |
| 386 | } |
| 387 | |
| 388 | // Note: content would need to come from the change's content blob |
no test coverage detected