# Patchwork [3,of,8] convert: readability and test of rpairs function

Submitter Mads Kiilerich Nov. 17, 2013, 4:28 p.m. <4a71266b173ea8d73f62.1384705739@localhost.localdomain> mbox | patch /patch/3011/ Accepted da99ebd35f0018aa580225e88d3ef8cd0c4e585e show

Mads Kiilerich - Nov. 17, 2013, 4:28 p.m.
```# HG changeset patch
# Date 1384705119 18000
#      Sun Nov 17 11:18:39 2013 -0500
# Branch stable
# Node ID 4a71266b173ea8d73f62f107dfde0cc3d554c4af
convert: readability and test of rpairs function
```

## Patch

```diff --git a/hgext/convert/filemap.py b/hgext/convert/filemap.py
--- a/hgext/convert/filemap.py
+++ b/hgext/convert/filemap.py
@@ -10,12 +10,20 @@  from mercurial.i18n import _
from mercurial import util, error
from common import SKIPREV, converter_source

-def rpairs(name):
-    e = len(name)
-    while e != -1:
-        yield name[:e], name[e + 1:]
-        e = name.rfind('/', 0, e)
-    yield '.', name
+def rpairs(path):
+    '''Yield tuples with path split at '/', starting with the full path.
+    No leading, trailing or double '/', please.
+    >>> for x in rpairs('foo/bar/baz'): print x
+    ('foo/bar/baz', '')
+    ('foo/bar', 'baz')
+    ('foo', 'bar/baz')
+    ('.', 'foo/bar/baz')
+    '''
+    i = len(path)
+    while i != -1:
+        yield path[:i], path[i + 1:]
+        i = path.rfind('/', 0, i)
+    yield '.', path

def normalize(path):
''' We use posixpath.normpath to support cross-platform path format.
diff --git a/tests/test-doctest.py b/tests/test-doctest.py
--- a/tests/test-doctest.py
+++ b/tests/test-doctest.py
@@ -26,3 +26,4 @@  testmod('mercurial.url')
testmod('mercurial.util')
testmod('mercurial.util', testtarget='platform')
testmod('hgext.convert.cvsps')
+testmod('hgext.convert.filemap')

```