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