changeset 20048:da99ebd35f00

convert: readability and test of rpairs function
author Mads Kiilerich <madski@unity3d.com>
date Sun, 17 Nov 2013 11:18:39 -0500
parents 10a7d2bcb81b
children 8cebb59ee4e2
files hgext/convert/filemap.py tests/test-doctest.py
diffstat 2 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/filemap.py	Sun Nov 17 11:16:59 2013 -0500
+++ b/hgext/convert/filemap.py	Sun Nov 17 11:18:39 2013 -0500
@@ -10,12 +10,20 @@
 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.
--- a/tests/test-doctest.py	Sun Nov 17 11:16:59 2013 -0500
+++ b/tests/test-doctest.py	Sun Nov 17 11:18:39 2013 -0500
@@ -26,3 +26,4 @@
 testmod('mercurial.util')
 testmod('mercurial.util', testtarget='platform')
 testmod('hgext.convert.cvsps')
+testmod('hgext.convert.filemap')