dirstate-entry: add `modified` property
This was already done in the Rust implementation and is a useful primitive.
The C implementation had this called `merged`, but wasn't used anywhere.
It will be used in the next changeset.
--- a/mercurial/cext/parsers.c Mon Dec 19 16:22:01 2022 +0100
+++ b/mercurial/cext/parsers.c Mon May 02 11:40:33 2022 +0200
@@ -177,7 +177,7 @@
(dirstate_flag_p1_tracked | dirstate_flag_p2_info));
}
-static inline bool dirstate_item_c_merged(dirstateItemObject *self)
+static inline bool dirstate_item_c_modified(dirstateItemObject *self)
{
return ((self->flags & dirstate_flag_wc_tracked) &&
(self->flags & dirstate_flag_p1_tracked) &&
@@ -195,7 +195,7 @@
{
if (dirstate_item_c_removed(self)) {
return 'r';
- } else if (dirstate_item_c_merged(self)) {
+ } else if (dirstate_item_c_modified(self)) {
return 'm';
} else if (dirstate_item_c_added(self)) {
return 'a';
@@ -642,9 +642,9 @@
}
};
-static PyObject *dirstate_item_get_merged(dirstateItemObject *self)
+static PyObject *dirstate_item_get_modified(dirstateItemObject *self)
{
- if (dirstate_item_c_merged(self)) {
+ if (dirstate_item_c_modified(self)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
@@ -709,7 +709,7 @@
NULL},
{"added", (getter)dirstate_item_get_added, NULL, "added", NULL},
{"p2_info", (getter)dirstate_item_get_p2_info, NULL, "p2_info", NULL},
- {"merged", (getter)dirstate_item_get_merged, NULL, "merged", NULL},
+ {"modified", (getter)dirstate_item_get_modified, NULL, "modified", 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},
@@ -1187,7 +1187,7 @@
void manifest_module_init(PyObject *mod);
void revlog_module_init(PyObject *mod);
-static const int version = 20;
+static const int version = 21;
static void module_init(PyObject *mod)
{
--- a/mercurial/policy.py Mon Dec 19 16:22:01 2022 +0100
+++ b/mercurial/policy.py Mon May 02 11:40:33 2022 +0200
@@ -76,7 +76,7 @@
('cext', 'bdiff'): 3,
('cext', 'mpatch'): 1,
('cext', 'osutil'): 4,
- ('cext', 'parsers'): 20,
+ ('cext', 'parsers'): 21,
}
# map import request to other package or module
--- a/mercurial/pure/parsers.py Mon Dec 19 16:22:01 2022 +0100
+++ b/mercurial/pure/parsers.py Mon May 02 11:40:33 2022 +0200
@@ -435,6 +435,11 @@
return self._wc_tracked and not (self._p1_tracked or self._p2_info)
@property
+ def modified(self):
+ """True if the file has been modified"""
+ return self._wc_tracked and self._p1_tracked and self._p2_info
+
+ @property
def maybe_clean(self):
"""True if the file has a chance to be in the "clean" state"""
if not self._wc_tracked:
--- a/rust/hg-cpython/src/dirstate/item.rs Mon Dec 19 16:22:01 2022 +0100
+++ b/rust/hg-cpython/src/dirstate/item.rs Mon May 02 11:40:33 2022 +0200
@@ -151,6 +151,10 @@
Ok(self.entry(py).get().added())
}
+ @property
+ def modified(&self) -> PyResult<bool> {
+ Ok(self.entry(py).get().modified())
+ }
@property
def p2_info(&self) -> PyResult<bool> {