author | Gregory Szorc <gregory.szorc@gmail.com> |
Mon, 21 Feb 2022 10:48:45 -0700 | |
changeset 48908 | ed2af4560f6e |
parent 48875 | 6000f5b25c9b |
child 48909 | 0aae0e2e90fc |
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 |
|
47312
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
19 |
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
|
20 |
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
|
21 |
import random |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 |
import struct |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 |
|
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
|
24 |
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
|
25 |
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
|
26 |
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
|
27 |
node, |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
28 |
pycompat, |
47255
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
29 |
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
|
30 |
) |
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 |
|
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
32 |
from . import ( |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
33 |
constants, |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
34 |
) |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
35 |
|
47312
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
36 |
|
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
37 |
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
|
38 |
"""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
|
39 |
|
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
40 |
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
|
41 |
# 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
|
42 |
# 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
|
43 |
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
|
44 |
|
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 |
# 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
|
47 |
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
|
48 |
|
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
49 |
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
|
50 |
|
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
51 |
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
|
52 |
try: |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
53 |
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
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
raise |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
58 |
seed = b'04' # chosen by a fair dice roll. garanteed to be random |
48908
ed2af4560f6e
revlogutils: remove Python 2 variant for iter_seed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
59 |
iter_seed = iter(seed) |
47312
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
60 |
# 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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
else: |
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.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
|
72 |
# 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
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
|
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47266
diff
changeset
|
81 |
|
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
82 |
# Docket format |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
83 |
# |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
84 |
# * 4 bytes: revlog version |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
85 |
# | 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
|
86 |
# | revlog index header. |
47323
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
87 |
# * 1 bytes: size of index uuid |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
88 |
# * 1 bytes: number of outdated index uuid |
47324
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
89 |
# * 1 bytes: size of data uuid |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
90 |
# * 1 bytes: number of outdated data uuid |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
91 |
# * 1 bytes: size of sizedata uuid |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
92 |
# * 1 bytes: number of outdated data 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
|
93 |
# * 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
|
94 |
# * 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
|
95 |
# * 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
|
96 |
# * 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
|
97 |
# * 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
|
98 |
# * 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
|
99 |
# * 1 bytes: default compression header |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
100 |
S_HEADER = struct.Struct(constants.INDEX_HEADER_FMT + b'BBBBBBLLLLLLc') |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
101 |
# * 1 bytes: size of index uuid |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
102 |
# * 8 bytes: size of file |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
103 |
S_OLD_UID = struct.Struct('>BL') |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
104 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
105 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
106 |
class RevlogDocket(object): |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
107 |
"""metadata associated with revlog""" |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
108 |
|
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
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
version_header=None, |
47323
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
114 |
index_uuid=None, |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
115 |
older_index_uuids=(), |
47324
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
116 |
data_uuid=None, |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
117 |
older_data_uuids=(), |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
118 |
sidedata_uuid=None, |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
119 |
older_sidedata_uuids=(), |
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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
sidedata_end=0, |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
125 |
pending_sidedata_end=0, |
47255
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
126 |
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
|
127 |
): |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
128 |
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
|
129 |
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
|
130 |
self._dirty = False |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
131 |
self._radix = revlog.radix |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
132 |
self._path = revlog._docket_file |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
133 |
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
|
134 |
self._index_uuid = index_uuid |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
135 |
self._older_index_uuids = older_index_uuids |
47324
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
136 |
self._data_uuid = data_uuid |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
137 |
self._older_data_uuids = older_data_uuids |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
138 |
self._sidedata_uuid = sidedata_uuid |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
139 |
self._older_sidedata_uuids = older_sidedata_uuids |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
140 |
assert not set(older_index_uuids) & set(older_data_uuids) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
141 |
assert not set(older_data_uuids) & set(older_sidedata_uuids) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
142 |
assert not set(older_index_uuids) & set(older_sidedata_uuids) |
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
|
143 |
# 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
|
144 |
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
|
145 |
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
|
146 |
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
|
147 |
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
|
148 |
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
|
149 |
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
|
150 |
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
|
151 |
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
|
152 |
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
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
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
|
160 |
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
|
161 |
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
|
162 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
163 |
def index_filepath(self): |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
164 |
"""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
|
165 |
# 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
|
166 |
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
|
167 |
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
|
168 |
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
|
169 |
|
47454
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
170 |
def new_index_file(self): |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
171 |
"""switch index file to a new UID |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
172 |
|
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
173 |
The previous index UID is moved to the "older" list.""" |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
174 |
old = (self._index_uuid, self._index_end) |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
175 |
self._older_index_uuids.insert(0, old) |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
176 |
self._index_uuid = make_uid() |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
177 |
return self.index_filepath() |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
178 |
|
47455
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
179 |
def old_index_filepaths(self, include_empty=True): |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
180 |
"""yield file path to older index files associated to this docket""" |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
181 |
# very simplistic version at first |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
182 |
for uuid, size in self._older_index_uuids: |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
183 |
if include_empty or size > 0: |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
184 |
yield b"%s-%s.idx" % (self._radix, uuid) |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
185 |
|
47324
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
186 |
def data_filepath(self): |
47388
bcf92bdc2bca
revlog: fix docket.date_filepath docstring
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47371
diff
changeset
|
187 |
"""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
|
188 |
# 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
|
189 |
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
|
190 |
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
|
191 |
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
|
192 |
|
47454
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
193 |
def new_data_file(self): |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
194 |
"""switch data file to a new UID |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
195 |
|
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
196 |
The previous data UID is moved to the "older" list.""" |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
197 |
old = (self._data_uuid, self._data_end) |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
198 |
self._older_data_uuids.insert(0, old) |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
199 |
self._data_uuid = make_uid() |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
200 |
return self.data_filepath() |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
201 |
|
47455
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
202 |
def old_data_filepaths(self, include_empty=True): |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
203 |
"""yield file path to older data files associated to this docket""" |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
204 |
# very simplistic version at first |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
205 |
for uuid, size in self._older_data_uuids: |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
206 |
if include_empty or size > 0: |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
207 |
yield b"%s-%s.dat" % (self._radix, uuid) |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
208 |
|
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
209 |
def sidedata_filepath(self): |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
210 |
"""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
|
211 |
# 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
|
212 |
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
|
213 |
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
|
214 |
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
|
215 |
|
47454
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
216 |
def new_sidedata_file(self): |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
217 |
"""switch sidedata file to a new UID |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
218 |
|
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
219 |
The previous sidedata UID is moved to the "older" list.""" |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
220 |
old = (self._sidedata_uuid, self._sidedata_end) |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
221 |
self._older_sidedata_uuids.insert(0, old) |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
222 |
self._sidedata_uuid = make_uid() |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
223 |
return self.sidedata_filepath() |
865c260d7163
revlog: add docket method to request new content files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47453
diff
changeset
|
224 |
|
47455
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
225 |
def old_sidedata_filepaths(self, include_empty=True): |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
226 |
"""yield file path to older sidedata files associated to this docket""" |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
227 |
# very simplistic version at first |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
228 |
for uuid, size in self._older_sidedata_uuids: |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
229 |
if include_empty or size > 0: |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
230 |
yield b"%s-%s.sda" % (self._radix, uuid) |
f93a867a6486
revlog: list older-but-still-around file in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47454
diff
changeset
|
231 |
|
47238
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
232 |
@property |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
233 |
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
|
234 |
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
|
235 |
|
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
236 |
@index_end.setter |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
237 |
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
|
238 |
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
|
239 |
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
|
240 |
self._dirty = True |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
241 |
|
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
|
242 |
@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
|
243 |
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
|
244 |
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
|
245 |
|
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
246 |
@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
|
247 |
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
|
248 |
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
|
249 |
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
|
250 |
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
|
251 |
|
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
252 |
@property |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
253 |
def sidedata_end(self): |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
254 |
return self._sidedata_end |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
255 |
|
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
256 |
@sidedata_end.setter |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
257 |
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
|
258 |
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
|
259 |
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
|
260 |
self._dirty = True |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
261 |
|
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
|
262 |
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
|
263 |
"""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
|
264 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
265 |
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
|
266 |
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
|
267 |
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
|
268 |
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
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
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
|
273 |
if not stripping: |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
274 |
# 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
|
275 |
# 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
|
276 |
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
|
277 |
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
|
278 |
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
|
279 |
# 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
|
280 |
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
|
281 |
return True |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
282 |
|
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
|
283 |
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
|
284 |
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
|
285 |
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
|
286 |
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
|
287 |
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
|
288 |
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
|
289 |
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
|
290 |
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
|
291 |
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
|
292 |
|
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
|
293 |
# 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
|
294 |
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
|
295 |
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
|
296 |
data = ( |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
297 |
self._version_header, |
47323
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
298 |
len(self._index_uuid), |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
299 |
len(self._older_index_uuids), |
47324
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
300 |
len(self._data_uuid), |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
301 |
len(self._older_data_uuids), |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
302 |
len(self._sidedata_uuid), |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
303 |
len(self._older_sidedata_uuids), |
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
|
304 |
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
|
305 |
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
|
306 |
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
|
307 |
self._data_end, |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
308 |
official_sidedata_end, |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
309 |
self._sidedata_end, |
47255
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
310 |
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
|
311 |
) |
47323
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
312 |
s = [] |
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
313 |
s.append(S_HEADER.pack(*data)) |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
314 |
|
47323
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
315 |
s.append(self._index_uuid) |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
316 |
for u, size in self._older_index_uuids: |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
317 |
s.append(S_OLD_UID.pack(len(u), size)) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
318 |
for u, size in self._older_index_uuids: |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
319 |
s.append(u) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
320 |
|
47324
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
321 |
s.append(self._data_uuid) |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
322 |
for u, size in self._older_data_uuids: |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
323 |
s.append(S_OLD_UID.pack(len(u), size)) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
324 |
for u, size in self._older_data_uuids: |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
325 |
s.append(u) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
326 |
|
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
327 |
s.append(self._sidedata_uuid) |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
328 |
for u, size in self._older_sidedata_uuids: |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
329 |
s.append(S_OLD_UID.pack(len(u), size)) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
330 |
for u, size in self._older_sidedata_uuids: |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
331 |
s.append(u) |
47323
f612db768c7a
revlogv2: use a unique filename for index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
332 |
return b''.join(s) |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
333 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
334 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
335 |
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
|
336 |
"""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
|
337 |
rl_version = version_header & 0xFFFF |
921648d31553
changelogv2: use a dedicated version number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47255
diff
changeset
|
338 |
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
|
339 |
return None |
47255
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
340 |
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
|
341 |
docket = RevlogDocket( |
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
342 |
revlog, |
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
343 |
version_header=version_header, |
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
344 |
default_compression_header=comp, |
ff9fd7107d11
revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47242
diff
changeset
|
345 |
) |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
346 |
docket._dirty = True |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
347 |
return docket |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
348 |
|
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
349 |
|
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
350 |
def _parse_old_uids(get_data, count): |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
351 |
all_sizes = [] |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
352 |
all_uids = [] |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
353 |
for i in range(0, count): |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
354 |
raw = get_data(S_OLD_UID.size) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
355 |
all_sizes.append(S_OLD_UID.unpack(raw)) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
356 |
|
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
357 |
for uid_size, file_size in all_sizes: |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
358 |
uid = get_data(uid_size) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
359 |
all_uids.append((uid, file_size)) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
360 |
return all_uids |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
361 |
|
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
362 |
|
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
|
363 |
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
|
364 |
"""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
|
365 |
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
|
366 |
|
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
|
367 |
# 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
|
368 |
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
|
369 |
|
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
|
370 |
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
|
371 |
"""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
|
372 |
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
|
373 |
# 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
|
374 |
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
|
375 |
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
|
376 |
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
|
377 |
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
|
378 |
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
|
379 |
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
|
380 |
|
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
381 |
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
|
382 |
|
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
383 |
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
|
384 |
|
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
385 |
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
|
386 |
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
|
387 |
|
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
388 |
older_index_uuid_count = next(iheader) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
389 |
older_index_uuids = _parse_old_uids(get_data, older_index_uuid_count) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
390 |
|
47325
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
391 |
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
|
392 |
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
|
393 |
|
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
394 |
older_data_uuid_count = next(iheader) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
395 |
older_data_uuids = _parse_old_uids(get_data, older_data_uuid_count) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
396 |
|
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
397 |
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
|
398 |
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
|
399 |
|
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
400 |
older_sidedata_uuid_count = next(iheader) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
401 |
older_sidedata_uuids = _parse_old_uids(get_data, older_sidedata_uuid_count) |
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
402 |
|
47325
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
403 |
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
|
404 |
|
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
405 |
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
|
406 |
|
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
407 |
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
|
408 |
|
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
409 |
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
|
410 |
|
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
411 |
sidedata_size = next(iheader) |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
412 |
|
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
413 |
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
|
414 |
|
47325
f286d715f9ab
revlogv2: simplify and clarify the processing of each entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47324
diff
changeset
|
415 |
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
|
416 |
|
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
417 |
docket = RevlogDocket( |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
418 |
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
|
419 |
use_pending=use_pending, |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
420 |
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
|
421 |
index_uuid=index_uuid, |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
422 |
older_index_uuids=older_index_uuids, |
47324
0a3fa41fa719
revlogv2: use a unique filename for data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47323
diff
changeset
|
423 |
data_uuid=data_uuid, |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
424 |
older_data_uuids=older_data_uuids, |
47389
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
425 |
sidedata_uuid=sidedata_uuid, |
47453
c252631500e4
revlog: add a way to keep track of older uids in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47423
diff
changeset
|
426 |
older_sidedata_uuids=older_sidedata_uuids, |
47238
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
427 |
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
|
428 |
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
|
429 |
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
|
430 |
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
|
431 |
sidedata_end=sidedata_size, |
e6292eb33384
revlog: store sidedata in their own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47388
diff
changeset
|
432 |
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
|
433 |
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
|
434 |
) |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
435 |
return docket |