Mercurial > hg-stable
changeset 46153:0a721fc457bf
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
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 02 Dec 2020 11:04:11 +0100 |
parents | e166e8a035a7 |
children | ecbb2fc9418c |
files | rust/hg-core/src/copy_tracing.rs |
diffstat | 1 files changed, 15 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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.