Patchwork D9649: copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`

login
register
mail settings
Submitter phabricator
Date Dec. 21, 2020, 10:28 p.m.
Message ID <differential-rev-PHID-DREV-asbq7gtgwkx5whmxucb3-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47959/
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
  Instead of filtering the relevant parent inside de ChangedFiles method, we now
  yield all copies information and let the caller do the filtering. Soon, the
  filtering will be replaced by dispatching.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -105,7 +105,8 @@ 
     Removed(&'a HgPath),
     /// The parent ? children edge introduce copy information between (dest,
     /// source)
-    Copied(&'a HgPath, &'a HgPath),
+    CopiedFromP1(&'a HgPath, &'a HgPath),
+    CopiedFromP2(&'a HgPath, &'a HgPath),
 }
 
 /// This express the possible "special" case we can get in a merge
@@ -244,10 +245,9 @@ 
     }
 
     /// Return an iterator over all the `Action` in this instance.
-    fn iter_actions(&self, parent: Parent) -> ActionsIterator {
+    fn iter_actions(&self) -> ActionsIterator {
         ActionsIterator {
             changes: &self,
-            parent: parent,
             current: 0,
         }
     }
@@ -281,7 +281,6 @@ 
 
 struct ActionsIterator<'a> {
     changes: &'a ChangedFiles<'a>,
-    parent: Parent,
     current: u32,
 }
 
@@ -289,10 +288,6 @@ 
     type Item = Action<'a>;
 
     fn next(&mut self) -> Option<Action<'a>> {
-        let copy_flag = match self.parent {
-            Parent::FirstParent => P1_COPY,
-            Parent::SecondParent => P2_COPY,
-        };
         while self.current < self.changes.nb_items {
             let (flags, file, source) = self.changes.entry(self.current);
             self.current += 1;
@@ -300,8 +295,10 @@ 
                 return Some(Action::Removed(file));
             }
             let copy = flags & COPY_MASK;
-            if copy == copy_flag {
-                return Some(Action::Copied(file, source));
+            if copy == P1_COPY {
+                return Some(Action::CopiedFromP1(file, source));
+            } else if copy == P2_COPY {
+                return Some(Action::CopiedFromP2(file, source));
             }
         }
         return None;
@@ -498,18 +495,34 @@ 
     current_rev: Revision,
 ) -> InternalPathCopies {
     let mut copies = base_copies.clone();
-    for action in changes.iter_actions(parent) {
+    for action in changes.iter_actions() {
         match action {
-            Action::Copied(path_dest, path_source) => {
-                add_one_copy(
-                    current_rev,
-                    &mut path_map,
-                    &mut copies,
-                    &base_copies,
-                    path_dest,
-                    path_source,
-                );
-            }
+            Action::CopiedFromP1(path_dest, path_source) => {
+                match parent {
+                    _ => (), // not the parent we are looking for
+                    Parent::FirstParent => add_one_copy(
+                        current_rev,
+                        path_map,
+                        &mut copies,
+                        &base_copies,
+                        path_dest,
+                        path_source,
+                    ),
+                };
+            },
+            Action::CopiedFromP2(path_dest, path_source) => {
+                match parent {
+                    _ => (), //not the parent we are looking for
+                    Parent::SecondParent => add_one_copy(
+                        current_rev,
+                        path_map,
+                        &mut copies,
+                        &base_copies,
+                        path_dest,
+                        path_source,
+                    ),
+                };
+            },
             Action::Removed(deleted_path) => {
                 // We must drop copy information for removed file.
                 //