Mercurial > hg
annotate mercurial/revlogutils/docket.py @ 47242:4abd474a10af
revlogv2: also keep track for the size of the "data" file
This is useful to make sure we always start writing at the right location,
without effort.
Differential Revision: https://phab.mercurial-scm.org/D10632
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 03 May 2021 12:35:35 +0200 |
parents | 2219853a1503 |
children | ff9fd7107d11 |
rev | line source |
---|---|
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 |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 import struct |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
21 |
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
|
22 from .. import ( |
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
|
23 error, |
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 ) |
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 |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
26 from . import ( |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
27 constants, |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
28 ) |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
29 |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
30 # Docket format |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
31 # |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
32 # * 4 bytes: revlog version |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
33 # | 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
|
34 # | revlog index header. |
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
|
35 # * 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
|
36 # * 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
|
37 # * 8 bytes: size of 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
|
38 # * 8 bytes: pending size of 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
|
39 S_HEADER = struct.Struct(constants.INDEX_HEADER.format + 'LLLL') |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
40 |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
41 |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
42 class RevlogDocket(object): |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
43 """metadata associated with revlog""" |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
44 |
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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 version_header=None, |
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
|
50 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
|
51 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
|
52 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
|
53 pending_data_end=0, |
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
|
54 ): |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
55 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
|
56 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
|
57 self._dirty = False |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
58 self._radix = revlog.radix |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
59 self._path = revlog._docket_file |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
60 self._opener = revlog.opener |
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
|
61 # 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
|
62 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
|
63 assert data_end <= pending_data_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
|
64 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
|
65 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
|
66 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
|
67 self._pending_data_end = pending_data_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
|
68 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
|
69 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
|
70 self._data_end = self._pending_data_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
|
71 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
|
72 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
|
73 self._data_end = self._initial_data_end |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
74 |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
75 def index_filepath(self): |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
76 """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
|
77 # very simplistic version at first |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
78 return b"%s.idx" % self._radix |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
79 |
47238
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
80 @property |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
81 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
|
82 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
|
83 |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
84 @index_end.setter |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
85 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
|
86 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
|
87 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
|
88 self._dirty = True |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
89 |
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
|
90 @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
|
91 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
|
92 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
|
93 |
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 @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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 |
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
|
100 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
|
101 """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
|
102 |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 if not stripping: |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
112 # 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
|
113 # 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
|
114 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
|
115 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
|
116 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
|
117 # 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
|
118 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
|
119 return True |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
120 |
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
|
121 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
|
122 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
|
123 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
|
124 official_data_end = self._initial_data_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
|
125 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
|
126 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
|
127 official_data_end = self._data_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
|
128 |
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 # 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
|
130 assert official_data_end <= self._data_end |
47238
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
131 data = ( |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
132 self._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
|
133 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
|
134 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
|
135 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
|
136 self._data_end, |
47238
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
137 ) |
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
138 return S_HEADER.pack(*data) |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
139 |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
140 |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
141 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
|
142 """given a revlog version a new 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
|
143 if (version_header & 0xFFFF) != constants.REVLOGV2: |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
144 return None |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
145 docket = RevlogDocket(revlog, version_header=version_header) |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
146 docket._dirty = True |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
147 return docket |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
148 |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
149 |
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
|
150 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
|
151 """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
|
152 header = S_HEADER.unpack(data[: S_HEADER.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
|
153 version_header = header[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
|
154 index_size = header[1] |
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 pending_index_size = header[2] |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
156 data_size = header[3] |
4abd474a10af
revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47241
diff
changeset
|
157 pending_data_size = header[4] |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
158 docket = RevlogDocket( |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
159 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
|
160 use_pending=use_pending, |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
161 version_header=version_header, |
47238
6597255a4f94
revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47234
diff
changeset
|
162 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
|
163 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
|
164 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
|
165 pending_data_end=pending_data_size, |
47234
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
166 ) |
616b8f412676
revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
167 return docket |