author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Fri, 28 May 2021 23:41:17 +0200 | |
changeset 47389 | e6292eb33384 |
parent 47388 | bcf92bdc2bca |
child 47423 | be903d043099 |
permissions | -rw-r--r-- |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 |
# docket - code related to revlog "docket" |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 |
# |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
3 |
# Copyright 2021 Pierre-Yves David <pierre-yves.david@octobus.net> |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 |
# |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 |
# GNU General Public License version 2 or any later version. |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
7 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 |
### Revlog docket file |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
9 |
# |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 |
# The revlog is stored on disk using multiple files: |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 |
# |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 |
# * a small docket file, containing metadata and a pointer, |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 |
# |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 |
# * an index file, containing fixed width information about revisions, |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 |
# |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 |
# * a data file, containing variable width data for these revisions, |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 |
from __future__ import absolute_import |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 |
|
47312
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
20 |
import errno |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
21 |
import os |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
22 |
import random |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 |
import struct |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
24 |
|
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
25 |
from .. import ( |
47312
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
26 |
encoding, |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
27 |
error, |
47312
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
28 |
node, |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
29 |
pycompat, |
47255
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
30 |
util, |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
31 |
) |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
32 |
|
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
33 |
from . import ( |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
34 |
constants, |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
35 |
) |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
36 |
|
47312
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
37 |
|
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
38 |
def make_uid(id_size=8): |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
39 |
"""return a new unique identifier. |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
40 |
|
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
41 |
The identifier is random and composed of ascii characters.""" |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
42 |
# size we "hex" the result we need half the number of bits to have a final |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
43 |
# uuid of size ID_SIZE |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
44 |
return node.hex(os.urandom(id_size // 2)) |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
45 |
|
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
46 |
|
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
47 |
# some special test logic to avoid anoying random output in the test |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
48 |
stable_docket_file = encoding.environ.get(b'HGTEST_UUIDFILE') |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
49 |
|
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
50 |
if stable_docket_file: |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
51 |
|
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
52 |
def make_uid(id_size=8): |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
53 |
try: |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
54 |
with open(stable_docket_file, mode='rb') as f: |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
55 |
seed = f.read().strip() |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
56 |
except IOError as inst: |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
57 |
if inst.errno != errno.ENOENT: |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
58 |
raise |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
59 |
seed = b'04' # chosen by a fair dice roll. garanteed to be random |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
60 |
if pycompat.ispy3: |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
61 |
iter_seed = iter(seed) |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
62 |
else: |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
63 |
iter_seed = (ord(c) for c in seed) |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
64 |
# some basic circular sum hashing on 64 bits |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
65 |
int_seed = 0 |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
66 |
low_mask = int('1' * 35, 2) |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
67 |
for i in iter_seed: |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
68 |
high_part = int_seed >> 35 |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
69 |
low_part = (int_seed & low_mask) << 28 |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
70 |
int_seed = high_part + low_part + i |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
71 |
r = random.Random() |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
72 |
if pycompat.ispy3: |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
73 |
r.seed(int_seed, version=1) |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
74 |
else: |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
75 |
r.seed(int_seed) |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
76 |
# once we drop python 3.8 support we can simply use r.randbytes |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
77 |
raw = r.getrandbits(id_size * 4) |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
78 |
assert id_size == 8 |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
79 |
p = struct.pack('>L', raw) |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
80 |
new = node.hex(p) |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
81 |
with open(stable_docket_file, 'wb') as f: |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
82 |
f.write(new) |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
83 |
return new |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
84 |
|
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
85 |
|
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
86 |
# Docket format |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
87 |
# |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
88 |
# * 4 bytes: revlog version |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
89 |
# | This is mandatory as docket must be compatible with the previous |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
90 |
# | revlog index header. |
47323
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
91 |
# * 1 bytes: size of index uuid |
47324
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
92 |
# * 1 bytes: size of data uuid |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
93 |
# * 1 bytes: size of sizedata uuid |
47242
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
94 |
# * 8 bytes: size of index-data |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
95 |
# * 8 bytes: pending size of index-data |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
96 |
# * 8 bytes: size of data |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
97 |
# * 8 bytes: size of sidedata |
47242
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
98 |
# * 8 bytes: pending size of data |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
99 |
# * 8 bytes: pending size of sidedata |
47255
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
100 |
# * 1 bytes: default compression header |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
101 |
S_HEADER = struct.Struct(constants.INDEX_HEADER_FMT + b'BBBLLLLLLc') |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
102 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
103 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
104 |
class RevlogDocket(object): |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
105 |
"""metadata associated with revlog""" |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
106 |
|
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
107 |
def __init__( |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
108 |
self, |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
109 |
revlog, |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
110 |
use_pending=False, |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
111 |
version_header=None, |
47323
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
112 |
index_uuid=None, |
47324
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
113 |
data_uuid=None, |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
114 |
sidedata_uuid=None, |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
115 |
index_end=0, |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
116 |
pending_index_end=0, |
47242
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
117 |
data_end=0, |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
118 |
pending_data_end=0, |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
119 |
sidedata_end=0, |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
120 |
pending_sidedata_end=0, |
47255
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
121 |
default_compression_header=None, |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
122 |
): |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
123 |
self._version_header = version_header |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
124 |
self._read_only = bool(use_pending) |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
125 |
self._dirty = False |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
126 |
self._radix = revlog.radix |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
127 |
self._path = revlog._docket_file |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
128 |
self._opener = revlog.opener |
47323
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
129 |
self._index_uuid = index_uuid |
47324
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
130 |
self._data_uuid = data_uuid |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
131 |
self._sidedata_uuid = sidedata_uuid |
47242
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
132 |
# thes asserts should be True as long as we have a single index filename |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
133 |
assert index_end <= pending_index_end |
47242
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
134 |
assert data_end <= pending_data_end |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
135 |
assert sidedata_end <= pending_sidedata_end |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
136 |
self._initial_index_end = index_end |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
137 |
self._pending_index_end = pending_index_end |
47242
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
138 |
self._initial_data_end = data_end |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
139 |
self._pending_data_end = pending_data_end |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
140 |
self._initial_sidedata_end = sidedata_end |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
141 |
self._pending_sidedata_end = pending_sidedata_end |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
142 |
if use_pending: |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
143 |
self._index_end = self._pending_index_end |
47242
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
144 |
self._data_end = self._pending_data_end |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
145 |
self._sidedata_end = self._pending_sidedata_end |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
146 |
else: |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
147 |
self._index_end = self._initial_index_end |
47242
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
148 |
self._data_end = self._initial_data_end |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
149 |
self._sidedata_end = self._initial_sidedata_end |
47255
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
150 |
self.default_compression_header = default_compression_header |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
151 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
152 |
def index_filepath(self): |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
153 |
"""file path to the current index file associated to this docket""" |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
154 |
# very simplistic version at first |
47323
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
155 |
if self._index_uuid is None: |
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
156 |
self._index_uuid = make_uid() |
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
157 |
return b"%s-%s.idx" % (self._radix, self._index_uuid) |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
158 |
|
47324
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
159 |
def data_filepath(self): |
47388
bcf92bdc2bca
revlog: fix docket.date_filepath docstring
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47371
diff
changeset
|
160 |
"""file path to the current data file associated to this docket""" |
47324
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
161 |
# very simplistic version at first |
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
162 |
if self._data_uuid is None: |
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
163 |
self._data_uuid = make_uid() |
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
164 |
return b"%s-%s.dat" % (self._radix, self._data_uuid) |
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
165 |
|
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
166 |
def sidedata_filepath(self): |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
167 |
"""file path to the current sidedata file associated to this docket""" |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
168 |
# very simplistic version at first |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
169 |
if self._sidedata_uuid is None: |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
170 |
self._sidedata_uuid = make_uid() |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
171 |
return b"%s-%s.sda" % (self._radix, self._sidedata_uuid) |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
172 |
|
47238
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
173 |
@property |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
174 |
def index_end(self): |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
175 |
return self._index_end |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
176 |
|
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
177 |
@index_end.setter |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
178 |
def index_end(self, new_size): |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
179 |
if new_size != self._index_end: |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
180 |
self._index_end = new_size |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
181 |
self._dirty = True |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
182 |
|
47242
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
183 |
@property |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
184 |
def data_end(self): |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
185 |
return self._data_end |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
186 |
|
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
187 |
@data_end.setter |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
188 |
def data_end(self, new_size): |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
189 |
if new_size != self._data_end: |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
190 |
self._data_end = new_size |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
191 |
self._dirty = True |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
192 |
|
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
193 |
@property |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
194 |
def sidedata_end(self): |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
195 |
return self._sidedata_end |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
196 |
|
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
197 |
@sidedata_end.setter |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
198 |
def sidedata_end(self, new_size): |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
199 |
if new_size != self._sidedata_end: |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
200 |
self._sidedata_end = new_size |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
201 |
self._dirty = True |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
202 |
|
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
203 |
def write(self, transaction, pending=False, stripping=False): |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
204 |
"""write the modification of disk if any |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
205 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
206 |
This make the new content visible to all process""" |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
207 |
if not self._dirty: |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
208 |
return False |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
209 |
else: |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
210 |
if self._read_only: |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
211 |
msg = b'writing read-only docket: %s' |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
212 |
msg %= self._path |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
213 |
raise error.ProgrammingError(msg) |
47238
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
214 |
if not stripping: |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
215 |
# XXX we could, leverage the docket while stripping. However it |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
216 |
# is not powerfull enough at the time of this comment |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
217 |
transaction.addbackup(self._path, location=b'store') |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
218 |
with self._opener(self._path, mode=b'w', atomictemp=True) as f: |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
219 |
f.write(self._serialize(pending=pending)) |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
220 |
# if pending we still need to the write final data eventually |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
221 |
self._dirty = pending |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
222 |
return True |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
223 |
|
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
224 |
def _serialize(self, pending=False): |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
225 |
if pending: |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
226 |
official_index_end = self._initial_index_end |
47242
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
227 |
official_data_end = self._initial_data_end |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
228 |
official_sidedata_end = self._initial_sidedata_end |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
229 |
else: |
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
230 |
official_index_end = self._index_end |
47242
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
231 |
official_data_end = self._data_end |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
232 |
official_sidedata_end = self._sidedata_end |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
233 |
|
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
234 |
# this assert should be True as long as we have a single index filename |
47242
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
235 |
assert official_data_end <= self._data_end |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
236 |
assert official_sidedata_end <= self._sidedata_end |
47238
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
237 |
data = ( |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
238 |
self._version_header, |
47323
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
239 |
len(self._index_uuid), |
47324
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
240 |
len(self._data_uuid), |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
241 |
len(self._sidedata_uuid), |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
242 |
official_index_end, |
47238
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
243 |
self._index_end, |
47242
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
244 |
official_data_end, |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
245 |
self._data_end, |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
246 |
official_sidedata_end, |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
247 |
self._sidedata_end, |
47255
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
248 |
self.default_compression_header, |
47238
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
249 |
) |
47323
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
250 |
s = [] |
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
251 |
s.append(S_HEADER.pack(*data)) |
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
252 |
s.append(self._index_uuid) |
47324
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
253 |
s.append(self._data_uuid) |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
254 |
s.append(self._sidedata_uuid) |
47323
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
255 |
return b''.join(s) |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
256 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
257 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
258 |
def default_docket(revlog, version_header): |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
259 |
"""given a revlog version a new docket object for the given revlog""" |
47266
921648d31553
changelogv2: use a dedicated version number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47255
diff
changeset
|
260 |
rl_version = version_header & 0xFFFF |
921648d31553
changelogv2: use a dedicated version number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47255
diff
changeset
|
261 |
if rl_version not in (constants.REVLOGV2, constants.CHANGELOGV2): |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
262 |
return None |
47255
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
263 |
comp = util.compengines[revlog._compengine].revlogheader() |
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
264 |
docket = RevlogDocket( |
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
265 |
revlog, |
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
266 |
version_header=version_header, |
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
267 |
default_compression_header=comp, |
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
268 |
) |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
269 |
docket._dirty = True |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
270 |
return docket |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
271 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
272 |
|
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
273 |
def parse_docket(revlog, data, use_pending=False): |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
274 |
"""given some docket data return a docket object for the given revlog""" |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
275 |
header = S_HEADER.unpack(data[: S_HEADER.size]) |
47326
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
276 |
|
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
277 |
# this is a mutable closure capture used in `get_data` |
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
278 |
offset = [S_HEADER.size] |
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
279 |
|
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
280 |
def get_data(size): |
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
281 |
"""utility closure to access the `size` next bytes""" |
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
282 |
if offset[0] + size > len(data): |
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
283 |
# XXX better class |
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
284 |
msg = b"docket is too short, expected %d got %d" |
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
285 |
msg %= (offset[0] + size, len(data)) |
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
286 |
raise error.Abort(msg) |
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
287 |
raw = data[offset[0] : offset[0] + size] |
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
288 |
offset[0] += size |
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
289 |
return raw |
47325
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
290 |
|
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
291 |
iheader = iter(header) |
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
292 |
|
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
293 |
version_header = next(iheader) |
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
294 |
|
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
295 |
index_uuid_size = next(iheader) |
47326
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
296 |
index_uuid = get_data(index_uuid_size) |
47325
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
297 |
|
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
298 |
data_uuid_size = next(iheader) |
47326
53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47325
diff
changeset
|
299 |
data_uuid = get_data(data_uuid_size) |
47325
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
300 |
|
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
301 |
sidedata_uuid_size = next(iheader) |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
302 |
sidedata_uuid = get_data(sidedata_uuid_size) |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
303 |
|
47325
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
304 |
index_size = next(iheader) |
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
305 |
|
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
306 |
pending_index_size = next(iheader) |
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
307 |
|
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
308 |
data_size = next(iheader) |
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
309 |
|
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
310 |
pending_data_size = next(iheader) |
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
311 |
|
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
312 |
sidedata_size = next(iheader) |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
313 |
|
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
314 |
pending_sidedata_size = next(iheader) |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
315 |
|
47325
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
316 |
default_compression_header = next(iheader) |
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
317 |
|
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
318 |
docket = RevlogDocket( |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
319 |
revlog, |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
320 |
use_pending=use_pending, |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
321 |
version_header=version_header, |
47323
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
322 |
index_uuid=index_uuid, |
47324
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
323 |
data_uuid=data_uuid, |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
324 |
sidedata_uuid=sidedata_uuid, |
47238
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
325 |
index_end=index_size, |
47241
2219853a1503
revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47238
diff
changeset
|
326 |
pending_index_end=pending_index_size, |
47242
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
327 |
data_end=data_size, |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
328 |
pending_data_end=pending_data_size, |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
329 |
sidedata_end=sidedata_size, |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
330 |
pending_sidedata_end=pending_sidedata_size, |
47255
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
331 |
default_compression_header=default_compression_header, |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
332 |
) |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
333 |
return docket |