comparison mercurial/patch.py @ 24242:3acb83c6c0f1

patch: rename pathstrip to pathtransform In upcoming patches we'll not just strip path components but also add new ones.
author Siddharth Agarwal <sid0@fb.com>
date Fri, 06 Mar 2015 21:12:30 -0800
parents 32e8d94b9473
children daee2039dd11
comparison
equal deleted inserted replaced
24241:e7baf88c29c3 24242:3acb83c6c0f1
1085 i = s.find(' ') 1085 i = s.find(' ')
1086 if i < 0: 1086 if i < 0:
1087 return s 1087 return s
1088 return s[:i] 1088 return s[:i]
1089 1089
1090 def pathstrip(path, strip): 1090 def pathtransform(path, strip):
1091 pathlen = len(path) 1091 pathlen = len(path)
1092 i = 0 1092 i = 0
1093 if strip == 0: 1093 if strip == 0:
1094 return '', path.rstrip() 1094 return '', path.rstrip()
1095 count = strip 1095 count = strip
1108 def makepatchmeta(backend, afile_orig, bfile_orig, hunk, strip): 1108 def makepatchmeta(backend, afile_orig, bfile_orig, hunk, strip):
1109 nulla = afile_orig == "/dev/null" 1109 nulla = afile_orig == "/dev/null"
1110 nullb = bfile_orig == "/dev/null" 1110 nullb = bfile_orig == "/dev/null"
1111 create = nulla and hunk.starta == 0 and hunk.lena == 0 1111 create = nulla and hunk.starta == 0 and hunk.lena == 0
1112 remove = nullb and hunk.startb == 0 and hunk.lenb == 0 1112 remove = nullb and hunk.startb == 0 and hunk.lenb == 0
1113 abase, afile = pathstrip(afile_orig, strip) 1113 abase, afile = pathtransform(afile_orig, strip)
1114 gooda = not nulla and backend.exists(afile) 1114 gooda = not nulla and backend.exists(afile)
1115 bbase, bfile = pathstrip(bfile_orig, strip) 1115 bbase, bfile = pathtransform(bfile_orig, strip)
1116 if afile == bfile: 1116 if afile == bfile:
1117 goodb = gooda 1117 goodb = gooda
1118 else: 1118 else:
1119 goodb = not nullb and backend.exists(bfile) 1119 goodb = not nullb and backend.exists(bfile)
1120 missing = not goodb and not gooda and not create 1120 missing = not goodb and not gooda and not create
1350 1350
1351 def _applydiff(ui, fp, patcher, backend, store, strip=1, 1351 def _applydiff(ui, fp, patcher, backend, store, strip=1,
1352 eolmode='strict'): 1352 eolmode='strict'):
1353 1353
1354 def pstrip(p): 1354 def pstrip(p):
1355 return pathstrip(p, strip - 1)[1] 1355 return pathtransform(p, strip - 1)[1]
1356 1356
1357 rejects = 0 1357 rejects = 0
1358 err = 0 1358 err = 0
1359 current_file = None 1359 current_file = None
1360 1360
1539 changed = set() 1539 changed = set()
1540 for state, values in iterhunks(fp): 1540 for state, values in iterhunks(fp):
1541 if state == 'file': 1541 if state == 'file':
1542 afile, bfile, first_hunk, gp = values 1542 afile, bfile, first_hunk, gp = values
1543 if gp: 1543 if gp:
1544 gp.path = pathstrip(gp.path, strip - 1)[1] 1544 gp.path = pathtransform(gp.path, strip - 1)[1]
1545 if gp.oldpath: 1545 if gp.oldpath:
1546 gp.oldpath = pathstrip(gp.oldpath, strip - 1)[1] 1546 gp.oldpath = pathtransform(gp.oldpath, strip - 1)[1]
1547 else: 1547 else:
1548 gp = makepatchmeta(backend, afile, bfile, first_hunk, strip) 1548 gp = makepatchmeta(backend, afile, bfile, first_hunk, strip)
1549 changed.add(gp.path) 1549 changed.add(gp.path)
1550 if gp.op == 'RENAME': 1550 if gp.op == 'RENAME':
1551 changed.add(gp.oldpath) 1551 changed.add(gp.oldpath)