MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / get_file_lines_by_trunk

Function get_file_lines_by_trunk

atomic-core/src/output/crdt.rs:331–409  ·  view source on GitHub ↗

Retrieve all lines for a file by trunk ID.

(
    txn: &mut T,
    trunk_id: TrunkId,
    options: &RetrievalOptions,
)

Source from the content-addressed store, hash-verified

329
330/// Retrieve all lines for a file by trunk ID.
331pub 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

Callers 2

get_file_with_optionsFunction · 0.85

Calls 11

encode_branch_idFunction · 0.85
decode_leaf_idFunction · 0.85
lenMethod · 0.45
get_crdt_branchMethod · 0.45
is_deletedMethod · 0.45
iter_branch_leavesMethod · 0.45
get_crdt_leafMethod · 0.45
add_tokenMethod · 0.45
is_aliveMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected