Patchwork [09,of,10] diffhelpers: make return value of testhunk() more Pythonic

login
register
mail settings
Submitter Yuya Nishihara
Date April 11, 2018, 3:33 p.m.
Message ID <c487b1b45eabcbe4cfd3.1523460839@mimosa>
Download mbox | patch
Permalink /patch/30703/
State Accepted
Headers show

Comments

Yuya Nishihara - April 11, 2018, 3:33 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1523275732 -32400
#      Mon Apr 09 21:08:52 2018 +0900
# Node ID c487b1b45eabcbe4cfd38a22a66e2fe6a71176b3
# Parent  6265e0c7a7ab727f253fdc915caa2339fbe65728
diffhelpers: make return value of testhunk() more Pythonic

It's no longer C.

Patch

diff --git a/mercurial/diffhelpers.py b/mercurial/diffhelpers.py
--- a/mercurial/diffhelpers.py
+++ b/mercurial/diffhelpers.py
@@ -70,8 +70,8 @@  def testhunk(a, b, bstart):
     alen = len(a)
     blen = len(b)
     if alen > blen - bstart:
-        return -1
+        return False
     for i in xrange(alen):
         if a[i][1:] != b[i + bstart]:
-            return -1
-    return 0
+            return False
+    return True
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -795,8 +795,7 @@  class patchfile(object):
         # if there's skew we want to emit the "(offset %d lines)" even
         # when the hunk cleanly applies at start + skew, so skip the
         # fast case code
-        if (self.skew == 0 and
-            diffhelpers.testhunk(old, self.lines, oldstart) == 0):
+        if self.skew == 0 and diffhelpers.testhunk(old, self.lines, oldstart):
             if self.remove:
                 self.backend.unlink(self.fname)
             else:
@@ -823,7 +822,7 @@  class patchfile(object):
                     cand = [oldstart]
 
                 for l in cand:
-                    if not old or diffhelpers.testhunk(old, self.lines, l) == 0:
+                    if not old or diffhelpers.testhunk(old, self.lines, l):
                         self.lines[l : l + len(old)] = new
                         self.offset += len(new) - len(old)
                         self.skew = l - orig_start