context: add 'dirs()' to changectx/workingctx for directory patterns stable
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Thu, 23 Feb 2012 00:07:54 +0900
branchstable
changeset 16143 fceb2964fa6c
parent 16141 f346de4dff57
child 16144 4546a8513dcd
context: add 'dirs()' to changectx/workingctx for directory patterns this patch adds 'dirs()' to changectx/workingctx, which returns map of all directories deduced from manifest, to examine whether specified pattern is related to the context as directory or not quickly. 'workingctx.dirs()' uses 'dirstate.dirs()' rather than building another copy of it.
mercurial/context.py
mercurial/dirstate.py
--- a/mercurial/context.py	Mon Feb 20 17:59:48 2012 +0100
+++ b/mercurial/context.py	Thu Feb 23 00:07:54 2012 +0900
@@ -236,6 +236,22 @@
         return patch.diff(self._repo, ctx2.node(), self.node(),
                           match=match, opts=diffopts)
 
+    @propertycache
+    def _dirs(self):
+        dirs = set()
+        for f in self._manifest:
+            pos = f.rfind('/')
+            while pos != -1:
+                f = f[:pos]
+                if f in dirs:
+                    break # dirs already contains this and above
+                dirs.add(f)
+                pos = f.rfind('/')
+        return dirs
+
+    def dirs(self):
+        return self._dirs
+
 class filectx(object):
     """A filecontext object makes access to data related to a particular
        filerevision convenient."""
@@ -953,6 +969,9 @@
             finally:
                 wlock.release()
 
+    def dirs(self):
+        return self._repo.dirstate.dirs()
+
 class workingfilectx(filectx):
     """A workingfilectx object makes access to data related to a particular
        file in the working directory convenient."""
--- a/mercurial/dirstate.py	Mon Feb 20 17:59:48 2012 +0100
+++ b/mercurial/dirstate.py	Thu Feb 23 00:07:54 2012 +0900
@@ -110,6 +110,9 @@
                 _incdirs(dirs, f)
         return dirs
 
+    def dirs(self):
+        return self._dirs
+
     @propertycache
     def _ignore(self):
         files = [self._join('.hgignore')]