Mercurial > hg
comparison mercurial/patch.py @ 34131:0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Our code transformer can't rewrite string literals in docstrings, and I
don't want to make the transformer more complex.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 03 Sep 2017 14:32:11 +0900 |
parents | 8b8b70cb4288 |
children | a8994d08e4a2 |
comparison
equal
deleted
inserted
replaced
34130:ada8a19672ab | 34131:0fa781320203 |
---|---|
1477 '''reverse the signs in the hunks given as argument | 1477 '''reverse the signs in the hunks given as argument |
1478 | 1478 |
1479 This function operates on hunks coming out of patch.filterpatch, that is | 1479 This function operates on hunks coming out of patch.filterpatch, that is |
1480 a list of the form: [header1, hunk1, hunk2, header2...]. Example usage: | 1480 a list of the form: [header1, hunk1, hunk2, header2...]. Example usage: |
1481 | 1481 |
1482 >>> rawpatch = """diff --git a/folder1/g b/folder1/g | 1482 >>> rawpatch = b"""diff --git a/folder1/g b/folder1/g |
1483 ... --- a/folder1/g | 1483 ... --- a/folder1/g |
1484 ... +++ b/folder1/g | 1484 ... +++ b/folder1/g |
1485 ... @@ -1,7 +1,7 @@ | 1485 ... @@ -1,7 +1,7 @@ |
1486 ... +firstline | 1486 ... +firstline |
1487 ... c | 1487 ... c |
1539 def parsepatch(originalchunks, maxcontext=None): | 1539 def parsepatch(originalchunks, maxcontext=None): |
1540 """patch -> [] of headers -> [] of hunks | 1540 """patch -> [] of headers -> [] of hunks |
1541 | 1541 |
1542 If maxcontext is not None, trim context lines if necessary. | 1542 If maxcontext is not None, trim context lines if necessary. |
1543 | 1543 |
1544 >>> rawpatch = '''diff --git a/folder1/g b/folder1/g | 1544 >>> rawpatch = b'''diff --git a/folder1/g b/folder1/g |
1545 ... --- a/folder1/g | 1545 ... --- a/folder1/g |
1546 ... +++ b/folder1/g | 1546 ... +++ b/folder1/g |
1547 ... @@ -1,8 +1,10 @@ | 1547 ... @@ -1,8 +1,10 @@ |
1548 ... 1 | 1548 ... 1 |
1549 ... 2 | 1549 ... 2 |
1665 | 1665 |
1666 prefix, if not empty, is expected to be normalized with a / at the end. | 1666 prefix, if not empty, is expected to be normalized with a / at the end. |
1667 | 1667 |
1668 Returns (stripped components, path in repository). | 1668 Returns (stripped components, path in repository). |
1669 | 1669 |
1670 >>> pathtransform('a/b/c', 0, '') | 1670 >>> pathtransform(b'a/b/c', 0, b'') |
1671 ('', 'a/b/c') | 1671 ('', 'a/b/c') |
1672 >>> pathtransform(' a/b/c ', 0, '') | 1672 >>> pathtransform(b' a/b/c ', 0, b'') |
1673 ('', ' a/b/c') | 1673 ('', ' a/b/c') |
1674 >>> pathtransform(' a/b/c ', 2, '') | 1674 >>> pathtransform(b' a/b/c ', 2, b'') |
1675 ('a/b/', 'c') | 1675 ('a/b/', 'c') |
1676 >>> pathtransform('a/b/c', 0, 'd/e/') | 1676 >>> pathtransform(b'a/b/c', 0, b'd/e/') |
1677 ('', 'd/e/a/b/c') | 1677 ('', 'd/e/a/b/c') |
1678 >>> pathtransform(' a//b/c ', 2, 'd/e/') | 1678 >>> pathtransform(b' a//b/c ', 2, b'd/e/') |
1679 ('a//b/', 'd/e/c') | 1679 ('a//b/', 'd/e/c') |
1680 >>> pathtransform('a/b/c', 3, '') | 1680 >>> pathtransform(b'a/b/c', 3, b'') |
1681 Traceback (most recent call last): | 1681 Traceback (most recent call last): |
1682 PatchError: unable to strip away 1 of 3 dirs from a/b/c | 1682 PatchError: unable to strip away 1 of 3 dirs from a/b/c |
1683 ''' | 1683 ''' |
1684 pathlen = len(path) | 1684 pathlen = len(path) |
1685 i = 0 | 1685 i = 0 |