Mark every content vertex for this file as deleted. Delete the specific line vertices identified by `built.deleted_lines`. Proper patch theory: only the targeted vertices are marked deleted. Unaffected lines stay alive as the original vertices. Falls back to whole-file deletion for legacy single-vertex files or when `deleted_lines` is empty (full-file Delete hunk).
(
ctx: &mut GlobalizeContext<'_, T>,
built: &BuiltHunk,
inode: Inode,
inode_pos: Position<NodeId>,
local: Local,
encoding: Option<Encoding>,
)
| 574 | /// Falls back to whole-file deletion for legacy single-vertex files or |
| 575 | /// when `deleted_lines` is empty (full-file Delete hunk). |
| 576 | fn globalize_delete<T>( |
| 577 | ctx: &mut GlobalizeContext<'_, T>, |
| 578 | built: &BuiltHunk, |
| 579 | inode: Inode, |
| 580 | inode_pos: Position<NodeId>, |
| 581 | local: Local, |
| 582 | encoding: Option<Encoding>, |
| 583 | ) -> GlobalizeResult<Vec<GraphOp<Option<Hash>>>> |
| 584 | where |
| 585 | T: GraphTxnT + TreeTxnT + InodeGraphOps, |
| 586 | { |
| 587 | // Whole-file lifecycle changes must always depend on the inode's creating |
| 588 | // change, including zero-byte files whose deletion has no content edges. |
| 589 | ctx.add_dependency_by_id(inode_pos.change)?; |
| 590 | |
| 591 | // An empty range denotes deletion of the file itself. Generated-file |
| 592 | // content optimizations must not turn that lifecycle operation into an |
| 593 | // Edit: it needs the same canonical FileDel as every other file. |
| 594 | if should_use_opaque_generated_vertices(&local.path) && !built.deleted_lines.is_empty() { |
| 595 | let content_vertices = find_content_vertices(ctx.txn(), inode, inode_pos)?; |
| 596 | let deletion_edges = build_deletion_edges(ctx, &content_vertices)?; |
| 597 | let deletion = EdgeUpdate { |
| 598 | edges: deletion_edges, |
| 599 | inode: position_to_option_hash_resolved(ctx.txn(), inode_pos, None), |
| 600 | }; |
| 601 | return Ok(vec![GraphOp::Edit { |
| 602 | change: Atom::EdgeUpdate(deletion), |
| 603 | local, |
| 604 | encoding, |
| 605 | }]); |
| 606 | } |
| 607 | |
| 608 | let sorted = collect_sorted_content_vertices_cached(ctx, inode, inode_pos)?; |
| 609 | |
| 610 | // Targeted deletion when we have per-line vertices and a specific |
| 611 | // deleted range. |
| 612 | if sorted.len() > 1 && !built.deleted_lines.is_empty() { |
| 613 | let first_deleted = *built.deleted_lines.first().unwrap(); |
| 614 | let last_deleted = *built.deleted_lines.last().unwrap(); |
| 615 | |
| 616 | if last_deleted < sorted.len() { |
| 617 | let to_delete: Vec<GraphNode<NodeId>> = |
| 618 | (first_deleted..=last_deleted).map(|i| sorted[i]).collect(); |
| 619 | let deletion_edges = build_deletion_edges(ctx, &to_delete)?; |
| 620 | |
| 621 | let deletion = EdgeUpdate { |
| 622 | edges: deletion_edges, |
| 623 | inode: position_to_option_hash_resolved(ctx.txn(), inode_pos, None), |
| 624 | }; |
| 625 | |
| 626 | return Ok(vec![GraphOp::Edit { |
| 627 | change: Atom::EdgeUpdate(deletion), |
| 628 | local, |
| 629 | encoding, |
| 630 | }]); |
| 631 | } |
| 632 | } |
| 633 |
no test coverage detected