##// END OF EJS Templates
revlog: code for `revlogv0` in its own module...
marmoute -
r47812:724db234 default
parent child Browse files
Show More
@@ -0,0 +1,144 b''
1 # revlogv0 - code related to revlog format "V0"
2 #
3 # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com>
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
7 from __future__ import absolute_import
8
9
10 from ..node import sha1nodeconstants
11 from .constants import (
12 INDEX_ENTRY_V0,
13 )
14 from ..i18n import _
15
16 from .. import (
17 error,
18 node,
19 pycompat,
20 util,
21 )
22
23 from . import (
24 flagutil,
25 nodemap as nodemaputil,
26 )
27
28
29 def getoffset(q):
30 return int(q >> 16)
31
32
33 def gettype(q):
34 return int(q & 0xFFFF)
35
36
37 def offset_type(offset, type):
38 if (type & ~flagutil.REVIDX_KNOWN_FLAGS) != 0:
39 raise ValueError(b'unknown revlog index flags')
40 return int(int(offset) << 16 | type)
41
42
43 class revlogoldindex(list):
44 entry_size = INDEX_ENTRY_V0.size
45
46 @property
47 def nodemap(self):
48 msg = b"index.nodemap is deprecated, use index.[has_node|rev|get_rev]"
49 util.nouideprecwarn(msg, b'5.3', stacklevel=2)
50 return self._nodemap
51
52 @util.propertycache
53 def _nodemap(self):
54 nodemap = nodemaputil.NodeMap({sha1nodeconstants.nullid: node.nullrev})
55 for r in range(0, len(self)):
56 n = self[r][7]
57 nodemap[n] = r
58 return nodemap
59
60 def has_node(self, node):
61 """return True if the node exist in the index"""
62 return node in self._nodemap
63
64 def rev(self, node):
65 """return a revision for a node
66
67 If the node is unknown, raise a RevlogError"""
68 return self._nodemap[node]
69
70 def get_rev(self, node):
71 """return a revision for a node
72
73 If the node is unknown, return None"""
74 return self._nodemap.get(node)
75
76 def append(self, tup):
77 self._nodemap[tup[7]] = len(self)
78 super(revlogoldindex, self).append(tup)
79
80 def __delitem__(self, i):
81 if not isinstance(i, slice) or not i.stop == -1 or i.step is not None:
82 raise ValueError(b"deleting slices only supports a:-1 with step 1")
83 for r in pycompat.xrange(i.start, len(self)):
84 del self._nodemap[self[r][7]]
85 super(revlogoldindex, self).__delitem__(i)
86
87 def clearcaches(self):
88 self.__dict__.pop('_nodemap', None)
89
90 def __getitem__(self, i):
91 if i == -1:
92 return (0, 0, 0, -1, -1, -1, -1, node.nullid)
93 return list.__getitem__(self, i)
94
95 def pack_header(self, header):
96 """pack header information in binary"""
97 return b''
98
99 def entry_binary(self, rev):
100 """return the raw binary string representing a revision"""
101 entry = self[rev]
102 if gettype(entry[0]):
103 raise error.RevlogError(
104 _(b'index entry flags need revlog version 1')
105 )
106 e2 = (
107 getoffset(entry[0]),
108 entry[1],
109 entry[3],
110 entry[4],
111 self[entry[5]][7],
112 self[entry[6]][7],
113 entry[7],
114 )
115 return INDEX_ENTRY_V0.pack(*e2)
116
117
118 def parse_index_v0(data, inline):
119 s = INDEX_ENTRY_V0.size
120 index = []
121 nodemap = nodemaputil.NodeMap({node.nullid: node.nullrev})
122 n = off = 0
123 l = len(data)
124 while off + s <= l:
125 cur = data[off : off + s]
126 off += s
127 e = INDEX_ENTRY_V0.unpack(cur)
128 # transform to revlogv1 format
129 e2 = (
130 offset_type(e[0], 0),
131 e[1],
132 -1,
133 e[2],
134 e[3],
135 nodemap.get(e[4], node.nullrev),
136 nodemap.get(e[5], node.nullrev),
137 e[6],
138 )
139 index.append(e2)
140 nodemap[e[6]] = n
141 n += 1
142
143 index = revlogoldindex(index)
144 return index, None
@@ -36,7 +36,6 b' from .pycompat import getattr'
36 from .revlogutils.constants import (
36 from .revlogutils.constants import (
37 FLAG_GENERALDELTA,
37 FLAG_GENERALDELTA,
38 FLAG_INLINE_DATA,
38 FLAG_INLINE_DATA,
39 INDEX_ENTRY_V0,
40 INDEX_HEADER,
39 INDEX_HEADER,
41 REVLOGV0,
40 REVLOGV0,
42 REVLOGV1,
41 REVLOGV1,
@@ -76,6 +75,7 b' from .revlogutils import ('
76 deltas as deltautil,
75 deltas as deltautil,
77 flagutil,
76 flagutil,
78 nodemap as nodemaputil,
77 nodemap as nodemaputil,
78 revlogv0,
79 sidedata as sidedatautil,
79 sidedata as sidedatautil,
80 )
80 )
81 from .utils import (
81 from .utils import (
@@ -136,14 +136,6 b' ellipsisprocessor = ('
136 )
136 )
137
137
138
138
139 def getoffset(q):
140 return int(q >> 16)
141
142
143 def gettype(q):
144 return int(q & 0xFFFF)
145
146
147 def offset_type(offset, type):
139 def offset_type(offset, type):
148 if (type & ~flagutil.REVIDX_KNOWN_FLAGS) != 0:
140 if (type & ~flagutil.REVIDX_KNOWN_FLAGS) != 0:
149 raise ValueError(b'unknown revlog index flags')
141 raise ValueError(b'unknown revlog index flags')
@@ -214,110 +206,6 b' class revlogproblem(object):'
214 node = attr.ib(default=None)
206 node = attr.ib(default=None)
215
207
216
208
217 class revlogoldindex(list):
218 entry_size = INDEX_ENTRY_V0.size
219
220 @property
221 def nodemap(self):
222 msg = b"index.nodemap is deprecated, use index.[has_node|rev|get_rev]"
223 util.nouideprecwarn(msg, b'5.3', stacklevel=2)
224 return self._nodemap
225
226 @util.propertycache
227 def _nodemap(self):
228 nodemap = nodemaputil.NodeMap({sha1nodeconstants.nullid: nullrev})
229 for r in range(0, len(self)):
230 n = self[r][7]
231 nodemap[n] = r
232 return nodemap
233
234 def has_node(self, node):
235 """return True if the node exist in the index"""
236 return node in self._nodemap
237
238 def rev(self, node):
239 """return a revision for a node
240
241 If the node is unknown, raise a RevlogError"""
242 return self._nodemap[node]
243
244 def get_rev(self, node):
245 """return a revision for a node
246
247 If the node is unknown, return None"""
248 return self._nodemap.get(node)
249
250 def append(self, tup):
251 self._nodemap[tup[7]] = len(self)
252 super(revlogoldindex, self).append(tup)
253
254 def __delitem__(self, i):
255 if not isinstance(i, slice) or not i.stop == -1 or i.step is not None:
256 raise ValueError(b"deleting slices only supports a:-1 with step 1")
257 for r in pycompat.xrange(i.start, len(self)):
258 del self._nodemap[self[r][7]]
259 super(revlogoldindex, self).__delitem__(i)
260
261 def clearcaches(self):
262 self.__dict__.pop('_nodemap', None)
263
264 def __getitem__(self, i):
265 if i == -1:
266 return (0, 0, 0, -1, -1, -1, -1, sha1nodeconstants.nullid)
267 return list.__getitem__(self, i)
268
269 def entry_binary(self, rev):
270 """return the raw binary string representing a revision"""
271 entry = self[rev]
272 if gettype(entry[0]):
273 raise error.RevlogError(
274 _(b'index entry flags need revlog version 1')
275 )
276 e2 = (
277 getoffset(entry[0]),
278 entry[1],
279 entry[3],
280 entry[4],
281 self[entry[5]][7],
282 self[entry[6]][7],
283 entry[7],
284 )
285 return INDEX_ENTRY_V0.pack(*e2)
286
287 def pack_header(self, header):
288 """Pack header information in binary"""
289 return b''
290
291
292 def parse_index_v0(data, inline):
293 s = INDEX_ENTRY_V0.size
294 index = []
295 nodemap = nodemaputil.NodeMap({sha1nodeconstants.nullid: nullrev})
296 n = off = 0
297 l = len(data)
298 while off + s <= l:
299 cur = data[off : off + s]
300 off += s
301 e = INDEX_ENTRY_V0.unpack(cur)
302 # transform to revlogv1 format
303 e2 = (
304 offset_type(e[0], 0),
305 e[1],
306 -1,
307 e[2],
308 e[3],
309 nodemap.get(e[4], nullrev),
310 nodemap.get(e[5], nullrev),
311 e[6],
312 )
313 index.append(e2)
314 nodemap[e[6]] = n
315 n += 1
316
317 index = revlogoldindex(index)
318 return index, None
319
320
321 def parse_index_v1(data, inline):
209 def parse_index_v1(data, inline):
322 # call the C implementation to parse the index data
210 # call the C implementation to parse the index data
323 index, cache = parsers.parse_index2(data, inline)
211 index, cache = parsers.parse_index2(data, inline)
@@ -621,7 +509,7 b' class revlog(object):'
621
509
622 self._parse_index = parse_index_v1
510 self._parse_index = parse_index_v1
623 if self.version == REVLOGV0:
511 if self.version == REVLOGV0:
624 self._parse_index = parse_index_v0
512 self._parse_index = revlogv0.parse_index_v0
625 elif fmt == REVLOGV2:
513 elif fmt == REVLOGV2:
626 self._parse_index = parse_index_v2
514 self._parse_index = parse_index_v2
627 elif devel_nodemap:
515 elif devel_nodemap:
General Comments 0
You need to be logged in to leave comments. Login now