##// END OF EJS Templates
patch: stop modifying gitpatch objects...
Patrick Mezard -
r14389:909ac6b9 default
parent child Browse files
Show More
@@ -1157,7 +1157,8 b' def iterhunks(fp):'
1157 # scan whole input for git metadata
1157 # scan whole input for git metadata
1158 gitpatches = [('b/' + gp.path, gp) for gp
1158 gitpatches = [('b/' + gp.path, gp) for gp
1159 in scangitpatch(lr, x)]
1159 in scangitpatch(lr, x)]
1160 yield 'git', [g[1] for g in gitpatches]
1160 yield 'git', [g[1] for g in gitpatches
1161 if g[1].op in ('COPY', 'RENAME')]
1161 gitpatches.reverse()
1162 gitpatches.reverse()
1162 afile = 'a/' + m.group(1)
1163 afile = 'a/' + m.group(1)
1163 bfile = 'b/' + m.group(2)
1164 bfile = 'b/' + m.group(2)
@@ -1220,6 +1221,10 b' def applydiff(ui, fp, changed, backend, '
1220 eolmode=eolmode)
1221 eolmode=eolmode)
1221
1222
1222 def _applydiff(ui, fp, patcher, backend, changed, strip=1, eolmode='strict'):
1223 def _applydiff(ui, fp, patcher, backend, changed, strip=1, eolmode='strict'):
1224
1225 def pstrip(p):
1226 return pathstrip(p, strip - 1)[1]
1227
1223 rejects = 0
1228 rejects = 0
1224 err = 0
1229 err = 0
1225 current_file = None
1230 current_file = None
@@ -1239,18 +1244,19 b' def _applydiff(ui, fp, patcher, backend,'
1239 current_file = None
1244 current_file = None
1240 afile, bfile, first_hunk, gp = values
1245 afile, bfile, first_hunk, gp = values
1241 if gp:
1246 if gp:
1242 changed[gp.path] = gp
1247 path = pstrip(gp.path)
1248 changed[path] = gp
1243 if gp.op == 'DELETE':
1249 if gp.op == 'DELETE':
1244 backend.unlink(gp.path)
1250 backend.unlink(path)
1245 continue
1251 continue
1246 if gp.op == 'RENAME':
1252 if gp.op == 'RENAME':
1247 backend.unlink(gp.oldpath)
1253 backend.unlink(pstrip(gp.oldpath))
1248 if gp.mode and not first_hunk:
1254 if gp.mode and not first_hunk:
1249 if gp.op == 'ADD':
1255 if gp.op == 'ADD':
1250 # Added files without content have no hunk and must be created
1256 # Added files without content have no hunk and must be created
1251 backend.writelines(gp.path, [], gp.mode)
1257 backend.writelines(path, [], gp.mode)
1252 else:
1258 else:
1253 backend.setmode(gp.path, gp.mode[0], gp.mode[1])
1259 backend.setmode(path, gp.mode[0], gp.mode[1])
1254 if not first_hunk:
1260 if not first_hunk:
1255 continue
1261 continue
1256 try:
1262 try:
@@ -1266,11 +1272,7 b' def _applydiff(ui, fp, patcher, backend,'
1266 continue
1272 continue
1267 elif state == 'git':
1273 elif state == 'git':
1268 for gp in values:
1274 for gp in values:
1269 gp.path = pathstrip(gp.path, strip - 1)[1]
1275 backend.copy(pstrip(gp.oldpath), pstrip(gp.path))
1270 if gp.oldpath:
1271 gp.oldpath = pathstrip(gp.oldpath, strip - 1)[1]
1272 if gp.op in ('COPY', 'RENAME'):
1273 backend.copy(gp.oldpath, gp.path)
1274 else:
1276 else:
1275 raise util.Abort(_('unsupported parser state: %s') % state)
1277 raise util.Abort(_('unsupported parser state: %s') % state)
1276
1278
@@ -1387,25 +1389,18 b' def changedfiles(ui, repo, patchpath, st'
1387 try:
1389 try:
1388 changed = set()
1390 changed = set()
1389 for state, values in iterhunks(fp):
1391 for state, values in iterhunks(fp):
1390 if state == 'hunk':
1392 if state == 'file':
1391 continue
1392 elif state == 'file':
1393 afile, bfile, first_hunk, gp = values
1393 afile, bfile, first_hunk, gp = values
1394 if gp:
1394 if gp:
1395 changed.add(gp.path)
1395 changed.add(pathstrip(gp.path, strip - 1)[1])
1396 if gp.op == 'RENAME':
1396 if gp.op == 'RENAME':
1397 changed.add(gp.oldpath)
1397 changed.add(pathstrip(gp.oldpath, strip - 1)[1])
1398 if not first_hunk:
1398 if not first_hunk:
1399 continue
1399 continue
1400 current_file, missing = selectfile(backend, afile, bfile,
1400 current_file, missing = selectfile(backend, afile, bfile,
1401 first_hunk, strip)
1401 first_hunk, strip)
1402 changed.add(current_file)
1402 changed.add(current_file)
1403 elif state == 'git':
1403 elif state not in ('hunk', 'git'):
1404 for gp in values:
1405 gp.path = pathstrip(gp.path, strip - 1)[1]
1406 if gp.oldpath:
1407 gp.oldpath = pathstrip(gp.oldpath, strip - 1)[1]
1408 else:
1409 raise util.Abort(_('unsupported parser state: %s') % state)
1404 raise util.Abort(_('unsupported parser state: %s') % state)
1410 return changed
1405 return changed
1411 finally:
1406 finally:
General Comments 0
You need to be logged in to leave comments. Login now