Patchwork [1,of,6] scmutil: migrate finddirs from dirstate

login
register
mail settings
Submitter Bryan O'Sullivan
Date April 1, 2013, 8:49 p.m.
Message ID <cd42138d63c3110cbcd0.1364849354@australite.local>
Download mbox | patch
Permalink /patch/1231/
State Accepted, archived
Headers show

Comments

Bryan O'Sullivan - April 1, 2013, 8:49 p.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@fb.com>
# Date 1364849265 25200
#      Mon Apr 01 13:47:45 2013 -0700
# Node ID cd42138d63c3110cbcd07b389f1d99920fb031ac
# Parent  5f6a483def6e04c65b8d8dfa56a7bcadd3adb756
scmutil: migrate finddirs from dirstate

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -25,21 +25,15 @@  class rootcache(filecache):
     def join(self, obj, fname):
         return obj._join(fname)
 
-def _finddirs(path):
-    pos = path.rfind('/')
-    while pos != -1:
-        yield path[:pos]
-        pos = path.rfind('/', 0, pos)
-
 def _incdirs(dirs, path):
-    for base in _finddirs(path):
+    for base in scmutil.finddirs(path):
         if base in dirs:
             dirs[base] += 1
             return
         dirs[base] = 1
 
 def _decdirs(dirs, path):
-    for base in _finddirs(path):
+    for base in scmutil.finddirs(path):
         if dirs[base] > 1:
             dirs[base] -= 1
             return
@@ -343,7 +337,7 @@  class dirstate(object):
             if f in self._dirs:
                 raise util.Abort(_('directory %r already in dirstate') % f)
             # shadows
-            for d in _finddirs(f):
+            for d in scmutil.finddirs(f):
                 if d in self._dirs:
                     break
                 if d in self._map and self[d] != 'r':
@@ -537,7 +531,7 @@  class dirstate(object):
             return False
         if self._ignore(f):
             return True
-        for p in _finddirs(f):
+        for p in scmutil.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
@@ -927,3 +927,9 @@  class filecache(object):
             del obj.__dict__[self.name]
         except KeyError:
             raise AttributeError(self.name)
+
+def finddirs(path):
+    pos = path.rfind('/')
+    while pos != -1:
+        yield path[:pos]
+        pos = path.rfind('/', 0, pos)