##// 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 1157 # scan whole input for git metadata
1158 1158 gitpatches = [('b/' + gp.path, gp) for gp
1159 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 1162 gitpatches.reverse()
1162 1163 afile = 'a/' + m.group(1)
1163 1164 bfile = 'b/' + m.group(2)
@@ -1220,6 +1221,10 b' def applydiff(ui, fp, changed, backend, '
1220 1221 eolmode=eolmode)
1221 1222
1222 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 1228 rejects = 0
1224 1229 err = 0
1225 1230 current_file = None
@@ -1239,18 +1244,19 b' def _applydiff(ui, fp, patcher, backend,'
1239 1244 current_file = None
1240 1245 afile, bfile, first_hunk, gp = values
1241 1246 if gp:
1242 changed[gp.path] = gp
1247 path = pstrip(gp.path)
1248 changed[path] = gp
1243 1249 if gp.op == 'DELETE':
1244 backend.unlink(gp.path)
1250 backend.unlink(path)
1245 1251 continue
1246 1252 if gp.op == 'RENAME':
1247 backend.unlink(gp.oldpath)
1253 backend.unlink(pstrip(gp.oldpath))
1248 1254 if gp.mode and not first_hunk:
1249 1255 if gp.op == 'ADD':
1250 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 1258 else:
1253 backend.setmode(gp.path, gp.mode[0], gp.mode[1])
1259 backend.setmode(path, gp.mode[0], gp.mode[1])
1254 1260 if not first_hunk:
1255 1261 continue
1256 1262 try:
@@ -1266,11 +1272,7 b' def _applydiff(ui, fp, patcher, backend,'
1266 1272 continue
1267 1273 elif state == 'git':
1268 1274 for gp in values:
1269 gp.path = pathstrip(gp.path, strip - 1)[1]
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)
1275 backend.copy(pstrip(gp.oldpath), pstrip(gp.path))
1274 1276 else:
1275 1277 raise util.Abort(_('unsupported parser state: %s') % state)
1276 1278
@@ -1387,25 +1389,18 b' def changedfiles(ui, repo, patchpath, st'
1387 1389 try:
1388 1390 changed = set()
1389 1391 for state, values in iterhunks(fp):
1390 if state == 'hunk':
1391 continue
1392 elif state == 'file':
1392 if state == 'file':
1393 1393 afile, bfile, first_hunk, gp = values
1394 1394 if gp:
1395 changed.add(gp.path)
1395 changed.add(pathstrip(gp.path, strip - 1)[1])
1396 1396 if gp.op == 'RENAME':
1397 changed.add(gp.oldpath)
1397 changed.add(pathstrip(gp.oldpath, strip - 1)[1])
1398 1398 if not first_hunk:
1399 1399 continue
1400 1400 current_file, missing = selectfile(backend, afile, bfile,
1401 1401 first_hunk, strip)
1402 1402 changed.add(current_file)
1403 elif state == '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:
1403 elif state not in ('hunk', 'git'):
1409 1404 raise util.Abort(_('unsupported parser state: %s') % state)
1410 1405 return changed
1411 1406 finally:
General Comments 0
You need to be logged in to leave comments. Login now