Patchwork [1,of,4] revlog: move delta check to it's own function

login
register
mail settings
Submitter Durham Goode
Date Aug. 30, 2015, 10:09 p.m.
Message ID <cae419eb6fc8bf526372.1440972592@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/10328/
State Accepted
Headers show

Comments

Durham Goode - Aug. 30, 2015, 10:09 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1440966780 25200
#      Sun Aug 30 13:33:00 2015 -0700
# Node ID cae419eb6fc8bf5263727ab030c5b8e2eca0aa6d
# Parent  ab66c1dee405aca0c51b8f76eab255d805c194d7
revlog: move delta check to it's own function

This moves the delta vs fulltext comparison to its own function. This will allow
us to reuse the function in future patches for more efficient delta choices. As
a side effect, this will also allow extensions to modify our delta criteria.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1233,6 +1233,25 @@  class revlog(object):
             return ('u', text)
         return ("", bin)
 
+    def _isgooddelta(self, d, textlen):
+        """Returns True if the given delta is good. Good means that it is within
+        the disk span, disk size, and chain length bounds that we know to be
+        performant."""
+        if d is None:
+            return False
+
+        # - 'dist' is the distance from the base revision -- bounding it limits
+        #   the amount of I/O we need to do.
+        # - 'compresseddeltalen' is the sum of the total size of deltas we need
+        #   to apply -- bounding it limits the amount of CPU we consume.
+        dist, l, data, base, chainbase, chainlen, compresseddeltalen = d
+        if (dist > textlen * 4 or l > textlen or
+            compresseddeltalen > textlen * 2 or
+            (self._maxchainlen and chainlen > self._maxchainlen)):
+            return False
+
+        return True
+
     def _addrevision(self, node, text, transaction, link, p1, p2, flags,
                      cachedelta, ifh, dfh):
         """internal function to add revisions to the log
@@ -1334,13 +1353,7 @@  class revlog(object):
         else:
             textlen = len(text)
 
-        # - 'dist' is the distance from the base revision -- bounding it limits
-        #   the amount of I/O we need to do.
-        # - 'compresseddeltalen' is the sum of the total size of deltas we need
-        #   to apply -- bounding it limits the amount of CPU we consume.
-        if (d is None or dist > textlen * 4 or l > textlen or
-            compresseddeltalen > textlen * 2 or
-            (self._maxchainlen and chainlen > self._maxchainlen)):
+        if not self._isgooddelta(d, textlen):
             text = buildtext()
             data = self.compress(text)
             l = len(data[1]) + len(data[0])