mercurial/revlog.py
changeset 47253 b876f0bf7366
parent 47252 e340b556a13e
child 47254 eac3591abbf4
equal deleted inserted replaced
47252:e340b556a13e 47253:b876f0bf7366
    34 from .i18n import _
    34 from .i18n import _
    35 from .pycompat import getattr
    35 from .pycompat import getattr
    36 from .revlogutils.constants import (
    36 from .revlogutils.constants import (
    37     ALL_KINDS,
    37     ALL_KINDS,
    38     COMP_MODE_INLINE,
    38     COMP_MODE_INLINE,
       
    39     COMP_MODE_PLAIN,
    39     FEATURES_BY_VERSION,
    40     FEATURES_BY_VERSION,
    40     FLAG_GENERALDELTA,
    41     FLAG_GENERALDELTA,
    41     FLAG_INLINE_DATA,
    42     FLAG_INLINE_DATA,
    42     INDEX_HEADER,
    43     INDEX_HEADER,
    43     REVLOGV0,
    44     REVLOGV0,
  1755         to be used for reading. If used, the seek position of the file will not
  1756         to be used for reading. If used, the seek position of the file will not
  1756         be preserved.
  1757         be preserved.
  1757 
  1758 
  1758         Returns a str holding uncompressed data for the requested revision.
  1759         Returns a str holding uncompressed data for the requested revision.
  1759         """
  1760         """
  1760         return self.decompress(self._getsegmentforrevs(rev, rev, df=df)[1])
  1761         compression_mode = self.index[rev][10]
       
  1762         data = self._getsegmentforrevs(rev, rev, df=df)[1]
       
  1763         if compression_mode == COMP_MODE_PLAIN:
       
  1764             return data
       
  1765         elif compression_mode == COMP_MODE_INLINE:
       
  1766             return self.decompress(data)
       
  1767         else:
       
  1768             msg = 'unknown compression mode %d'
       
  1769             msg %= compression_mode
       
  1770             raise error.RevlogError(msg)
  1761 
  1771 
  1762     def _chunks(self, revs, df=None, targetsize=None):
  1772     def _chunks(self, revs, df=None, targetsize=None):
  1763         """Obtain decompressed chunks for the specified revisions.
  1773         """Obtain decompressed chunks for the specified revisions.
  1764 
  1774 
  1765         Accepts an iterable of numeric revisions that are assumed to be in
  1775         Accepts an iterable of numeric revisions that are assumed to be in
  1808             for rev in revschunk:
  1818             for rev in revschunk:
  1809                 chunkstart = start(rev)
  1819                 chunkstart = start(rev)
  1810                 if inline:
  1820                 if inline:
  1811                     chunkstart += (rev + 1) * iosize
  1821                     chunkstart += (rev + 1) * iosize
  1812                 chunklength = length(rev)
  1822                 chunklength = length(rev)
       
  1823                 comp_mode = self.index[rev][10]
  1813                 c = buffer(data, chunkstart - offset, chunklength)
  1824                 c = buffer(data, chunkstart - offset, chunklength)
  1814                 ladd(decomp(c))
  1825                 if comp_mode == COMP_MODE_PLAIN:
       
  1826                     ladd(c)
       
  1827                 elif comp_mode == COMP_MODE_INLINE:
       
  1828                     ladd(decomp(c))
       
  1829                 else:
       
  1830                     msg = 'unknown compression mode %d'
       
  1831                     msg %= comp_mode
       
  1832                     raise error.RevlogError(msg)
  1815 
  1833 
  1816         return l
  1834         return l
  1817 
  1835 
  1818     def _chunkclear(self):
  1836     def _chunkclear(self):
  1819         """Clear the raw chunk cache."""
  1837         """Clear the raw chunk cache."""
  2459 
  2477 
  2460         revinfo = _revisioninfo(node, p1, p2, btext, textlen, cachedelta, flags)
  2478         revinfo = _revisioninfo(node, p1, p2, btext, textlen, cachedelta, flags)
  2461 
  2479 
  2462         deltainfo = deltacomputer.finddeltainfo(revinfo, fh)
  2480         deltainfo = deltacomputer.finddeltainfo(revinfo, fh)
  2463 
  2481 
       
  2482         compression_mode = COMP_MODE_INLINE
       
  2483         if self._docket is not None:
       
  2484             h, d = deltainfo.data
       
  2485             if not h and not d:
       
  2486                 # not data to store at all... declare them uncompressed
       
  2487                 compression_mode = COMP_MODE_PLAIN
       
  2488             elif not h and d[0:1] == b'\0':
       
  2489                 compression_mode = COMP_MODE_PLAIN
       
  2490             elif h == b'u':
       
  2491                 # we have a more efficient way to declare uncompressed
       
  2492                 h = b''
       
  2493                 compression_mode = COMP_MODE_PLAIN
       
  2494                 deltainfo = deltautil.drop_u_compression(deltainfo)
       
  2495 
  2464         if sidedata and self.hassidedata:
  2496         if sidedata and self.hassidedata:
  2465             serialized_sidedata = sidedatautil.serialize_sidedata(sidedata)
  2497             serialized_sidedata = sidedatautil.serialize_sidedata(sidedata)
  2466             sidedata_offset = offset + deltainfo.deltalen
  2498             sidedata_offset = offset + deltainfo.deltalen
  2467         else:
  2499         else:
  2468             serialized_sidedata = b""
  2500             serialized_sidedata = b""
  2480             p1r,
  2512             p1r,
  2481             p2r,
  2513             p2r,
  2482             node,
  2514             node,
  2483             sidedata_offset,
  2515             sidedata_offset,
  2484             len(serialized_sidedata),
  2516             len(serialized_sidedata),
  2485             COMP_MODE_INLINE,
  2517             compression_mode,
  2486         )
  2518         )
  2487 
  2519 
  2488         self.index.append(e)
  2520         self.index.append(e)
  2489         entry = self.index.entry_binary(curr)
  2521         entry = self.index.entry_binary(curr)
  2490         if curr == 0 and self._docket is None:
  2522         if curr == 0 and self._docket is None: