mercurial/revlog.py
changeset 47259 07641bafa646
parent 47258 c4dbb7636a12
child 47261 80164d50ae3d
--- a/mercurial/revlog.py	Mon May 03 23:14:48 2021 +0200
+++ b/mercurial/revlog.py	Mon May 03 23:40:05 2021 +0200
@@ -3381,6 +3381,26 @@
                 serialized_sidedata = sidedatautil.serialize_sidedata(
                     new_sidedata
                 )
+
+                sidedata_compression_mode = COMP_MODE_INLINE
+                if serialized_sidedata and self.hassidedata:
+                    sidedata_compression_mode = COMP_MODE_PLAIN
+                    h, comp_sidedata = self.compress(serialized_sidedata)
+                    if (
+                        h != b'u'
+                        and comp_sidedata[0] != b'\0'
+                        and len(comp_sidedata) < len(serialized_sidedata)
+                    ):
+                        assert not h
+                        if (
+                            comp_sidedata[0]
+                            == self._docket.default_compression_header
+                        ):
+                            sidedata_compression_mode = COMP_MODE_DEFAULT
+                            serialized_sidedata = comp_sidedata
+                        else:
+                            sidedata_compression_mode = COMP_MODE_INLINE
+                            serialized_sidedata = comp_sidedata
                 if entry[8] != 0 or entry[9] != 0:
                     # rewriting entries that already have sidedata is not
                     # supported yet, because it introduces garbage data in the
@@ -3395,6 +3415,7 @@
                     current_offset,
                     len(serialized_sidedata),
                     new_offset_flags,
+                    sidedata_compression_mode,
                 )
 
                 # the sidedata computation might have move the file cursors around