##// END OF EJS Templates
revlog: raise offset/type helpers to global scope
Matt Mackall -
r4918:e017d3a8 default
parent child Browse files
Show More
@@ -61,7 +61,7 b' class bundlerevlog(revlog.revlog):'
61 if self.version == revlog.REVLOGV0:
61 if self.version == revlog.REVLOGV0:
62 e = (start, size, None, link, p1, p2, node)
62 e = (start, size, None, link, p1, p2, node)
63 else:
63 else:
64 e = (self.offset_type(start, 0), size, -1, None, link,
64 e = (revlog.offset_type(start, 0), size, -1, None, link,
65 self.rev(p1), self.rev(p2), node)
65 self.rev(p1), self.rev(p2), node)
66 self.basemap[n] = prev
66 self.basemap[n] = prev
67 self.index.append(e)
67 self.index.append(e)
@@ -281,6 +281,17 b' class lazymap(object):'
281 class RevlogError(Exception): pass
281 class RevlogError(Exception): pass
282 class LookupError(RevlogError): pass
282 class LookupError(RevlogError): pass
283
283
284 def getoffset(q):
285 if q & 0xFFFF:
286 raise RevlogError(_('incompatible revision flag %x') % q)
287 return int(q >> 16)
288
289 def gettype(q):
290 return int(q & 0xFFFF)
291
292 def offset_type(offset, type):
293 return long(long(offset) << 16 | type)
294
284 class revlog(object):
295 class revlog(object):
285 """
296 """
286 the underlying revision storage object
297 the underlying revision storage object
@@ -333,6 +344,8 b' class revlog(object):'
333 f = self.opener(self.indexfile)
344 f = self.opener(self.indexfile)
334 i = f.read(4)
345 i = f.read(4)
335 f.seek(0)
346 f.seek(0)
347 if len(i) > 0:
348 v = struct.unpack(versionformat, i)[0]
336 except IOError, inst:
349 except IOError, inst:
337 if inst.errno != errno.ENOENT:
350 if inst.errno != errno.ENOENT:
338 raise
351 raise
@@ -351,8 +364,6 b' class revlog(object):'
351 and st.st_size == oldst.st_size):
364 and st.st_size == oldst.st_size):
352 return
365 return
353 self.indexstat = st
366 self.indexstat = st
354 if len(i) > 0:
355 v = struct.unpack(versionformat, i)[0]
356 flags = v & ~0xFFFF
367 flags = v & ~0xFFFF
357 fmt = v & 0xFFFF
368 fmt = v & 0xFFFF
358 if fmt == REVLOGV0:
369 if fmt == REVLOGV0:
@@ -385,8 +396,8 b' class revlog(object):'
385 self.parseindex(f, st)
396 self.parseindex(f, st)
386 if self.version != REVLOGV0:
397 if self.version != REVLOGV0:
387 e = list(self.index[0])
398 e = list(self.index[0])
388 type = self.ngtype(e[0])
399 type = gettype(e[0])
389 e[0] = self.offset_type(0, type)
400 e[0] = offset_type(0, type)
390 self.index[0] = e
401 self.index[0] = e
391 else:
402 else:
392 self.nodemap = {nullid: nullrev}
403 self.nodemap = {nullid: nullrev}
@@ -438,18 +449,6 b' class revlog(object):'
438 break
449 break
439
450
440
451
441 def ngoffset(self, q):
442 if q & 0xFFFF:
443 raise RevlogError(_('%s: incompatible revision flag %x') %
444 (self.indexfile, q))
445 return long(q >> 16)
446
447 def ngtype(self, q):
448 return int(q & 0xFFFF)
449
450 def offset_type(self, offset, type):
451 return long(long(offset) << 16 | type)
452
453 def loadindex(self, start, end):
452 def loadindex(self, start, end):
454 """load a block of indexes all at once from the lazy parser"""
453 """load a block of indexes all at once from the lazy parser"""
455 if isinstance(self.index, lazyindex):
454 if isinstance(self.index, lazyindex):
@@ -498,7 +497,7 b' class revlog(object):'
498 if rev == nullrev:
497 if rev == nullrev:
499 return 0
498 return 0
500 if self.version != REVLOGV0:
499 if self.version != REVLOGV0:
501 return self.ngoffset(self.index[rev][0])
500 return getoffset(self.index[rev][0])
502 return self.index[rev][0]
501 return self.index[rev][0]
503
502
504 def end(self, rev): return self.start(rev) + self.length(rev)
503 def end(self, rev): return self.start(rev) + self.length(rev)
@@ -1042,7 +1041,7 b' class revlog(object):'
1042 if self.version == REVLOGV0:
1041 if self.version == REVLOGV0:
1043 e = (offset, l, base, link, p1, p2, node)
1042 e = (offset, l, base, link, p1, p2, node)
1044 else:
1043 else:
1045 e = (self.offset_type(offset, 0), l, len(text),
1044 e = (offset_type(offset, 0), l, len(text),
1046 base, link, self.rev(p1), self.rev(p2), node)
1045 base, link, self.rev(p1), self.rev(p2), node)
1047
1046
1048 self.index.append(e)
1047 self.index.append(e)
@@ -1205,7 +1204,7 b' class revlog(object):'
1205 if self.version == REVLOGV0:
1204 if self.version == REVLOGV0:
1206 e = (end, len(cdelta), base, link, p1, p2, node)
1205 e = (end, len(cdelta), base, link, p1, p2, node)
1207 else:
1206 else:
1208 e = (self.offset_type(end, 0), len(cdelta), textlen, base,
1207 e = (offset_type(end, 0), len(cdelta), textlen, base,
1209 link, self.rev(p1), self.rev(p2), node)
1208 link, self.rev(p1), self.rev(p2), node)
1210 self.index.append(e)
1209 self.index.append(e)
1211 self.nodemap[node] = r
1210 self.nodemap[node] = r
General Comments 0
You need to be logged in to leave comments. Login now