diff mercurial/context.py @ 16143:fceb2964fa6c stable

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.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Thu, 23 Feb 2012 00:07:54 +0900
parents 131d1a09108a
children 616c2e278f18
line wrap: on
line diff
--- 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."""