# HG changeset patch # User Pierre-Yves David # Date 2020-12-16 09:59:00 # Node ID 2076df13d00f809e6c4eeaf7636ca3813b708fdf # Parent 600f8d510ab617dfe00586a751ddb2e23ffcd774 copies-rust: refactor the "deletion" case We rearrange the code to single out the case where information need to be overwritten on both side of the merge. This open the way to better dealing with this case. Differential Revision: https://phab.mercurial-scm.org/D9651 diff --git a/rust/hg-core/src/copy_tracing.rs b/rust/hg-core/src/copy_tracing.rs --- a/rust/hg-core/src/copy_tracing.rs +++ b/rust/hg-core/src/copy_tracing.rs @@ -510,22 +510,35 @@ fn chain_changes( // propagate this information when merging two // InternalPathCopies object. let deleted = path_map.tokenize(deleted_path); - match &mut p1_copies { - None => (), - Some(copies) => { - copies.entry(deleted).and_modify(|old| { - old.mark_delete(current_rev); - }); - } + + let p1_entry = match &mut p1_copies { + None => None, + Some(copies) => match copies.entry(deleted) { + Entry::Occupied(e) => Some(e), + Entry::Vacant(_) => None, + }, + }; + let p2_entry = match &mut p2_copies { + None => None, + Some(copies) => match copies.entry(deleted) { + Entry::Occupied(e) => Some(e), + Entry::Vacant(_) => None, + }, }; - match &mut p2_copies { - None => (), - Some(copies) => { - copies.entry(deleted).and_modify(|old| { - old.mark_delete(current_rev); - }); + + match (p1_entry, p2_entry) { + (None, None) => (), + (Some(mut e), None) => { + e.get_mut().mark_delete(current_rev) } - }; + (None, Some(mut e)) => { + e.get_mut().mark_delete(current_rev) + } + (Some(mut e1), Some(mut e2)) => { + e1.get_mut().mark_delete(current_rev); + e2.get_mut().mark_delete(current_rev); + } + } } } }