mercurial/revlog.py
changeset 4987 8d30004ada40
parent 4986 58cc017ec7e0
child 4988 14486eea8e7a
equal deleted inserted replaced
4986:58cc017ec7e0 4987:8d30004ada40
    13 from node import *
    13 from node import *
    14 from i18n import _
    14 from i18n import _
    15 import binascii, changegroup, errno, ancestor, mdiff, os
    15 import binascii, changegroup, errno, ancestor, mdiff, os
    16 import sha, struct, util, zlib
    16 import sha, struct, util, zlib
    17 
    17 
    18 # revlog version strings
    18 # revlog flags
    19 REVLOGV0 = 0
    19 REVLOGV0 = 0
    20 REVLOGNG = 1
    20 REVLOGNG = 1
    21 
       
    22 # revlog flags
       
    23 REVLOGNGINLINEDATA = (1 << 16)
    21 REVLOGNGINLINEDATA = (1 << 16)
    24 REVLOG_DEFAULT_FLAGS = REVLOGNGINLINEDATA
    22 REVLOG_DEFAULT_FLAGS = REVLOGNGINLINEDATA
    25 
       
    26 REVLOG_DEFAULT_FORMAT = REVLOGNG
    23 REVLOG_DEFAULT_FORMAT = REVLOGNG
    27 REVLOG_DEFAULT_VERSION = REVLOG_DEFAULT_FORMAT | REVLOG_DEFAULT_FLAGS
    24 REVLOG_DEFAULT_VERSION = REVLOG_DEFAULT_FORMAT | REVLOG_DEFAULT_FLAGS
       
    25 
       
    26 class RevlogError(Exception):
       
    27     pass
       
    28 class LookupError(RevlogError):
       
    29     pass
       
    30 
       
    31 def getoffset(q):
       
    32     if q & 0xFFFF:
       
    33         raise RevlogError(_('incompatible revision flag %x') % q)
       
    34     return int(q >> 16)
       
    35 
       
    36 def gettype(q):
       
    37     return int(q & 0xFFFF)
       
    38 
       
    39 def offset_type(offset, type):
       
    40     return long(long(offset) << 16 | type)
    28 
    41 
    29 def hash(text, p1, p2):
    42 def hash(text, p1, p2):
    30     """generate a hash from the given text and its parent hashes
    43     """generate a hash from the given text and its parent hashes
    31 
    44 
    32     This hash combines both the current file contents and its history
    45     This hash combines both the current file contents and its history
    65     if t == 'x':
    78     if t == 'x':
    66         return zlib.decompress(bin)
    79         return zlib.decompress(bin)
    67     if t == 'u':
    80     if t == 'u':
    68         return bin[1:]
    81         return bin[1:]
    69     raise RevlogError(_("unknown compression type %r") % t)
    82     raise RevlogError(_("unknown compression type %r") % t)
    70 
       
    71 indexformatv0 = ">4l20s20s20s"
       
    72 v0shaoffset = 56
       
    73 # index ng:
       
    74 # 6 bytes offset
       
    75 # 2 bytes flags
       
    76 # 4 bytes compressed length
       
    77 # 4 bytes uncompressed length
       
    78 # 4 bytes: base rev
       
    79 # 4 bytes link rev
       
    80 # 4 bytes parent 1 rev
       
    81 # 4 bytes parent 2 rev
       
    82 # 32 bytes: nodeid
       
    83 indexformatng = ">Qiiiiii20s12x"
       
    84 ngshaoffset = 32
       
    85 versionformat = ">I"
       
    86 
    83 
    87 class lazyparser(object):
    84 class lazyparser(object):
    88     """
    85     """
    89     this class avoids the need to parse the entirety of large indices
    86     this class avoids the need to parse the entirety of large indices
    90     """
    87     """
   287     def __setitem__(self, key, val):
   284     def __setitem__(self, key, val):
   288         self.p.map[key] = val
   285         self.p.map[key] = val
   289     def __delitem__(self, key):
   286     def __delitem__(self, key):
   290         del self.p.map[key]
   287         del self.p.map[key]
   291 
   288 
   292 class RevlogError(Exception):
   289 indexformatv0 = ">4l20s20s20s"
   293     pass
   290 v0shaoffset = 56
   294 class LookupError(RevlogError):
       
   295     pass
       
   296 
       
   297 def getoffset(q):
       
   298     if q & 0xFFFF:
       
   299         raise RevlogError(_('incompatible revision flag %x') % q)
       
   300     return int(q >> 16)
       
   301 
       
   302 def gettype(q):
       
   303     return int(q & 0xFFFF)
       
   304 
       
   305 def offset_type(offset, type):
       
   306     return long(long(offset) << 16 | type)
       
   307 
   291 
   308 class revlogoldio(object):
   292 class revlogoldio(object):
   309     def __init__(self):
   293     def __init__(self):
   310         self.size = struct.calcsize(indexformatv0)
   294         self.size = struct.calcsize(indexformatv0)
   311 
   295 
   331 
   315 
   332     def packentry(self, entry, node, version):
   316     def packentry(self, entry, node, version):
   333         e2 = (getoffset(entry[0]), entry[1], entry[3], entry[4],
   317         e2 = (getoffset(entry[0]), entry[1], entry[3], entry[4],
   334               node(entry[5]), node(entry[6]), entry[7])
   318               node(entry[5]), node(entry[6]), entry[7])
   335         return struct.pack(indexformatv0, *e2)
   319         return struct.pack(indexformatv0, *e2)
       
   320 
       
   321 # index ng:
       
   322 # 6 bytes offset
       
   323 # 2 bytes flags
       
   324 # 4 bytes compressed length
       
   325 # 4 bytes uncompressed length
       
   326 # 4 bytes: base rev
       
   327 # 4 bytes link rev
       
   328 # 4 bytes parent 1 rev
       
   329 # 4 bytes parent 2 rev
       
   330 # 32 bytes: nodeid
       
   331 indexformatng = ">Qiiiiii20s12x"
       
   332 ngshaoffset = 32
       
   333 versionformat = ">I"
   336 
   334 
   337 class revlogio(object):
   335 class revlogio(object):
   338     def __init__(self):
   336     def __init__(self):
   339         self.size = struct.calcsize(indexformatng)
   337         self.size = struct.calcsize(indexformatng)
   340 
   338 
  1251             if inst.errno != errno.ENOENT:
  1249             if inst.errno != errno.ENOENT:
  1252                 raise
  1250                 raise
  1253             di = 0
  1251             di = 0
  1254 
  1252 
  1255         return (dd, di)
  1253         return (dd, di)
  1256 
       
  1257