Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 14392:bb5cbc16349e
patch: fast-path git case in selectfile()
We avoid a lot of complicated heuristics in git cases, where these heurestics
may even be broken when copies are involved.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Thu, 19 May 2011 22:55:13 +0200 |
parents | 1e64e1e12195 |
children | cd1ca2556cac |
comparison
equal
deleted
inserted
replaced
14391:1e64e1e12195 | 14392:bb5cbc16349e |
---|---|
1023 while i < pathlen - 1 and path[i] == '/': | 1023 while i < pathlen - 1 and path[i] == '/': |
1024 i += 1 | 1024 i += 1 |
1025 count -= 1 | 1025 count -= 1 |
1026 return path[:i].lstrip(), path[i:].rstrip() | 1026 return path[:i].lstrip(), path[i:].rstrip() |
1027 | 1027 |
1028 def selectfile(backend, afile_orig, bfile_orig, hunk, strip): | 1028 def selectfile(backend, afile_orig, bfile_orig, hunk, strip, gp): |
1029 if gp: | |
1030 # Git patches do not play games. Excluding copies from the | |
1031 # following heuristic avoids a lot of confusion | |
1032 fname = pathstrip(gp.path, strip - 1)[1] | |
1033 missing = not hunk.createfile() and not backend.exists(fname) | |
1034 return fname, missing | |
1029 nulla = afile_orig == "/dev/null" | 1035 nulla = afile_orig == "/dev/null" |
1030 nullb = bfile_orig == "/dev/null" | 1036 nullb = bfile_orig == "/dev/null" |
1031 abase, afile = pathstrip(afile_orig, strip) | 1037 abase, afile = pathstrip(afile_orig, strip) |
1032 gooda = not nulla and backend.exists(afile) | 1038 gooda = not nulla and backend.exists(afile) |
1033 bbase, bfile = pathstrip(bfile_orig, strip) | 1039 bbase, bfile = pathstrip(bfile_orig, strip) |
1253 if not first_hunk: | 1259 if not first_hunk: |
1254 continue | 1260 continue |
1255 try: | 1261 try: |
1256 mode = gp and gp.mode or None | 1262 mode = gp and gp.mode or None |
1257 current_file, missing = selectfile(backend, afile, bfile, | 1263 current_file, missing = selectfile(backend, afile, bfile, |
1258 first_hunk, strip) | 1264 first_hunk, strip, gp) |
1259 current_file = patcher(ui, current_file, backend, mode, | 1265 current_file = patcher(ui, current_file, backend, mode, |
1260 missing=missing, eolmode=eolmode) | 1266 missing=missing, eolmode=eolmode) |
1261 except PatchError, inst: | 1267 except PatchError, inst: |
1262 ui.warn(str(inst) + '\n') | 1268 ui.warn(str(inst) + '\n') |
1263 current_file = None | 1269 current_file = None |
1389 if gp.op == 'RENAME': | 1395 if gp.op == 'RENAME': |
1390 changed.add(pathstrip(gp.oldpath, strip - 1)[1]) | 1396 changed.add(pathstrip(gp.oldpath, strip - 1)[1]) |
1391 if not first_hunk: | 1397 if not first_hunk: |
1392 continue | 1398 continue |
1393 current_file, missing = selectfile(backend, afile, bfile, | 1399 current_file, missing = selectfile(backend, afile, bfile, |
1394 first_hunk, strip) | 1400 first_hunk, strip, gp) |
1395 changed.add(current_file) | 1401 changed.add(current_file) |
1396 elif state not in ('hunk', 'git'): | 1402 elif state not in ('hunk', 'git'): |
1397 raise util.Abort(_('unsupported parser state: %s') % state) | 1403 raise util.Abort(_('unsupported parser state: %s') % state) |
1398 return changed | 1404 return changed |
1399 finally: | 1405 finally: |