changeset 48134:3c7db97ce541

dirstate-item: implement `drop_merge_data` on the Rust DirstateItem It was currently missing and we want to be able to use in it the Rust case too. Differential Revision: https://phab.mercurial-scm.org/D11579
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 02 Oct 2021 00:14:32 +0200
parents 55293938b843
children bd5f7c61d69d
files rust/hg-core/src/dirstate/entry.rs rust/hg-cpython/src/dirstate/item.rs
diffstat 2 files changed, 32 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate/entry.rs	Sat Oct 02 00:02:55 2021 +0200
+++ b/rust/hg-core/src/dirstate/entry.rs	Sat Oct 02 00:14:32 2021 +0200
@@ -263,6 +263,33 @@
         }
     }
 
+    pub fn drop_merge_data(&mut self) {
+        if self.flags.contains(Flags::CLEAN_P1)
+            || self.flags.contains(Flags::CLEAN_P2)
+            || self.flags.contains(Flags::MERGED)
+            || self.flags.contains(Flags::P2_TRACKED)
+        {
+            if self.flags.contains(Flags::MERGED) {
+                self.flags.insert(Flags::P1_TRACKED);
+            } else {
+                self.flags.remove(Flags::P1_TRACKED);
+            }
+            self.flags.remove(
+                Flags::MERGED
+                    | Flags::CLEAN_P1
+                    | Flags::CLEAN_P2
+                    | Flags::P2_TRACKED,
+            );
+            self.flags.insert(Flags::POSSIBLY_DIRTY);
+            self.mode = 0;
+            self.mtime = 0;
+            // size = None on the python size turn into size = NON_NORMAL when
+            // accessed. So the next line is currently required, but a some
+            // future clean up would be welcome.
+            self.size = SIZE_NON_NORMAL;
+        }
+    }
+
     pub fn set_possibly_dirty(&mut self) {
         self.flags.insert(Flags::POSSIBLY_DIRTY)
     }
--- a/rust/hg-cpython/src/dirstate/item.rs	Sat Oct 02 00:02:55 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/item.rs	Sat Oct 02 00:14:32 2021 +0200
@@ -166,6 +166,11 @@
         DirstateItem::create_instance(py, Cell::new(entry))
     }
 
+    def drop_merge_data(&self) -> PyResult<PyNone> {
+        self.update(py, |entry| entry.drop_merge_data());
+        Ok(PyNone)
+    }
+
     def set_clean(
         &self,
         mode: i32,