diff --git a/mercurial/patch.py b/mercurial/patch.py
index 3acb83c6c0f162d9ad9965a0978bb43eca32371e_bWVyY3VyaWFsL3BhdGNoLnB5..daee2039dd1116f4399d22d5cf42286f76cbe24f_bWVyY3VyaWFsL3BhdGNoLnB5 100644
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1088,6 +1088,22 @@
     return s[:i]
 
 def pathtransform(path, strip):
+    '''turn a path from a patch into a path suitable for the repository
+
+    Returns (stripped components, path in repository).
+
+    >>> pathtransform('a/b/c', 0)
+    ('', 'a/b/c')
+    >>> pathtransform('   a/b/c   ', 0)
+    ('', '   a/b/c')
+    >>> pathtransform('   a/b/c   ', 2)
+    ('a/b/', 'c')
+    >>> pathtransform('   a//b/c   ', 2)
+    ('a//b/', 'c')
+    >>> pathtransform('a/b/c', 3)
+    Traceback (most recent call last):
+    PatchError: unable to strip away 1 of 3 dirs from a/b/c
+    '''
     pathlen = len(path)
     i = 0
     if strip == 0:
diff --git a/tests/test-doctest.py b/tests/test-doctest.py
index 3acb83c6c0f162d9ad9965a0978bb43eca32371e_dGVzdHMvdGVzdC1kb2N0ZXN0LnB5..daee2039dd1116f4399d22d5cf42286f76cbe24f_dGVzdHMvdGVzdC1kb2N0ZXN0LnB5 100644
--- a/tests/test-doctest.py
+++ b/tests/test-doctest.py
@@ -19,6 +19,7 @@
 testmod('mercurial.hgweb.hgwebdir_mod')
 testmod('mercurial.match')
 testmod('mercurial.minirst')
+testmod('mercurial.patch')
 testmod('mercurial.pathutil')
 testmod('mercurial.revset')
 testmod('mercurial.store')