mercurial/revlogutils/deltas.py
changeset 42463 a0b26fc8fbba
parent 42057 566daffc607d
child 42464 66c27df1be84
--- a/mercurial/revlogutils/deltas.py	Fri Apr 26 00:28:22 2019 +0200
+++ b/mercurial/revlogutils/deltas.py	Thu Apr 25 22:30:14 2019 +0200
@@ -679,6 +679,25 @@
             # if chain already have too much data, skip base
             if deltas_limit < chainsize:
                 continue
+            if sparse and revlog.upperboundcomp is not None:
+                maxcomp = revlog.upperboundcomp
+                basenotsnap = (p1, p2, nullrev)
+                if rev not in basenotsnap and revlog.issnapshot(rev):
+                    snapshotdepth = revlog.snapshotdepth(rev)
+                    # If text is significantly larger than the base, we can
+                    # expect the resulting delta to be proportional to the size
+                    # difference
+                    revsize = revlog.rawsize(rev)
+                    rawsizedistance = max(textlen - revsize, 0)
+                    # use an estimate of the compression upper bound.
+                    lowestrealisticdeltalen = rawsizedistance // maxcomp
+
+                    # check the absolute constraint on the delta size
+                    snapshotlimit = textlen >> snapshotdepth
+                    if snapshotlimit < lowestrealisticdeltalen:
+                        # delta lower bound is larger than accepted upper bound
+                        continue
+
             group.append(rev)
         if group:
             # XXX: in the sparse revlog case, group can become large,