Mercurial > public > mercurial-scm > hg-stable
diff mercurial/pathutil.py @ 43677:0b7733719d21
utils: move finddirs() to pathutil
This is a follow-up to c21aca51b392 (utils: move the `dirs` definition
in pathutil (API), 2019-11-06). finddirs() is closely related to dirs
and used by it.
Differential Revision: https://phab.mercurial-scm.org/D7388
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 14 Nov 2019 08:03:26 -0800 |
parents | c21aca51b392 |
children | d84420232492 |
line wrap: on
line diff
--- a/mercurial/pathutil.py Wed Nov 13 21:52:25 2019 -0500 +++ b/mercurial/pathutil.py Thu Nov 14 08:03:26 2019 -0800 @@ -275,6 +275,14 @@ return path +def finddirs(path): + pos = path.rfind(b'/') + while pos != -1: + yield path[:pos] + pos = path.rfind(b'/', 0, pos) + yield b'' + + class dirs(object): '''a multiset of directory names from a set of file paths''' @@ -295,7 +303,7 @@ def addpath(self, path): dirs = self._dirs - for base in util.finddirs(path): + for base in finddirs(path): if base.endswith(b'/'): raise ValueError( "found invalid consecutive slashes in path: %r" % base @@ -307,7 +315,7 @@ def delpath(self, path): dirs = self._dirs - for base in util.finddirs(path): + for base in finddirs(path): if dirs[base] > 1: dirs[base] -= 1 return