[PATCH] manifest: move dirs() to manifest

Drew Gottlieb drgott at google.com
Fri Mar 13 19:18:20 UTC 2015


# HG changeset patch
# User Drew Gottlieb <drgott at google.com>
# Date 1426180563 25200
#      Thu Mar 12 10:16:03 2015 -0700
# Node ID 47f1fdab71a77d88ca51d96002a8f3306b10e527
# Parent  2b7ab29627fd93ca7f5cb838403c2f6c728469bd
manifest: move dirs() to manifest

This moves implementation of dirs() from basectx to manifestdict. Moving
knowledge of the manifest's dirs to the manifest itself allows for cleaner
implementation of more optimized manifests. This change also adds a new
hasdir() method to manifest for the same reason, and also adds a hasdir() to
context for convenience -- which calls the manifest's.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -264,12 +264,11 @@
         diffopts = patch.diffopts(self._repo.ui, opts)
         return patch.diff(self._repo, ctx2, self, match=match, opts=diffopts)
 
-    @propertycache
-    def _dirs(self):
-        return scmutil.dirs(self._manifest)
+    def dirs(self):
+        return self._manifest.dirs()
 
-    def dirs(self):
-        return self._dirs
+    def hasdir(self, dir):
+        return self._manifest.hasdir(dir)
 
     def dirty(self, missing=False, merge=True, branch=True):
         return False
@@ -606,10 +605,8 @@
             if match(fn):
                 yield fn
         for fn in sorted(fset):
-            if fn in self._dirs:
-                # specified pattern is a directory
-                continue
-            match.bad(fn, _('no such file in rev %s') % self)
+            if not self.hasdir(fn):
+                match.bad(fn, _('no such file in rev %s') % self)
 
     def matches(self, match):
         return self.walk(match)
@@ -1559,7 +1556,7 @@
             def bad(f, msg):
                 # 'f' may be a directory pattern from 'match.files()',
                 # so 'f not in ctx1' is not enough
-                if f not in other and f not in other.dirs():
+                if f not in other and not other.hasdir(f):
                     self._repo.ui.warn('%s: %s\n' %
                                        (self._repo.dirstate.pathto(f), msg))
             match.bad = bad
diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -6,9 +6,10 @@
 # GNU General Public License version 2 or any later version.
 
 from i18n import _
-import mdiff, parsers, error, revlog, util
+import mdiff, parsers, error, revlog, util, scmutil
 import array, struct
 
+propertycache = util.propertycache
 
 class _lazymanifest(dict):
     """This is the pure implementation of lazymanifest.
@@ -141,6 +142,16 @@
         files.difference_update(m2.iterkeys())
         return files
 
+    @propertycache
+    def _dirs(self):
+        return scmutil.dirs(self)
+
+    def dirs(self):
+        return self._dirs
+
+    def hasdir(self, dir):
+        return dir in self._dirs
+
     def matches(self, match):
         '''generate a new manifest filtered by the match argument'''
         if match.always():


More information about the Mercurial-devel mailing list