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] |