Patchwork [1,of,2] util: move finddirs implementation from scmutil to util

login
register
mail settings
Submitter Mads Kiilerich
Date Aug. 25, 2014, 1:38 a.m.
Message ID <8c8b4c31df719d1095e9.1408930695@localhost.localdomain>
Download mbox | patch
Permalink /patch/5593/
State Changes Requested
Headers show

Comments

Mads Kiilerich - Aug. 25, 2014, 1:38 a.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1408394486 -7200
#      Mon Aug 18 22:41:26 2014 +0200
# Node ID 8c8b4c31df719d1095e96efcd26be34079b074f6
# Parent  90cf454edd709c616d1e5ea4f30fb4d02f0c01a4
util: move finddirs implementation from scmutil to util
Matt Mackall - Sept. 4, 2014, 7:57 p.m.
On Mon, 2014-08-25 at 03:38 +0200, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1408394486 -7200
> #      Mon Aug 18 22:41:26 2014 +0200
> # Node ID 8c8b4c31df719d1095e96efcd26be34079b074f6
> # Parent  90cf454edd709c616d1e5ea4f30fb4d02f0c01a4
> util: move finddirs implementation from scmutil to util

Probably not a step in the right direction: eventually this will have to
move back into scmutil to be in the vfs object so it can grow an
encoding-aware variant.

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -328,7 +328,7 @@  class dirstate(object):
             if f in self._dirs:
                 raise util.Abort(_('directory %r already in dirstate') % f)
             # shadows
-            for d in scmutil.finddirs(f):
+            for d in util.finddirs(f):
                 if d in self._dirs:
                     break
                 if d in self._map and self[d] != 'r':
@@ -526,7 +526,7 @@  class dirstate(object):
             return False
         if self._ignore(f):
             return True
-        for p in scmutil.finddirs(f):
+        for p in util.finddirs(f):
             if self._ignore(p):
                 return True
         return False
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -940,7 +940,7 @@  class dirs(object):
 
     def addpath(self, path):
         dirs = self._dirs
-        for base in finddirs(path):
+        for base in util.finddirs(path):
             if base in dirs:
                 dirs[base] += 1
                 return
@@ -948,7 +948,7 @@  class dirs(object):
 
     def delpath(self, path):
         dirs = self._dirs
-        for base in finddirs(path):
+        for base in util.finddirs(path):
             if dirs[base] > 1:
                 dirs[base] -= 1
                 return
@@ -962,9 +962,3 @@  class dirs(object):
 
 if util.safehasattr(parsers, 'dirs'):
     dirs = parsers.dirs
-
-def finddirs(path):
-    pos = path.rfind('/')
-    while pos != -1:
-        yield path[:pos]
-        pos = path.rfind('/', 0, pos)
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -981,6 +981,19 @@  def ensuredirs(name, mode=None):
     if mode is not None:
         os.chmod(name, mode)
 
+def finddirs(path):
+    '''yield parent dirs of path, longest first. path must be pconvert'ed.
+
+    >>> list(finddirs('/foo/bar/baz/'))
+    ['/foo/bar/baz', '/foo/bar', '/foo', '']
+    >>> list(finddirs('foo/bar/baz'))
+    ['foo/bar', 'foo']
+    '''
+    pos = path.rfind('/')
+    while pos != -1:
+        yield path[:pos]
+        pos = path.rfind('/', 0, pos)
+
 def readfile(path):
     fp = open(path, 'rb')
     try: