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