##// END OF EJS Templates
revlog: create a create `null_item` attribute for V0...
marmoute -
r48021:ba21cfd9 default
parent child Browse files
Show More
@@ -1,146 +1,147 b''
1 # revlogv0 - code related to revlog format "V0"
1 # revlogv0 - code related to revlog format "V0"
2 #
2 #
3 # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com>
3 # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
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.
6 # GNU General Public License version 2 or any later version.
7 from __future__ import absolute_import
7 from __future__ import absolute_import
8
8
9
9
10 from ..node import sha1nodeconstants
10 from ..node import sha1nodeconstants
11 from .constants import (
11 from .constants import (
12 INDEX_ENTRY_V0,
12 INDEX_ENTRY_V0,
13 )
13 )
14 from ..i18n import _
14 from ..i18n import _
15
15
16 from .. import (
16 from .. import (
17 error,
17 error,
18 node,
18 node,
19 pycompat,
19 pycompat,
20 util,
20 util,
21 )
21 )
22
22
23 from . import (
23 from . import (
24 flagutil,
24 flagutil,
25 nodemap as nodemaputil,
25 nodemap as nodemaputil,
26 )
26 )
27
27
28
28
29 def getoffset(q):
29 def getoffset(q):
30 return int(q >> 16)
30 return int(q >> 16)
31
31
32
32
33 def gettype(q):
33 def gettype(q):
34 return int(q & 0xFFFF)
34 return int(q & 0xFFFF)
35
35
36
36
37 def offset_type(offset, type):
37 def offset_type(offset, type):
38 if (type & ~flagutil.REVIDX_KNOWN_FLAGS) != 0:
38 if (type & ~flagutil.REVIDX_KNOWN_FLAGS) != 0:
39 raise ValueError(b'unknown revlog index flags')
39 raise ValueError(b'unknown revlog index flags')
40 return int(int(offset) << 16 | type)
40 return int(int(offset) << 16 | type)
41
41
42
42
43 class revlogoldindex(list):
43 class revlogoldindex(list):
44 entry_size = INDEX_ENTRY_V0.size
44 entry_size = INDEX_ENTRY_V0.size
45 null_item = (0, 0, 0, -1, -1, -1, -1, node.nullid)
45
46
46 @property
47 @property
47 def nodemap(self):
48 def nodemap(self):
48 msg = b"index.nodemap is deprecated, use index.[has_node|rev|get_rev]"
49 msg = b"index.nodemap is deprecated, use index.[has_node|rev|get_rev]"
49 util.nouideprecwarn(msg, b'5.3', stacklevel=2)
50 util.nouideprecwarn(msg, b'5.3', stacklevel=2)
50 return self._nodemap
51 return self._nodemap
51
52
52 @util.propertycache
53 @util.propertycache
53 def _nodemap(self):
54 def _nodemap(self):
54 nodemap = nodemaputil.NodeMap({sha1nodeconstants.nullid: node.nullrev})
55 nodemap = nodemaputil.NodeMap({sha1nodeconstants.nullid: node.nullrev})
55 for r in range(0, len(self)):
56 for r in range(0, len(self)):
56 n = self[r][7]
57 n = self[r][7]
57 nodemap[n] = r
58 nodemap[n] = r
58 return nodemap
59 return nodemap
59
60
60 def has_node(self, node):
61 def has_node(self, node):
61 """return True if the node exist in the index"""
62 """return True if the node exist in the index"""
62 return node in self._nodemap
63 return node in self._nodemap
63
64
64 def rev(self, node):
65 def rev(self, node):
65 """return a revision for a node
66 """return a revision for a node
66
67
67 If the node is unknown, raise a RevlogError"""
68 If the node is unknown, raise a RevlogError"""
68 return self._nodemap[node]
69 return self._nodemap[node]
69
70
70 def get_rev(self, node):
71 def get_rev(self, node):
71 """return a revision for a node
72 """return a revision for a node
72
73
73 If the node is unknown, return None"""
74 If the node is unknown, return None"""
74 return self._nodemap.get(node)
75 return self._nodemap.get(node)
75
76
76 def append(self, tup):
77 def append(self, tup):
77 self._nodemap[tup[7]] = len(self)
78 self._nodemap[tup[7]] = len(self)
78 super(revlogoldindex, self).append(tup)
79 super(revlogoldindex, self).append(tup)
79
80
80 def __delitem__(self, i):
81 def __delitem__(self, i):
81 if not isinstance(i, slice) or not i.stop == -1 or i.step is not None:
82 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 raise ValueError(b"deleting slices only supports a:-1 with step 1")
83 for r in pycompat.xrange(i.start, len(self)):
84 for r in pycompat.xrange(i.start, len(self)):
84 del self._nodemap[self[r][7]]
85 del self._nodemap[self[r][7]]
85 super(revlogoldindex, self).__delitem__(i)
86 super(revlogoldindex, self).__delitem__(i)
86
87
87 def clearcaches(self):
88 def clearcaches(self):
88 self.__dict__.pop('_nodemap', None)
89 self.__dict__.pop('_nodemap', None)
89
90
90 def __getitem__(self, i):
91 def __getitem__(self, i):
91 if i == -1:
92 if i == -1:
92 return (0, 0, 0, -1, -1, -1, -1, node.nullid)
93 return self.null_item
93 return list.__getitem__(self, i)
94 return list.__getitem__(self, i)
94
95
95 def pack_header(self, header):
96 def pack_header(self, header):
96 """pack header information in binary"""
97 """pack header information in binary"""
97 return b''
98 return b''
98
99
99 def entry_binary(self, rev):
100 def entry_binary(self, rev):
100 """return the raw binary string representing a revision"""
101 """return the raw binary string representing a revision"""
101 entry = self[rev]
102 entry = self[rev]
102 if gettype(entry[0]):
103 if gettype(entry[0]):
103 raise error.RevlogError(
104 raise error.RevlogError(
104 _(b'index entry flags need revlog version 1')
105 _(b'index entry flags need revlog version 1')
105 )
106 )
106 e2 = (
107 e2 = (
107 getoffset(entry[0]),
108 getoffset(entry[0]),
108 entry[1],
109 entry[1],
109 entry[3],
110 entry[3],
110 entry[4],
111 entry[4],
111 self[entry[5]][7],
112 self[entry[5]][7],
112 self[entry[6]][7],
113 self[entry[6]][7],
113 entry[7],
114 entry[7],
114 )
115 )
115 return INDEX_ENTRY_V0.pack(*e2)
116 return INDEX_ENTRY_V0.pack(*e2)
116
117
117
118
118 def parse_index_v0(data, inline):
119 def parse_index_v0(data, inline):
119 s = INDEX_ENTRY_V0.size
120 s = INDEX_ENTRY_V0.size
120 index = []
121 index = []
121 nodemap = nodemaputil.NodeMap({node.nullid: node.nullrev})
122 nodemap = nodemaputil.NodeMap({node.nullid: node.nullrev})
122 n = off = 0
123 n = off = 0
123 l = len(data)
124 l = len(data)
124 while off + s <= l:
125 while off + s <= l:
125 cur = data[off : off + s]
126 cur = data[off : off + s]
126 off += s
127 off += s
127 e = INDEX_ENTRY_V0.unpack(cur)
128 e = INDEX_ENTRY_V0.unpack(cur)
128 # transform to revlogv1 format
129 # transform to revlogv1 format
129 e2 = (
130 e2 = (
130 offset_type(e[0], 0),
131 offset_type(e[0], 0),
131 e[1],
132 e[1],
132 -1,
133 -1,
133 e[2],
134 e[2],
134 e[3],
135 e[3],
135 nodemap.get(e[4], node.nullrev),
136 nodemap.get(e[4], node.nullrev),
136 nodemap.get(e[5], node.nullrev),
137 nodemap.get(e[5], node.nullrev),
137 e[6],
138 e[6],
138 0, # no side data support
139 0, # no side data support
139 0, # no side data support
140 0, # no side data support
140 )
141 )
141 index.append(e2)
142 index.append(e2)
142 nodemap[e[6]] = n
143 nodemap[e[6]] = n
143 n += 1
144 n += 1
144
145
145 index = revlogoldindex(index)
146 index = revlogoldindex(index)
146 return index, None
147 return index, None
General Comments 0
You need to be logged in to leave comments. Login now