##// END OF EJS Templates
patch: refactor iterhunks() regular and binary files emission
Patrick Mezard -
r14383:1bd52cb1 default
parent child Browse files
Show More
@@ -1129,28 +1129,26 b' def iterhunks(fp):'
1129 x = lr.readline()
1129 x = lr.readline()
1130 if not x:
1130 if not x:
1131 break
1131 break
1132 if (state == BFILE and ((not context and x[0] == '@') or
1132 if state == BFILE and (
1133 ((context is not False) and x.startswith('***************')))):
1133 (not context and x[0] == '@')
1134 if context is None and x.startswith('***************'):
1134 or (context is not False and x.startswith('***************'))
1135 context = True
1135 or x.startswith('GIT binary patch')):
1136 gpatch = changed.get(bfile)
1136 gp = changed.get(bfile)
1137 create = afile == '/dev/null' or gpatch and gpatch.op == 'ADD'
1137 if x.startswith('GIT binary patch'):
1138 remove = bfile == '/dev/null' or gpatch and gpatch.op == 'DELETE'
1138 h = binhunk(gp)
1139 h = hunk(x, hunknum + 1, lr, context, create, remove)
1139 h.extract(lr)
1140 afile = 'a/' + afile
1141 bfile = 'b/' + bfile
1142 else:
1143 if context is None and x.startswith('***************'):
1144 context = True
1145 create = afile == '/dev/null' or gp and gp.op == 'ADD'
1146 remove = bfile == '/dev/null' or gp and gp.op == 'DELETE'
1147 h = hunk(x, hunknum + 1, lr, context, create, remove)
1140 hunknum += 1
1148 hunknum += 1
1141 if emitfile:
1149 if emitfile:
1142 emitfile = False
1150 emitfile = False
1143 yield 'file', (afile, bfile, h, gpatch and gpatch.mode or None)
1151 yield 'file', (afile, bfile, h, gp and gp.mode or None)
1144 yield 'hunk', h
1145 elif state == BFILE and x.startswith('GIT binary patch'):
1146 gpatch = changed[bfile]
1147 h = binhunk(gpatch)
1148 hunknum += 1
1149 if emitfile:
1150 emitfile = False
1151 yield 'file', ('a/' + afile, 'b/' + bfile, h,
1152 gpatch and gpatch.mode or None)
1153 h.extract(lr)
1154 yield 'hunk', h
1152 yield 'hunk', h
1155 elif x.startswith('diff --git'):
1153 elif x.startswith('diff --git'):
1156 # check for git diff, scanning the whole patch file if needed
1154 # check for git diff, scanning the whole patch file if needed
General Comments 0
You need to be logged in to leave comments. Login now