localrepo: move dirstate validate function to class scope
authorSiddharth Agarwal <sid0@fb.com>
Wed, 02 Sep 2015 22:05:23 -0700
changeset 26155 51a30cae2bff
parent 26154 242853e14804
child 26156 a112fffdb632
localrepo: move dirstate validate function to class scope This will allow the function to be referred to by subclasses, as required for upcoming patches.
mercurial/localrepo.py
--- a/mercurial/localrepo.py	Thu Sep 03 10:29:42 2015 -0700
+++ b/mercurial/localrepo.py	Wed Sep 02 22:05:23 2015 -0700
@@ -300,6 +300,7 @@
         if create:
             self._writerequirements()
 
+        self._dirstatevalidatewarned = False
 
         self._branchcaches = {}
         self._revbranchcache = None
@@ -473,19 +474,19 @@
 
     @repofilecache('dirstate')
     def dirstate(self):
-        warned = [0]
-        def validate(node):
-            try:
-                self.changelog.rev(node)
-                return node
-            except error.LookupError:
-                if not warned[0]:
-                    warned[0] = True
-                    self.ui.warn(_("warning: ignoring unknown"
-                                   " working parent %s!\n") % short(node))
-                return nullid
+        return dirstate.dirstate(self.vfs, self.ui, self.root,
+                                 self._dirstatevalidate)
 
-        return dirstate.dirstate(self.vfs, self.ui, self.root, validate)
+    def _dirstatevalidate(self, node):
+        try:
+            self.changelog.rev(node)
+            return node
+        except error.LookupError:
+            if not self._dirstatevalidatewarned:
+                self._dirstatevalidatewarned = True
+                self.ui.warn(_("warning: ignoring unknown"
+                               " working parent %s!\n") % short(node))
+            return nullid
 
     def __getitem__(self, changeid):
         if changeid is None or changeid == wdirrev: