comparison mercurial/patch.py @ 34252:c43d055ae405

py3: stop using bytes[n] in patch.py
author Yuya Nishihara <yuya@tcha.org>
date Sun, 17 Sep 2017 12:20:35 +0900
parents 61714510220d
children 5ce32fe7df34
comparison
equal deleted inserted replaced
34251:61714510220d 34252:c43d055ae405
958 self.fromline, 958 self.fromline,
959 self.proc)) 959 self.proc))
960 960
961 def countchanges(self, hunk): 961 def countchanges(self, hunk):
962 """hunk -> (n+,n-)""" 962 """hunk -> (n+,n-)"""
963 add = len([h for h in hunk if h[0] == '+']) 963 add = len([h for h in hunk if h.startswith('+')])
964 rem = len([h for h in hunk if h[0] == '-']) 964 rem = len([h for h in hunk if h.startswith('-')])
965 return add, rem 965 return add, rem
966 966
967 def reversehunk(self): 967 def reversehunk(self):
968 """return another recordhunk which is the reverse of the hunk 968 """return another recordhunk which is the reverse of the hunk
969 969
970 If this hunk is diff(A, B), the returned hunk is diff(B, A). To do 970 If this hunk is diff(A, B), the returned hunk is diff(B, A). To do
971 that, swap fromline/toline and +/- signs while keep other things 971 that, swap fromline/toline and +/- signs while keep other things
972 unchanged. 972 unchanged.
973 """ 973 """
974 m = {'+': '-', '-': '+', '\\': '\\'} 974 m = {'+': '-', '-': '+', '\\': '\\'}
975 hunk = ['%s%s' % (m[l[0]], l[1:]) for l in self.hunk] 975 hunk = ['%s%s' % (m[l[0:1]], l[1:]) for l in self.hunk]
976 return recordhunk(self.header, self.toline, self.fromline, self.proc, 976 return recordhunk(self.header, self.toline, self.fromline, self.proc,
977 self.before, hunk, self.after) 977 self.before, hunk, self.after)
978 978
979 def write(self, fp): 979 def write(self, fp):
980 delta = len(self.before) + len(self.after) 980 delta = len(self.before) + len(self.after)