Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 24246:394a91cb3d4a
patch._applydiff: accept a prefix parameter
This is preparation for upcoming patches that will add support for applying a
patch within a subdirectory.
We normalize the prefix here because this is the main driver -- all code to
apply patches is expected to go through here.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Fri, 06 Mar 2015 22:22:14 -0800 |
parents | 740a17f885a1 |
children | 6e19516094a3 |
comparison
equal
deleted
inserted
replaced
24245:740a17f885a1 | 24246:394a91cb3d4a |
---|---|
1364 patching then normalized according to 'eolmode'. | 1364 patching then normalized according to 'eolmode'. |
1365 """ | 1365 """ |
1366 return _applydiff(ui, fp, patchfile, backend, store, strip=strip, | 1366 return _applydiff(ui, fp, patchfile, backend, store, strip=strip, |
1367 eolmode=eolmode) | 1367 eolmode=eolmode) |
1368 | 1368 |
1369 def _applydiff(ui, fp, patcher, backend, store, strip=1, | 1369 def _applydiff(ui, fp, patcher, backend, store, strip=1, prefix='', |
1370 eolmode='strict'): | 1370 eolmode='strict'): |
1371 | 1371 |
1372 if prefix: | |
1373 # clean up double slashes, lack of trailing slashes, etc | |
1374 prefix = util.normpath(prefix) + '/' | |
1372 def pstrip(p): | 1375 def pstrip(p): |
1373 return pathtransform(p, strip - 1, '')[1] | 1376 return pathtransform(p, strip - 1, prefix)[1] |
1374 | 1377 |
1375 rejects = 0 | 1378 rejects = 0 |
1376 err = 0 | 1379 err = 0 |
1377 current_file = None | 1380 current_file = None |
1378 | 1381 |
1391 if gp: | 1394 if gp: |
1392 gp.path = pstrip(gp.path) | 1395 gp.path = pstrip(gp.path) |
1393 if gp.oldpath: | 1396 if gp.oldpath: |
1394 gp.oldpath = pstrip(gp.oldpath) | 1397 gp.oldpath = pstrip(gp.oldpath) |
1395 else: | 1398 else: |
1396 gp = makepatchmeta(backend, afile, bfile, first_hunk, strip, '') | 1399 gp = makepatchmeta(backend, afile, bfile, first_hunk, strip, |
1400 prefix) | |
1397 if gp.op == 'RENAME': | 1401 if gp.op == 'RENAME': |
1398 backend.unlink(gp.oldpath) | 1402 backend.unlink(gp.oldpath) |
1399 if not first_hunk: | 1403 if not first_hunk: |
1400 if gp.op == 'DELETE': | 1404 if gp.op == 'DELETE': |
1401 backend.unlink(gp.path) | 1405 backend.unlink(gp.path) |