Patchwork [2,of,6,py3] py3: stop using bytes[n] in patch.py

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 17, 2017, 4:19 a.m.
Message ID <32586281847e0c04512b.1505621941@mimosa>
Download mbox | patch
Permalink /patch/23978/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 17, 2017, 4:19 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1505618435 -32400
#      Sun Sep 17 12:20:35 2017 +0900
# Node ID 32586281847e0c04512b3ace89315b69f0ac5b80
# Parent  2a70a351319def181dfc102f8577a1f006abf970
py3: stop using bytes[n] in patch.py

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -960,8 +960,8 @@  class recordhunk(object):
 
     def countchanges(self, hunk):
         """hunk -> (n+,n-)"""
-        add = len([h for h in hunk if h[0] == '+'])
-        rem = len([h for h in hunk if h[0] == '-'])
+        add = len([h for h in hunk if h.startswith('+')])
+        rem = len([h for h in hunk if h.startswith('-')])
         return add, rem
 
     def reversehunk(self):
@@ -972,7 +972,7 @@  class recordhunk(object):
         unchanged.
         """
         m = {'+': '-', '-': '+', '\\': '\\'}
-        hunk = ['%s%s' % (m[l[0]], l[1:]) for l in self.hunk]
+        hunk = ['%s%s' % (m[l[0:1]], l[1:]) for l in self.hunk]
         return recordhunk(self.header, self.toline, self.fromline, self.proc,
                           self.before, hunk, self.after)