dirstate-entry: turn dirstate tuple into a real object (like in C)
With dirstate V2, the stored information and actual format will change. This mean we need to start an a better abstraction for a dirstate entry that a tuple directly accessed.
By chance, the C code is already doing this and pretend to be a tuple. So it
should be fairly easy. We start with turning the tuple into an object, we will
slowly migrate the dirstate code to no longer use the tuple directly in later
changesets.
Differential Revision: https://phab.mercurial-scm.org/D10949
--- a/mercurial/pure/parsers.py Fri Jul 02 02:27:48 2021 +0200
+++ b/mercurial/pure/parsers.py Sat Jul 03 03:48:35 2021 +0200
@@ -32,18 +32,37 @@
_compress = zlib.compress
_decompress = zlib.decompress
-# Some code below makes tuples directly because it's more convenient. However,
-# code outside this module should always use dirstatetuple.
-def dirstatetuple(*x):
- """the four items are:
+
+class dirstatetuple(object):
+ """represent a dirstate entry
+
+ It contains:
+
- state (one of 'n', 'a', 'r', 'm')
- mode,
- size,
- mtime,
"""
- # x is a tuple
- return x
+ __slot__ = ('_state', '_mode', '_size', '_mtime')
+
+ def __init__(self, state, mode, size, mtime):
+ self._state = state
+ self._mode = mode
+ self._size = size
+ self._mtime = mtime
+
+ def __getitem__(self, idx):
+ if idx == 0 or idx == -4:
+ return self._state
+ elif idx == 1 or idx == -3:
+ return self._mode
+ elif idx == 2 or idx == -2:
+ return self._size
+ elif idx == 3 or idx == -1:
+ return self._mtime
+ else:
+ raise IndexError(idx)
def gettype(q):