[PATCH 1 of 3 STABLE] diffhelpers: backport 9e40bc4c1bde from C implementation

Yuya Nishihara yuya at tcha.org
Fri Apr 20 12:10:32 UTC 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1524148397 -32400
#      Thu Apr 19 23:33:17 2018 +0900
# Branch stable
# Node ID 171c91d2e6fb2ce686d24b34da5cc81482e0223d
# Parent  62053dbefda333714d285dbd2274067864186e19
diffhelpers: backport 9e40bc4c1bde from C implementation

9e40bc4c1bde just says "harden testhunk." I don't think this would be
the case, but it makes some sense to avoid negative index.

diff --git a/mercurial/diffhelpers.py b/mercurial/diffhelpers.py
--- a/mercurial/diffhelpers.py
+++ b/mercurial/diffhelpers.py
@@ -69,7 +69,7 @@ def testhunk(a, b, bstart):
     """
     alen = len(a)
     blen = len(b)
-    if alen > blen - bstart:
+    if alen > blen - bstart or bstart < 0:
         return False
     for i in xrange(alen):
         if a[i][1:] != b[i + bstart]:


More information about the Mercurial-devel mailing list