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

login
register
mail settings
Submitter Mads Kiilerich
Date Nov. 17, 2013, 4:28 p.m.
Message ID <4a71266b173ea8d73f62.1384705739@localhost.localdomain>
Download mbox | patch
Permalink /patch/3011/
State Accepted
Commit da99ebd35f0018aa580225e88d3ef8cd0c4e585e
Headers show

Comments

Mads Kiilerich - Nov. 17, 2013, 4:28 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1384705119 18000
#      Sun Nov 17 11:18:39 2013 -0500
# Branch stable
# Node ID 4a71266b173ea8d73f62f107dfde0cc3d554c4af
# Parent  6b40daa5808bbd6676a09d4860abc2c8eead020a
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')