[PATCH 1 of 3 STABLE V3] context: add 'dirs()' to changectx/workingctx for directory patterns

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed Feb 22 15:09:39 UTC 2012


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1329923274 -32400
# Branch stable
# Node ID caba21e946d5767ec29a0b7da32661d9d0a80e1d
# Parent  0e0060bf2f440d5cc33e5f36d99868a5380debd4
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.

diff -r 0e0060bf2f44 -r caba21e946d5 mercurial/context.py
--- a/mercurial/context.py	Mon Feb 13 17:22:35 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."""
diff -r 0e0060bf2f44 -r caba21e946d5 mercurial/dirstate.py
--- a/mercurial/dirstate.py	Mon Feb 13 17:22:35 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')]



More information about the Mercurial-devel mailing list