Patchwork D9495: copies-rust: use the `entry` API for copy information too

login
register
mail settings
Submitter phabricator
Date Dec. 2, 2020, 4:02 p.m.
Message ID <differential-rev-PHID-DREV-gxwv6zcfkb3ui6nphrpf-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47777/
State Superseded
Headers show

Comments

phabricator - Dec. 2, 2020, 4:02 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9495

AFFECTED FILES
  rust/hg-core/src/copy_tracing.rs

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

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
@@ -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;
@@ -501,11 +502,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.