# HG changeset patch # User Pierre-Yves David # Date 2021-07-03 01:48:35 # Node ID d4c795576aeb3040563a1acabec20320a04a6f64 # Parent 8b7e47802deb082aee3040f72ffd2e91b19b3910 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 diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py --- a/mercurial/pure/parsers.py +++ b/mercurial/pure/parsers.py @@ -32,18 +32,37 @@ stringio = pycompat.bytesio _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):