# HG changeset patch # User Pierre-Yves David # Date 1606903451 -3600 # Node ID 0a721fc457bfb63790d5d1eeccf0c8d8cae8f94e # Parent e166e8a035a782be80c0f2b164ccae2ea69a0c93 copies-rust: use the `entry` API for copy information too The code end up being complicated, but it split out the case were we add a new entry from the case were we overwrite one. And that is the goal here, being able to easily track value overwrite. Differential Revision: https://phab.mercurial-scm.org/D9495 diff -r e166e8a035a7 -r 0a721fc457bf rust/hg-core/src/copy_tracing.rs --- a/rust/hg-core/src/copy_tracing.rs Wed Dec 02 10:51:40 2020 +0100 +++ b/rust/hg-core/src/copy_tracing.rs Wed Dec 02 11:04:11 2020 +0100 @@ -4,6 +4,7 @@ use crate::NULL_REVISION; use im_rc::ordmap::DiffItem; +use im_rc::ordmap::Entry; use im_rc::ordmap::OrdMap; use std::cmp::Ordering; @@ -510,11 +511,20 @@ // record this information as we will need it to take // the right decision when merging conflicting copy // information. See merge_copies_dict for details. - let ttpc = TimeStampedPathCopy { - rev: current_rev, - path: entry, - }; - copies.insert(dest.to_owned(), ttpc); + match copies.entry(dest) { + Entry::Vacant(slot) => { + let ttpc = TimeStampedPathCopy { + rev: current_rev, + path: entry, + }; + slot.insert(ttpc); + } + Entry::Occupied(mut slot) => { + let mut ttpc = slot.get_mut(); + ttpc.rev = current_rev; + ttpc.path = entry; + } + } } Action::Removed(deleted_path) => { // We must drop copy information for removed file.