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>,
)
| 497 | /// Falls back to whole-file deletion for legacy single-vertex files or |
| 498 | /// when `deleted_lines` is empty (full-file Delete hunk). |
| 499 | fn globalize_delete<T>( |
| 500 | ctx: &mut GlobalizeContext<'_, T>, |
| 501 | built: &BuiltHunk, |
| 502 | inode: Inode, |
| 503 | inode_pos: Position<NodeId>, |
| 504 | local: Local, |
| 505 | encoding: Option<Encoding>, |
| 506 | ) -> GlobalizeResult<Vec<GraphOp<Option<Hash>>>> |
| 507 | where |
| 508 | T: GraphTxnT + TreeTxnT + InodeGraphOps, |
| 509 | { |
| 510 | if should_use_opaque_generated_vertices(&local.path) { |
| 511 | let content_vertices = find_content_vertices(ctx.txn(), inode, inode_pos)?; |
| 512 | let deletion_edges = build_deletion_edges(ctx, &content_vertices)?; |
| 513 | let deletion = EdgeUpdate { |
| 514 | edges: deletion_edges, |
| 515 | inode: position_to_option_hash_resolved(ctx.txn(), inode_pos, None), |
| 516 | }; |
| 517 | return Ok(vec![GraphOp::Edit { |
| 518 | change: Atom::EdgeUpdate(deletion), |
| 519 | local, |
| 520 | encoding, |
| 521 | }]); |
| 522 | } |
| 523 | |
| 524 | let sorted = collect_sorted_content_vertices_cached(ctx, inode, inode_pos)?; |
| 525 | |
| 526 | // Targeted deletion when we have per-line vertices and a specific |
| 527 | // deleted range. |
| 528 | if sorted.len() > 1 && !built.deleted_lines.is_empty() { |
| 529 | let first_deleted = *built.deleted_lines.first().unwrap(); |
| 530 | let last_deleted = *built.deleted_lines.last().unwrap(); |
| 531 | |
| 532 | if last_deleted < sorted.len() { |
| 533 | let to_delete: Vec<GraphNode<NodeId>> = |
| 534 | (first_deleted..=last_deleted).map(|i| sorted[i]).collect(); |
| 535 | let deletion_edges = build_deletion_edges(ctx, &to_delete)?; |
| 536 | |
| 537 | let deletion = EdgeUpdate { |
| 538 | edges: deletion_edges, |
| 539 | inode: position_to_option_hash_resolved(ctx.txn(), inode_pos, None), |
| 540 | }; |
| 541 | |
| 542 | return Ok(vec![GraphOp::Edit { |
| 543 | change: Atom::EdgeUpdate(deletion), |
| 544 | local, |
| 545 | encoding, |
| 546 | }]); |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | // Fallback: whole-file deletion. |
| 551 | let deletion = match delete_all_content(ctx, inode, inode_pos) { |
| 552 | Ok(d) => d, |
| 553 | Err(_) => { |
| 554 | let global_vertices = find_content_vertices_global(ctx.txn(), inode_pos)?; |
| 555 | let deletion_edges = build_deletion_edges(ctx, &global_vertices)?; |
| 556 | EdgeUpdate { |
no test coverage detected