##// END OF EJS Templates
revlog: make the index always return the same tuple...
marmoute -
r47913:4292bed8 default
parent child Browse files
Show More
@@ -335,18 +335,17 b' static PyObject *index_get(indexObject *'
335 c_node_id = data + 32;
335 c_node_id = data + 32;
336
336
337 if (self->entry_size == v1_entry_size) {
337 if (self->entry_size == v1_entry_size) {
338 return Py_BuildValue(v1_tuple_format, offset_flags, comp_len,
338 sidedata_offset = 0;
339 uncomp_len, base_rev, link_rev, parent_1,
339 sidedata_comp_len = 0;
340 parent_2, c_node_id, self->nodelen);
341 } else {
340 } else {
342 sidedata_offset = getbe64(data + 64);
341 sidedata_offset = getbe64(data + 64);
343 sidedata_comp_len = getbe32(data + 72);
342 sidedata_comp_len = getbe32(data + 72);
343 }
344
344
345 return Py_BuildValue(v2_tuple_format, offset_flags, comp_len,
345 return Py_BuildValue(v2_tuple_format, offset_flags, comp_len,
346 uncomp_len, base_rev, link_rev, parent_1,
346 uncomp_len, base_rev, link_rev, parent_1, parent_2,
347 parent_2, c_node_id, self->nodelen,
347 c_node_id, self->nodelen, sidedata_offset,
348 sidedata_offset, sidedata_comp_len);
348 sidedata_comp_len);
349 }
350 }
349 }
351 /*
350 /*
352 * Pack header information in binary
351 * Pack header information in binary
@@ -2769,15 +2768,9 b' static int index_init(indexObject *self,'
2769 self->entry_size = v1_entry_size;
2768 self->entry_size = v1_entry_size;
2770 }
2769 }
2771
2770
2772 if (self->format_version == format_v1) {
2773 self->nullentry =
2771 self->nullentry =
2774 Py_BuildValue(PY23("iiiiiiis#", "iiiiiiiy#"), 0, 0, 0, -1,
2772 Py_BuildValue(PY23("iiiiiiis#ii", "iiiiiiiy#ii"), 0, 0, 0, -1, -1,
2775 -1, -1, -1, nullid, self->nodelen);
2773 -1, -1, nullid, self->nodelen, 0, 0);
2776 } else {
2777 self->nullentry =
2778 Py_BuildValue(PY23("iiiiiiis#ii", "iiiiiiiy#ii"), 0, 0, 0,
2779 -1, -1, -1, -1, nullid, self->nodelen, 0, 0);
2780 }
2781
2774
2782 if (!self->nullentry)
2775 if (!self->nullentry)
2783 return -1;
2776 return -1;
@@ -53,7 +53,7 b' class BaseIndexObject(object):'
53 # Size of a C long int, platform independent
53 # Size of a C long int, platform independent
54 int_size = struct.calcsize(b'>i')
54 int_size = struct.calcsize(b'>i')
55 # An empty index entry, used as a default value to be overridden, or nullrev
55 # An empty index entry, used as a default value to be overridden, or nullrev
56 null_item = (0, 0, 0, -1, -1, -1, -1, sha1nodeconstants.nullid)
56 null_item = (0, 0, 0, -1, -1, -1, -1, sha1nodeconstants.nullid, 0, 0)
57
57
58 @util.propertycache
58 @util.propertycache
59 def entry_size(self):
59 def entry_size(self):
@@ -122,11 +122,16 b' class BaseIndexObject(object):'
122 else:
122 else:
123 index = self._calculate_index(i)
123 index = self._calculate_index(i)
124 data = self._data[index : index + self.entry_size]
124 data = self._data[index : index + self.entry_size]
125 r = self.index_format.unpack(data)
125 r = self._unpack_entry(data)
126 if self._lgt and i == 0:
126 if self._lgt and i == 0:
127 r = (offset_type(0, gettype(r[0])),) + r[1:]
127 r = (offset_type(0, gettype(r[0])),) + r[1:]
128 return r
128 return r
129
129
130 def _unpack_entry(self, data):
131 r = self.index_format.unpack(data)
132 r = r + (0, 0)
133 return r
134
130 def pack_header(self, header):
135 def pack_header(self, header):
131 """pack header information as binary"""
136 """pack header information as binary"""
132 v_fmt = revlog_constants.INDEX_HEADER
137 v_fmt = revlog_constants.INDEX_HEADER
@@ -135,7 +140,7 b' class BaseIndexObject(object):'
135 def entry_binary(self, rev):
140 def entry_binary(self, rev):
136 """return the raw binary string representing a revision"""
141 """return the raw binary string representing a revision"""
137 entry = self[rev]
142 entry = self[rev]
138 p = revlog_constants.INDEX_ENTRY_V1.pack(*entry)
143 p = revlog_constants.INDEX_ENTRY_V1.pack(*entry[:8])
139 if rev == 0:
144 if rev == 0:
140 p = p[revlog_constants.INDEX_HEADER.size :]
145 p = p[revlog_constants.INDEX_HEADER.size :]
141 return p
146 return p
@@ -266,7 +271,6 b' def parse_index2(data, inline, revlogv2='
266
271
267 class Index2Mixin(object):
272 class Index2Mixin(object):
268 index_format = revlog_constants.INDEX_ENTRY_V2
273 index_format = revlog_constants.INDEX_ENTRY_V2
269 null_item = (0, 0, 0, -1, -1, -1, -1, sha1nodeconstants.nullid, 0, 0)
270
274
271 def replace_sidedata_info(
275 def replace_sidedata_info(
272 self, i, sidedata_offset, sidedata_length, offset_flags
276 self, i, sidedata_offset, sidedata_length, offset_flags
@@ -292,6 +296,9 b' class Index2Mixin(object):'
292 msg = b"cannot rewrite entries outside of this transaction"
296 msg = b"cannot rewrite entries outside of this transaction"
293 raise KeyError(msg)
297 raise KeyError(msg)
294
298
299 def _unpack_entry(self, data):
300 return self.index_format.unpack(data)
301
295 def entry_binary(self, rev):
302 def entry_binary(self, rev):
296 """return the raw binary string representing a revision"""
303 """return the raw binary string representing a revision"""
297 entry = self[rev]
304 entry = self[rev]
@@ -135,6 +135,8 b' def parse_index_v0(data, inline):'
135 nodemap.get(e[4], node.nullrev),
135 nodemap.get(e[4], node.nullrev),
136 nodemap.get(e[5], node.nullrev),
136 nodemap.get(e[5], node.nullrev),
137 e[6],
137 e[6],
138 0, # no side data support
139 0, # no side data support
138 )
140 )
139 index.append(e2)
141 index.append(e2)
140 nodemap[e[6]] = n
142 nodemap[e[6]] = n
@@ -54,7 +54,18 b' class unionrevlog(revlog.revlog):'
54 for rev2 in self.revlog2:
54 for rev2 in self.revlog2:
55 rev = self.revlog2.index[rev2]
55 rev = self.revlog2.index[rev2]
56 # rev numbers - in revlog2, very different from self.rev
56 # rev numbers - in revlog2, very different from self.rev
57 _start, _csize, rsize, base, linkrev, p1rev, p2rev, node = rev
57 (
58 _start,
59 _csize,
60 rsize,
61 base,
62 linkrev,
63 p1rev,
64 p2rev,
65 node,
66 _sdo,
67 _sds,
68 ) = rev
58 flags = _start & 0xFFFF
69 flags = _start & 0xFFFF
59
70
60 if linkmapper is None: # link is to same revlog
71 if linkmapper is None: # link is to same revlog
@@ -49,6 +49,7 b' def py_parseindex(data, inline):'
49 cache = (0, data)
49 cache = (0, data)
50 while off <= l:
50 while off <= l:
51 e = struct.unpack(indexformatng, data[off : off + s])
51 e = struct.unpack(indexformatng, data[off : off + s])
52 e = e + (0, 0)
52 nodemap[e[7]] = n
53 nodemap[e[7]] = n
53 append(e)
54 append(e)
54 n += 1
55 n += 1
@@ -58,6 +59,7 b' def py_parseindex(data, inline):'
58 else:
59 else:
59 while off <= l:
60 while off <= l:
60 e = struct.unpack(indexformatng, data[off : off + s])
61 e = struct.unpack(indexformatng, data[off : off + s])
62 e = e + (0, 0)
61 nodemap[e[7]] = n
63 nodemap[e[7]] = n
62 append(e)
64 append(e)
63 n += 1
65 n += 1
@@ -240,7 +242,7 b' class parseindex2tests(unittest.TestCase'
240 break
242 break
241
243
242 def testminusone(self):
244 def testminusone(self):
243 want = (0, 0, 0, -1, -1, -1, -1, sha1nodeconstants.nullid)
245 want = (0, 0, 0, -1, -1, -1, -1, sha1nodeconstants.nullid, 0, 0)
244 index, junk = parsers.parse_index2(data_inlined, True)
246 index, junk = parsers.parse_index2(data_inlined, True)
245 got = index[-1]
247 got = index[-1]
246 self.assertEqual(want, got) # inline data
248 self.assertEqual(want, got) # inline data
General Comments 0
You need to be logged in to leave comments. Login now