Patchwork D9647: copies-rust: use matching to select the final copies information

login
register
mail settings
Submitter phabricator
Date Dec. 21, 2020, 10:28 p.m.
Message ID <differential-rev-PHID-DREV-3h7o4tu6lc2skjvjw4pc-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47956/
State New
Headers show

Comments

phabricator - Dec. 21, 2020, 10:28 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is a bit more idiomatic and this prepare a future refactoring where
  InternalCopies from both parent would be updated at the same time.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -412,49 +412,37 @@ 
                 p2,
             ), // will be None if the vertex is not to be traversed
         };
-        if let Some(parent_copies) = p1_copies {
-            // combine it with data for that revision
-            let vertex_copies = add_from_changes(
+        // combine it with data for that revision
+        let p1_copies = match p1_copies {
+            None => None,
+            Some(parent_copies) => Some(add_from_changes(
                 &mut path_map,
                 &parent_copies,
                 &changes,
                 Parent::FirstParent,
                 rev,
-            );
-            // keep that data around for potential later combination
-            copies = Some(vertex_copies);
-        }
-        if let Some(parent_copies) = p2_copies {
-            // combine it with data for that revision
-            let vertex_copies = add_from_changes(
+            )),
+        };
+        let p2_copies = match p2_copies {
+            None => None,
+            Some(parent_copies) => Some(add_from_changes(
                 &mut path_map,
                 &parent_copies,
                 &changes,
                 Parent::SecondParent,
                 rev,
-            );
-
-            copies = match copies {
-                None => Some(vertex_copies),
-                // Merge has two parents needs to combines their copy
-                // information.
-                //
-                // If we got data from both parents, We need to combine
-                // them.
-                Some(copies) => Some(merge_copies_dict(
-                    &path_map,
-                    rev,
-                    vertex_copies,
-                    copies,
-                    &changes,
-                )),
-            };
-        }
-        match copies {
-            Some(copies) => {
-                all_copies.insert(rev, copies);
-            }
-            _ => {}
+            )),
+        };
+        let copies = match (p1_copies, p2_copies) {
+            (None, None) => None,
+            (c, None) => c,
+            (None, c) => c,
+            (Some(p1_copies), Some(p2_copies)) => Some(merge_copies_dict(
+                &path_map, rev, p2_copies, p1_copies, &changes,
+            )),
+        };
+        if let Some(c) = copies {
+            all_copies.insert(rev, c);
         }
     }