dirstate: add a context for tracking files change
Let us start to use it. We will enforce it later.
--- a/mercurial/dirstate.py Mon Feb 13 21:51:45 2023 +0100
+++ b/mercurial/dirstate.py Thu Jan 26 17:44:27 2023 +0100
@@ -92,6 +92,7 @@
CHANGE_TYPE_PARENTS = "parents"
+CHANGE_TYPE_FILES = "files"
@interfaceutil.implementer(intdirstate.idirstate)
@@ -215,6 +216,11 @@
with self._changing(repo, CHANGE_TYPE_PARENTS) as c:
yield c
+ @contextlib.contextmanager
+ def changing_files(self, repo):
+ with self._changing(repo, CHANGE_TYPE_FILES) as c:
+ yield c
+
# here to help migration to the new code
def parentchange(self):
msg = (
@@ -250,6 +256,15 @@
return False
return self._change_type == CHANGE_TYPE_PARENTS
+ @property
+ def is_changing_files(self):
+ """Returns true if the dirstate is in the middle of a set of changes
+ that modify the files tracked or their sources.
+ """
+ if self._changing_level <= 0:
+ return False
+ return self._change_type == CHANGE_TYPE_FILES
+
@propertycache
def _map(self):
"""Return the dirstate contents (see documentation for dirstatemap)."""
--- a/mercurial/interfaces/dirstate.py Mon Feb 13 21:51:45 2023 +0100
+++ b/mercurial/interfaces/dirstate.py Thu Jan 26 17:44:27 2023 +0100
@@ -30,6 +30,9 @@
is_changing_parents = interfaceutil.Attribute(
"""True if parents changes in progress."""
)
+ is_changing_files = interfaceutil.Attribute(
+ """True if file tracking changes in progress."""
+ )
def _ignorefiles():
"""Return a list of files containing patterns to ignore."""
@@ -49,6 +52,15 @@
released.
"""
+ @contextlib.contextmanager
+ def changing_files(repo):
+ """Context manager for handling dirstate files.
+
+ If an exception occurs in the scope of the context manager,
+ the incoherent dirstate won't be written when wlock is
+ released.
+ """
+
def hasdir(d):
pass