Show More
@@ -36,6 +36,7 b' 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, | |
@@ -1757,7 +1758,16 b' class revlog(object):' | |||||
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. | |
@@ -1810,8 +1820,16 b' class revlog(object):' | |||||
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 | |||
@@ -2461,6 +2479,20 b' class revlog(object):' | |||||
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 | |
@@ -2482,7 +2514,7 b' class revlog(object):' | |||||
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) |
@@ -119,6 +119,10 b' REVIDX_RAWTEXT_CHANGING_FLAGS = REVIDX_I' | |||||
119 | # These constants are used in revlog version >=2 to denote the compression used |
|
119 | # These constants are used in revlog version >=2 to denote the compression used | |
120 | # for a chunk. |
|
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 | # Chunk use a compression mode stored "inline" at the start of the chunk |
|
126 | # Chunk use a compression mode stored "inline" at the start of the chunk | |
123 | # itself. This is the mode always used for revlog version "0" and "1" |
|
127 | # itself. This is the mode always used for revlog version "0" and "1" | |
124 | COMP_MODE_INLINE = 2 |
|
128 | COMP_MODE_INLINE = 2 |
@@ -553,6 +553,24 b' class _deltainfo(object):' | |||||
553 | snapshotdepth = attr.ib() |
|
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 | def isgooddeltainfo(revlog, deltainfo, revinfo): |
|
574 | def isgooddeltainfo(revlog, deltainfo, revinfo): | |
557 | """Returns True if the given delta is good. Good means that it is within |
|
575 | """Returns True if the given delta is good. Good means that it is within | |
558 | the disk span, disk size, and chain length bounds that we know to be |
|
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