comparison mercurial/pure/parsers.py @ 47665:a4443f66be6a

dirstate-item: add a `from_v1_data` constructor This class method is dedicated to building a DirstateItem from the data available in the "dirstate-v1" format. Since that format is frozen, this constructor will never change (unlike the `__init__` one). Differential Revision: https://phab.mercurial-scm.org/D11118
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 13 Jul 2021 13:06:50 +0200
parents 119b9c8db94d
children e53256a9f9c5
comparison
equal deleted inserted replaced
47664:119b9c8db94d 47665:a4443f66be6a
64 def __init__(self, state, mode, size, mtime): 64 def __init__(self, state, mode, size, mtime):
65 self._state = state 65 self._state = state
66 self._mode = mode 66 self._mode = mode
67 self._size = size 67 self._size = size
68 self._mtime = mtime 68 self._mtime = mtime
69
70 @classmethod
71 def from_v1_data(cls, state, mode, size, mtime):
72 """Build a new DirstateItem object from V1 data
73
74 Since the dirstate-v1 format is frozen, the signature of this function
75 is not expected to change, unlike the __init__ one.
76 """
77 return cls(
78 state=state,
79 mode=mode,
80 size=size,
81 mtime=mtime,
82 )
69 83
70 def __getitem__(self, idx): 84 def __getitem__(self, idx):
71 if idx == 0 or idx == -4: 85 if idx == 0 or idx == -4:
72 msg = b"do not use item[x], use item.state" 86 msg = b"do not use item[x], use item.state"
73 util.nouideprecwarn(msg, b'6.0', stacklevel=2) 87 util.nouideprecwarn(msg, b'6.0', stacklevel=2)
544 pos1 = pos2 + e[4] 558 pos1 = pos2 + e[4]
545 f = st[pos2:pos1] 559 f = st[pos2:pos1]
546 if b'\0' in f: 560 if b'\0' in f:
547 f, c = f.split(b'\0') 561 f, c = f.split(b'\0')
548 copymap[f] = c 562 copymap[f] = c
549 dmap[f] = DirstateItem(*e[:4]) 563 dmap[f] = DirstateItem.from_v1_data(*e[:4])
550 return parents 564 return parents
551 565
552 566
553 def pack_dirstate(dmap, copymap, pl, now): 567 def pack_dirstate(dmap, copymap, pl, now):
554 now = int(now) 568 now = int(now)