comparison mercurial/dirstateutils/docket.py @ 48165:d467e44f71d7

dirstate-v2: Move data file info in the docket closer together Having `data_size` next to `uuid_size` (and the UUID itself) makes more sense. Differential Revision: https://phab.mercurial-scm.org/D11545
author Simon Sapin <simon.sapin@octobus.net>
date Fri, 01 Oct 2021 12:27:17 +0200
parents 681851d6409b
children a32a96079e2d
comparison
equal deleted inserted replaced
48164:1ab4523afe12 48165:d467e44f71d7
19 TREE_METADATA_SIZE = 44 19 TREE_METADATA_SIZE = 44
20 20
21 # * 12 bytes: format marker 21 # * 12 bytes: format marker
22 # * 32 bytes: node ID of the working directory's first parent 22 # * 32 bytes: node ID of the working directory's first parent
23 # * 32 bytes: node ID of the working directory's second parent 23 # * 32 bytes: node ID of the working directory's second parent
24 # * {TREE_METADATA_SIZE} bytes: tree metadata, parsed separately
24 # * 4 bytes: big-endian used size of the data file 25 # * 4 bytes: big-endian used size of the data file
25 # * {TREE_METADATA_SIZE} bytes: tree metadata, parsed separately
26 # * 1 byte: length of the data file's UUID 26 # * 1 byte: length of the data file's UUID
27 # * variable: data file's UUID 27 # * variable: data file's UUID
28 # 28 #
29 # Node IDs are null-padded if shorter than 32 bytes. 29 # Node IDs are null-padded if shorter than 32 bytes.
30 # A data file shorter than the specified used size is corrupted (truncated) 30 # A data file shorter than the specified used size is corrupted (truncated)
31 HEADER = struct.Struct( 31 HEADER = struct.Struct(
32 ">{}s32s32sL{}sB".format(len(V2_FORMAT_MARKER), TREE_METADATA_SIZE) 32 ">{}s32s32s{}sLB".format(len(V2_FORMAT_MARKER), TREE_METADATA_SIZE)
33 ) 33 )
34 34
35 35
36 class DirstateDocket(object): 36 class DirstateDocket(object):
37 data_filename_pattern = b'dirstate.%s' 37 data_filename_pattern = b'dirstate.%s'
49 @classmethod 49 @classmethod
50 def parse(cls, data, nodeconstants): 50 def parse(cls, data, nodeconstants):
51 if not data: 51 if not data:
52 parents = (nodeconstants.nullid, nodeconstants.nullid) 52 parents = (nodeconstants.nullid, nodeconstants.nullid)
53 return cls(parents, 0, b'', None) 53 return cls(parents, 0, b'', None)
54 marker, p1, p2, data_size, meta, uuid_size = HEADER.unpack_from(data) 54 marker, p1, p2, meta, data_size, uuid_size = HEADER.unpack_from(data)
55 if marker != V2_FORMAT_MARKER: 55 if marker != V2_FORMAT_MARKER:
56 raise ValueError("expected dirstate-v2 marker") 56 raise ValueError("expected dirstate-v2 marker")
57 uuid = data[HEADER.size : HEADER.size + uuid_size] 57 uuid = data[HEADER.size : HEADER.size + uuid_size]
58 p1 = p1[: nodeconstants.nodelen] 58 p1 = p1[: nodeconstants.nodelen]
59 p2 = p2[: nodeconstants.nodelen] 59 p2 = p2[: nodeconstants.nodelen]
63 p1, p2 = self.parents 63 p1, p2 = self.parents
64 header = HEADER.pack( 64 header = HEADER.pack(
65 V2_FORMAT_MARKER, 65 V2_FORMAT_MARKER,
66 p1, 66 p1,
67 p2, 67 p2,
68 self.tree_metadata,
68 self.data_size, 69 self.data_size,
69 self.tree_metadata,
70 len(self.uuid), 70 len(self.uuid),
71 ) 71 )
72 return header + self.uuid 72 return header + self.uuid
73 73
74 def data_filename(self): 74 def data_filename(self):