comparison mercurial/pure/parsers.py @ 47507:d4c795576aeb

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
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 03 Jul 2021 03:48:35 +0200
parents 084ed6a7c6fd
children 67d11b0f659f
comparison
equal deleted inserted replaced
47501:8b7e47802deb 47507:d4c795576aeb
30 _pack = struct.pack 30 _pack = struct.pack
31 _unpack = struct.unpack 31 _unpack = struct.unpack
32 _compress = zlib.compress 32 _compress = zlib.compress
33 _decompress = zlib.decompress 33 _decompress = zlib.decompress
34 34
35 # Some code below makes tuples directly because it's more convenient. However, 35
36 # code outside this module should always use dirstatetuple. 36 class dirstatetuple(object):
37 def dirstatetuple(*x): 37 """represent a dirstate entry
38 """the four items are: 38
39 It contains:
40
39 - state (one of 'n', 'a', 'r', 'm') 41 - state (one of 'n', 'a', 'r', 'm')
40 - mode, 42 - mode,
41 - size, 43 - size,
42 - mtime, 44 - mtime,
43 """ 45 """
44 46
45 # x is a tuple 47 __slot__ = ('_state', '_mode', '_size', '_mtime')
46 return x 48
49 def __init__(self, state, mode, size, mtime):
50 self._state = state
51 self._mode = mode
52 self._size = size
53 self._mtime = mtime
54
55 def __getitem__(self, idx):
56 if idx == 0 or idx == -4:
57 return self._state
58 elif idx == 1 or idx == -3:
59 return self._mode
60 elif idx == 2 or idx == -2:
61 return self._size
62 elif idx == 3 or idx == -1:
63 return self._mtime
64 else:
65 raise IndexError(idx)
47 66
48 67
49 def gettype(q): 68 def gettype(q):
50 return int(q & 0xFFFF) 69 return int(q & 0xFFFF)
51 70