diff mercurial/context.py @ 16151:a01d2fb5ba65

merge with stable
author Matt Mackall <mpm@selenic.com>
date Wed, 22 Feb 2012 17:36:33 -0600
parents 004982e5d782 616c2e278f18
children 352053e6cd8e
line wrap: on
line diff
--- a/mercurial/context.py	Wed Feb 22 12:30:15 2012 +0100
+++ b/mercurial/context.py	Wed Feb 22 17:36:33 2012 -0600
@@ -206,14 +206,15 @@
         # follow that here, too
         fset.discard('.')
         for fn in self:
-            for ffn in fset:
-                # match if the file is the exact name or a directory
-                if ffn == fn or fn.startswith("%s/" % ffn):
-                    fset.remove(ffn)
-                    break
+            if fn in fset:
+                # specified pattern is the exact name
+                fset.remove(fn)
             if match(fn):
                 yield fn
         for fn in sorted(fset):
+            if fn in self._dirs:
+                # specified pattern is a directory
+                continue
             if match.bad(fn, _('no such file in rev %s') % self) and match(fn):
                 yield fn
 
@@ -236,6 +237,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."""
@@ -949,6 +966,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."""