Patchwork D11579: dirstate-item: implement `drop_merge_data` on the Rust DirstateItem

login
register
mail settings
Submitter phabricator
Date Oct. 2, 2021, 3:06 p.m.
Message ID <differential-rev-PHID-DREV-use64x6y5y5hqrct5ho2-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49903/
State Superseded
Headers show

Comments

phabricator - Oct. 2, 2021, 3:06 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  It was currently missing and we want to be able to use in it the Rust case too.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/hg-core/src/dirstate/entry.rs
  rust/hg-cpython/src/dirstate/item.rs

CHANGE DETAILS




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

Patch

diff --git a/rust/hg-cpython/src/dirstate/item.rs b/rust/hg-cpython/src/dirstate/item.rs
--- a/rust/hg-cpython/src/dirstate/item.rs
+++ b/rust/hg-cpython/src/dirstate/item.rs
@@ -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,
diff --git a/rust/hg-core/src/dirstate/entry.rs b/rust/hg-core/src/dirstate/entry.rs
--- a/rust/hg-core/src/dirstate/entry.rs
+++ b/rust/hg-core/src/dirstate/entry.rs
@@ -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)
     }