comparison mercurial/patch.py @ 24245:740a17f885a1

patch.makepatchmeta: accept a prefix parameter This is preparation for upcoming patches that will add support for applying a patch within a subdirectory.
author Siddharth Agarwal <sid0@fb.com>
date Fri, 06 Mar 2015 22:19:26 -0800
parents 5918bb365c72
children 394a91cb3d4a
comparison
equal deleted inserted replaced
24244:5918bb365c72 24245:740a17f885a1
1121 while i < pathlen - 1 and path[i] == '/': 1121 while i < pathlen - 1 and path[i] == '/':
1122 i += 1 1122 i += 1
1123 count -= 1 1123 count -= 1
1124 return path[:i].lstrip(), prefix + path[i:].rstrip() 1124 return path[:i].lstrip(), prefix + path[i:].rstrip()
1125 1125
1126 def makepatchmeta(backend, afile_orig, bfile_orig, hunk, strip): 1126 def makepatchmeta(backend, afile_orig, bfile_orig, hunk, strip, prefix):
1127 nulla = afile_orig == "/dev/null" 1127 nulla = afile_orig == "/dev/null"
1128 nullb = bfile_orig == "/dev/null" 1128 nullb = bfile_orig == "/dev/null"
1129 create = nulla and hunk.starta == 0 and hunk.lena == 0 1129 create = nulla and hunk.starta == 0 and hunk.lena == 0
1130 remove = nullb and hunk.startb == 0 and hunk.lenb == 0 1130 remove = nullb and hunk.startb == 0 and hunk.lenb == 0
1131 abase, afile = pathtransform(afile_orig, strip, '') 1131 abase, afile = pathtransform(afile_orig, strip, prefix)
1132 gooda = not nulla and backend.exists(afile) 1132 gooda = not nulla and backend.exists(afile)
1133 bbase, bfile = pathtransform(bfile_orig, strip, '') 1133 bbase, bfile = pathtransform(bfile_orig, strip, prefix)
1134 if afile == bfile: 1134 if afile == bfile:
1135 goodb = gooda 1135 goodb = gooda
1136 else: 1136 else:
1137 goodb = not nullb and backend.exists(bfile) 1137 goodb = not nullb and backend.exists(bfile)
1138 missing = not goodb and not gooda and not create 1138 missing = not goodb and not gooda and not create
1391 if gp: 1391 if gp:
1392 gp.path = pstrip(gp.path) 1392 gp.path = pstrip(gp.path)
1393 if gp.oldpath: 1393 if gp.oldpath:
1394 gp.oldpath = pstrip(gp.oldpath) 1394 gp.oldpath = pstrip(gp.oldpath)
1395 else: 1395 else:
1396 gp = makepatchmeta(backend, afile, bfile, first_hunk, strip) 1396 gp = makepatchmeta(backend, afile, bfile, first_hunk, strip, '')
1397 if gp.op == 'RENAME': 1397 if gp.op == 'RENAME':
1398 backend.unlink(gp.oldpath) 1398 backend.unlink(gp.oldpath)
1399 if not first_hunk: 1399 if not first_hunk:
1400 if gp.op == 'DELETE': 1400 if gp.op == 'DELETE':
1401 backend.unlink(gp.path) 1401 backend.unlink(gp.path)
1561 if gp: 1561 if gp:
1562 gp.path = pathtransform(gp.path, strip - 1, '')[1] 1562 gp.path = pathtransform(gp.path, strip - 1, '')[1]
1563 if gp.oldpath: 1563 if gp.oldpath:
1564 gp.oldpath = pathtransform(gp.oldpath, strip - 1, '')[1] 1564 gp.oldpath = pathtransform(gp.oldpath, strip - 1, '')[1]
1565 else: 1565 else:
1566 gp = makepatchmeta(backend, afile, bfile, first_hunk, strip) 1566 gp = makepatchmeta(backend, afile, bfile, first_hunk, strip,
1567 '')
1567 changed.add(gp.path) 1568 changed.add(gp.path)
1568 if gp.op == 'RENAME': 1569 if gp.op == 'RENAME':
1569 changed.add(gp.oldpath) 1570 changed.add(gp.oldpath)
1570 elif state not in ('hunk', 'git'): 1571 elif state not in ('hunk', 'git'):
1571 raise util.Abort(_('unsupported parser state: %s') % state) 1572 raise util.Abort(_('unsupported parser state: %s') % state)