marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/pure/parsers.py

CHANGE DETAILS

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 @@
 _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):
+    """represente a dirstate entry
+
+    It constains:
+
     - 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):



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to