Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 24385:885a573fa619
patch.pathtransform: prepend prefix even if strip is 0
Silly oversight by me.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Wed, 18 Mar 2015 20:59:06 -0700 |
parents | 8a997bd73448 |
children | 72d7d390ef5d |
comparison
equal
deleted
inserted
replaced
24384:5cb459dc32d2 | 24385:885a573fa619 |
---|---|
1463 ('', 'a/b/c') | 1463 ('', 'a/b/c') |
1464 >>> pathtransform(' a/b/c ', 0, '') | 1464 >>> pathtransform(' a/b/c ', 0, '') |
1465 ('', ' a/b/c') | 1465 ('', ' a/b/c') |
1466 >>> pathtransform(' a/b/c ', 2, '') | 1466 >>> pathtransform(' a/b/c ', 2, '') |
1467 ('a/b/', 'c') | 1467 ('a/b/', 'c') |
1468 >>> pathtransform('a/b/c', 0, 'd/e/') | |
1469 ('', 'd/e/a/b/c') | |
1468 >>> pathtransform(' a//b/c ', 2, 'd/e/') | 1470 >>> pathtransform(' a//b/c ', 2, 'd/e/') |
1469 ('a//b/', 'd/e/c') | 1471 ('a//b/', 'd/e/c') |
1470 >>> pathtransform('a/b/c', 3, '') | 1472 >>> pathtransform('a/b/c', 3, '') |
1471 Traceback (most recent call last): | 1473 Traceback (most recent call last): |
1472 PatchError: unable to strip away 1 of 3 dirs from a/b/c | 1474 PatchError: unable to strip away 1 of 3 dirs from a/b/c |
1473 ''' | 1475 ''' |
1474 pathlen = len(path) | 1476 pathlen = len(path) |
1475 i = 0 | 1477 i = 0 |
1476 if strip == 0: | 1478 if strip == 0: |
1477 return '', path.rstrip() | 1479 return '', prefix + path.rstrip() |
1478 count = strip | 1480 count = strip |
1479 while count > 0: | 1481 while count > 0: |
1480 i = path.find('/', i) | 1482 i = path.find('/', i) |
1481 if i == -1: | 1483 if i == -1: |
1482 raise PatchError(_("unable to strip away %d of %d dirs from %s") % | 1484 raise PatchError(_("unable to strip away %d of %d dirs from %s") % |