Patchwork [1,of,2] localrepo: move dirstate validate function to class scope

login
register
mail settings
Submitter Siddharth Agarwal
Date Sept. 3, 2015, 5:17 a.m.
Message ID <220e2aacec2ccb3062a4.1441257460@dev6666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/10380/
State Accepted
Headers show

Comments

Siddharth Agarwal - Sept. 3, 2015, 5:17 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1441256723 25200
#      Wed Sep 02 22:05:23 2015 -0700
# Node ID 220e2aacec2ccb3062a421998643579369e4fc01
# Parent  f77a3f27cea533232dc107a72773e90e2de9549d
localrepo: move dirstate validate function to class scope

This will allow the function to be referred to by subclasses, as required for
upcoming patches.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -300,6 +300,7 @@  class localrepository(object):
         if create:
             self._writerequirements()
 
+        self._dirstatevalidatewarned = False
 
         self._branchcaches = {}
         self._revbranchcache = None
@@ -473,19 +474,19 @@  class localrepository(object):
 
     @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: