Patchwork [5,of,8] revlog: split and document good delta conditional

login
register
mail settings
Submitter Boris Feld
Date Aug. 14, 2018, 4:39 p.m.
Message ID <130de8bf42ff740783b9.1534264755@FB-lair>
Download mbox | patch
Permalink /patch/33724/
State Accepted
Headers show

Comments

Boris Feld - Aug. 14, 2018, 4:39 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1532088056 -7200
#      Fri Jul 20 14:00:56 2018 +0200
# Node ID 130de8bf42ff740783b99c4996c0f774e27e67cf
# Parent  84ce7b4af1682c683c4e834af92dc1c3aca581c5
# EXP-Topic sparse-snapshot
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 130de8bf42ff
revlog: split and document good delta conditional

The logic is still identical, but having each conditional on its own helps to
document them and will help to edit them in the future.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -2478,9 +2478,30 @@  class revlog(object):
             # certain size. Be also apply this tradeoff here and relax span
             # constraint for small enought content.
             maxdist = self._srmingapsize
-        if (distance > maxdist or deltainfo.deltalen > textlen or
-            deltainfo.compresseddeltalen > textlen * 2 or
-            (self._maxchainlen and deltainfo.chainlen > self._maxchainlen)):
+
+        # Bad delta from read span:
+        #
+        #   If the span of data read is larger than the maximum allowed.
+        if (maxdist < distance):
+            return False
+
+        # Bad delta from new delta size:
+        #
+        #   If the delta size is larger than the target text, storing the
+        #   delta will be inefficient.
+        if (textlen < deltainfo.deltalen):
+            return False
+
+        # Bad delta from cumulated payload size:
+        #
+        #   If the sum of delta get larger than K * target text length.
+        if (textlen * 2  < deltainfo.compresseddeltalen):
+            return False
+
+        # Bad delta from chain length:
+        #
+        #   If the number of delta in the chain gets too high.
+        if (self._maxchainlen and  self._maxchainlen < deltainfo.chainlen):
             return False
 
         return True