changeset 43633: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 2e017696181f
children 43f57b9620d2
files mercurial/context.py mercurial/debugcommands.py mercurial/dirstate.py mercurial/hgweb/hgwebdir_mod.py mercurial/match.py mercurial/merge.py mercurial/pathutil.py mercurial/scmutil.py mercurial/util.py rust/hg-core/src/utils/files.rs
diffstat 10 files changed, 35 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Wed Nov 13 21:52:25 2019 -0500
+++ b/mercurial/context.py	Thu Nov 14 08:03:26 2019 -0800
@@ -2080,7 +2080,7 @@
             # warned and backed up
             if wvfs.isdir(f) and not wvfs.islink(f):
                 wvfs.rmtree(f, forcibly=True)
-            for p in reversed(list(util.finddirs(f))):
+            for p in reversed(list(pathutil.finddirs(f))):
                 if wvfs.isfileorlink(p):
                     wvfs.unlink(p)
                     break
--- a/mercurial/debugcommands.py	Wed Nov 13 21:52:25 2019 -0500
+++ b/mercurial/debugcommands.py	Thu Nov 14 08:03:26 2019 -0800
@@ -59,6 +59,7 @@
     merge as mergemod,
     obsolete,
     obsutil,
+    pathutil,
     phases,
     policy,
     pvec,
@@ -1343,7 +1344,7 @@
                     ignored = nf
                     ignoredata = repo.dirstate._ignorefileandline(nf)
                 else:
-                    for p in util.finddirs(nf):
+                    for p in pathutil.finddirs(nf):
                         if ignore(p):
                             ignored = p
                             ignoredata = repo.dirstate._ignorefileandline(p)
--- a/mercurial/dirstate.py	Wed Nov 13 21:52:25 2019 -0500
+++ b/mercurial/dirstate.py	Thu Nov 14 08:03:26 2019 -0800
@@ -404,7 +404,7 @@
                     _(b'directory %r already in dirstate') % pycompat.bytestr(f)
                 )
             # shadows
-            for d in util.finddirs(f):
+            for d in pathutil.finddirs(f):
                 if self._map.hastrackeddir(d):
                     break
                 entry = self._map.get(d)
@@ -707,7 +707,7 @@
     def _dirignore(self, f):
         if self._ignore(f):
             return True
-        for p in util.finddirs(f):
+        for p in pathutil.finddirs(f):
             if self._ignore(p):
                 return True
         return False
--- a/mercurial/hgweb/hgwebdir_mod.py	Wed Nov 13 21:52:25 2019 -0500
+++ b/mercurial/hgweb/hgwebdir_mod.py	Thu Nov 14 08:03:26 2019 -0800
@@ -32,6 +32,7 @@
     error,
     extensions,
     hg,
+    pathutil,
     profiling,
     pycompat,
     registrar,
@@ -436,7 +437,7 @@
             def _virtualdirs():
                 # Check the full virtual path, and each parent
                 yield virtual
-                for p in util.finddirs(virtual):
+                for p in pathutil.finddirs(virtual):
                     yield p
 
             for virtualrepo in _virtualdirs():
--- a/mercurial/match.py	Wed Nov 13 21:52:25 2019 -0500
+++ b/mercurial/match.py	Thu Nov 14 08:03:26 2019 -0800
@@ -18,7 +18,6 @@
     encoding,
     error,
     pathutil,
-    pathutil,
     policy,
     pycompat,
     util,
@@ -598,7 +597,8 @@
             dir in self._fileset
             or dir in self._dirs
             or any(
-                parentdir in self._fileset for parentdir in util.finddirs(dir)
+                parentdir in self._fileset
+                for parentdir in pathutil.finddirs(dir)
             )
         )
 
@@ -643,7 +643,7 @@
     @staticmethod
     def _findsplitdirs(path):
         # yields (dirname, basename) tuples, walking back to the root.  This is
-        # very similar to util.finddirs, except:
+        # very similar to pathutil.finddirs, except:
         #  - produces a (dirname, basename) tuple, not just 'dirname'
         # Unlike manifest._splittopdir, this does not suffix `dirname` with a
         # slash.
@@ -681,7 +681,9 @@
             dir in self._roots
             or dir in self._dirs
             or dir in self._parents
-            or any(parentdir in self._roots for parentdir in util.finddirs(dir))
+            or any(
+                parentdir in self._roots for parentdir in pathutil.finddirs(dir)
+            )
         )
 
     @propertycache
