# HG changeset patch # User Mads Kiilerich # Date 1384705119 18000 # Node ID da99ebd35f0018aa580225e88d3ef8cd0c4e585e # Parent 10a7d2bcb81bd5a9cb33b8e75fa8d045b2acf316 convert: readability and test of rpairs function diff -r 10a7d2bcb81b -r da99ebd35f00 hgext/convert/filemap.py --- 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. diff -r 10a7d2bcb81b -r da99ebd35f00 tests/test-doctest.py --- 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')