##// END OF EJS Templates
revlog: introduce a plain compression mode...
marmoute -
r48027:b876f0bf default
parent child Browse files
Show More
@@ -36,6 +36,7 b' from .pycompat import getattr'
36 36 from .revlogutils.constants import (
37 37 ALL_KINDS,
38 38 COMP_MODE_INLINE,
39 COMP_MODE_PLAIN,
39 40 FEATURES_BY_VERSION,
40 41 FLAG_GENERALDELTA,
41 42 FLAG_INLINE_DATA,
@@ -1757,7 +1758,16 b' class revlog(object):'
1757 1758
1758 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 1772 def _chunks(self, revs, df=None, targetsize=None):
1763 1773 """Obtain decompressed chunks for the specified revisions.
@@ -1810,8 +1820,16 b' class revlog(object):'
1810 1820 if inline:
1811 1821 chunkstart += (rev + 1) * iosize
1812 1822 chunklength = length(rev)
1823 comp_mode = self.index[rev][10]
1813 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 1834 return l
1817 1835
@@ -2461,6 +2479,20 b' class revlog(object):'
2461 2479
2462 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 2496 if sidedata and self.hassidedata:
2465 2497 serialized_sidedata = sidedatautil.serialize_sidedata(sidedata)
2466 2498 sidedata_offset = offset + deltainfo.deltalen
@@ -2482,7 +2514,7 b' class revlog(object):'
2482 2514 node,
2483 2515 sidedata_offset,
2484 2516 len(serialized_sidedata),
2485 COMP_MODE_INLINE,
2517 compression_mode,
2486 2518 )
2487 2519
2488 2520 self.index.append(e)
@@ -119,6 +119,10 b' REVIDX_RAWTEXT_CHANGING_FLAGS = REVIDX_I'
119 119 # These constants are used in revlog version >=2 to denote the compression used
120 120 # for a chunk.
121 121
122 # Chunk use no compression, the data stored on disk can be directly use as
123 # chunk value. Without any header information prefixed.
124 COMP_MODE_PLAIN = 0
125
122 126 # Chunk use a compression mode stored "inline" at the start of the chunk
123 127 # itself. This is the mode always used for revlog version "0" and "1"
124 128 COMP_MODE_INLINE = 2
@@ -553,6 +553,24 b' class _deltainfo(object):'
553 553 snapshotdepth = attr.ib()
554 554
555 555
556 def drop_u_compression(delta):
557 """turn into a "u" (no-compression) into no-compression without header
558
559 This is useful for revlog format that has better compression method.
560 """
561 assert delta.data[0] == b'u', delta.data[0]
562 return _deltainfo(
563 delta.distance,
564 delta.deltalen - 1,
565 (b'', delta.data[1]),
566 delta.base,
567 delta.chainbase,
568 delta.chainlen,
569 delta.compresseddeltalen,
570 delta.snapshotdepth,
571 )
572
573
556 574 def isgooddeltainfo(revlog, deltainfo, revinfo):
557 575 """Returns True if the given delta is good. Good means that it is within
558 576 the disk span, disk size, and chain length bounds that we know to be
General Comments 0
You need to be logged in to leave comments. Login now