@@ -706,7 +708,9 @@
             b'' in self._roots
             or dir in self._roots
             or dir in self._dirs
-            or any(parentdir in self._roots for parentdir in util.finddirs(dir))
+            or any(
+                parentdir in self._roots for parentdir in pathutil.finddirs(dir)
+            )
         ):
             return b'this'
 
@@ -1073,7 +1077,7 @@
 
     @propertycache
     def _pathdirs(self):
-        return set(util.finddirs(self._path))
+        return set(pathutil.finddirs(self._path))
 
     def visitdir(self, dir):
         if dir == self._path:
--- a/mercurial/merge.py	Wed Nov 13 21:52:25 2019 -0500
+++ b/mercurial/merge.py	Thu Nov 14 08:03:26 2019 -0800
@@ -32,6 +32,7 @@
     filemerge,
     match as matchmod,
     obsutil,
+    pathutil,
     pycompat,
     scmutil,
     subrepoutil,
@@ -813,7 +814,7 @@
             return False
 
         # Check for path prefixes that exist as unknown files.
-        for p in reversed(list(util.finddirs(f))):
+        for p in reversed(list(pathutil.finddirs(f))):
             if p in self._missingdircache:
                 return
             if p in self._unknowndircache:
@@ -947,7 +948,7 @@
             backup = (
                 f in fileconflicts
                 or f in pathconflicts
-                or any(p in pathconflicts for p in util.finddirs(f))
+                or any(p in pathconflicts for p in pathutil.finddirs(f))
             )
             (flags,) = args
             actions[f] = (ACTION_GET, (flags, backup), msg)
@@ -1077,7 +1078,7 @@
     in.
     """
     for f in manifest:
-        for p in util.finddirs(f):
+        for p in pathutil.finddirs(f):
             if p in dirs:
                 yield f, p
                 break
@@ -1116,7 +1117,7 @@
             ACTION_CREATED_MERGE,
         ):
             # This action may create a new local file.
-            createdfiledirs.update(util.finddirs(f))
+            createdfiledirs.update(pathutil.finddirs(f))
             if mf.hasdir(f):
                 # The file aliases a local directory.  This might be ok if all
                 # the files in the local directory are being deleted.  This
@@ -1710,7 +1711,7 @@
                 # with a directory this file is in, and if so, back that up.
                 conflicting = f
                 if not repo.wvfs.lexists(f):
-                    for p in util.finddirs(f):
+                    for p in pathutil.finddirs(f):
                         if repo.wvfs.isfileorlink(p):
                             conflicting = p
                             break
--- 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
--- a/mercurial/scmutil.py	Wed Nov 13 21:52:25 2019 -0500
+++ b/mercurial/scmutil.py	Thu Nov 14 08:03:26 2019 -0800
@@ -964,7 +964,7 @@
         ui.note(_(b'creating directory: %s\n') % origvfs.join(origbackupdir))
 
         # Remove any files that conflict with the backup file's path
-        for f in reversed(list(util.finddirs(filepath))):
+        for f in reversed(list(pathutil.finddirs(filepath))):
             if origvfs.isfileorlink(f):
                 ui.note(_(b'removing conflicting file: %s\n') % origvfs.join(f))
                 origvfs.unlink(f)
--- a/mercurial/util.py	Wed Nov 13 21:52:25 2019 -0500
+++ b/mercurial/util.py	Thu Nov 14 08:03:26 2019 -0800
@@ -3491,14 +3491,6 @@
     f.flush()
 
 
-def finddirs(path):
-    pos = path.rfind(b'/')
-    while pos != -1:
-        yield path[:pos]
-        pos = path.rfind(b'/', 0, pos)
-    yield b''
-
-
 # convenient shortcut
 dst = debugstacktrace
 
--- a/rust/hg-core/src/utils/files.rs	Wed Nov 13 21:52:25 2019 -0500
+++ b/rust/hg-core/src/utils/files.rs	Thu Nov 14 08:03:26 2019 -0800
@@ -119,7 +119,7 @@
 
     #[test]
     fn find_dirs_empty() {
-        // looks weird, but mercurial.util.finddirs(b"") yields b""
+        // looks weird, but mercurial.pathutil.finddirs(b"") yields b""
         let mut dirs = super::find_dirs(HgPath::new(b""));
         assert_eq!(dirs.next(), Some(HgPath::new(b"")));
         assert_eq!(dirs.next(), None);