Patchwork D11523: dirstate-item: introduce a `maybe_clean` property

login
register
mail settings
Submitter phabricator
Date Oct. 1, 2021, 9:39 a.m.
Message ID <differential-rev-PHID-DREV-thcocrl4xxutyjy6c6xu-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49849/
State Superseded
Headers show

Comments

phabricator - Oct. 1, 2021, 9:39 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  It is useful for some extension that seek to invalidate some state.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/cext/parsers.c
  mercurial/pure/parsers.py
  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
@@ -85,6 +85,11 @@ 
         Ok(self.entry(py).get().from_p2())
     }
 
+    @property
+    def maybe_clean(&self) -> PyResult<bool> {
+        Ok(self.entry(py).get().maybe_clean())
+    }
+
     def v1_state(&self) -> PyResult<PyBytes> {
         let (state, _mode, _size, _mtime) = self.entry(py).get().v1_data();
         let state_byte: u8 = state.into();
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
@@ -191,6 +191,20 @@ 
         self.flags.contains(Flags::WDIR_TRACKED | Flags::CLEAN_P2)
     }
 
+    pub fn maybe_clean(&self) -> bool {
+        if !self.flags.contains(Flags::WDIR_TRACKED) {
+            false
+        } else if self.added() {
+            false
+        } else if self.flags.contains(Flags::MERGED) {
+            false
+        } else if self.flags.contains(Flags::CLEAN_P2) {
+            false
+        } else {
+            true
+        }
+    }
+
     pub fn state(&self) -> EntryState {
         if self.removed() {
             EntryState::Removed
diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -319,6 +319,19 @@ 
         return self._wc_tracked and not (self._p1_tracked or self._p2_tracked)
 
     @property
+    def maybe_clean(self):
+        """True if the file has a chance to be in the "clean" state"""
+        if not self._wc_tracked:
+            return False
+        elif self.added:
+            return False
+        elif self._merged:
+            return False
+        elif self._clean_p2:
+            return False
+        return True
+
+    @property
     def merged(self):
         """True if the file has been merged
 
diff --git a/mercurial/cext/parsers.c b/mercurial/cext/parsers.c
--- a/mercurial/cext/parsers.c
+++ b/mercurial/cext/parsers.c
@@ -620,6 +620,21 @@ 
 	}
 };
 
+static PyObject *dirstate_item_get_maybe_clean(dirstateItemObject *self)
+{
+	if (!(self->flags & dirstate_flag_wc_tracked)) {
+		Py_RETURN_FALSE;
+	} else if (dirstate_item_c_added(self)) {
+		Py_RETURN_FALSE;
+	} else if (self->flags & dirstate_flag_merged) {
+		Py_RETURN_FALSE;
+	} else if (self->flags & dirstate_flag_clean_p2) {
+		Py_RETURN_FALSE;
+	} else {
+		Py_RETURN_TRUE;
+	}
+};
+
 static PyObject *dirstate_item_get_removed(dirstateItemObject *self)
 {
 	if (dirstate_item_c_removed(self)) {
@@ -638,6 +653,8 @@ 
     {"added", (getter)dirstate_item_get_added, NULL, "added", NULL},
     {"merged", (getter)dirstate_item_get_merged, NULL, "merged", NULL},
     {"from_p2", (getter)dirstate_item_get_from_p2, NULL, "from_p2", NULL},
+    {"maybe_clean", (getter)dirstate_item_get_maybe_clean, NULL, "maybe_clean",
+     NULL},
     {"removed", (getter)dirstate_item_get_removed, NULL, "removed", NULL},
     {NULL} /* Sentinel */
 };