Patchwork [1,of,2] localrepo: move closure of lock release to class

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 15, 2015, 1:55 p.m.
Message ID <02d72254dc69b88c60c5.1442325303@mimosa>
Download mbox | patch
Permalink /patch/10508/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 15, 2015, 1:55 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1442318428 -32400
#      Tue Sep 15 21:00:28 2015 +0900
# Node ID 02d72254dc69b88c60c59234e447572ae63ed41e
# Parent  7df5d476087392e217699a41c11fbe8cd48713b2
localrepo: move closure of lock release to class

It only captures "self", so it isn't necessary to be created dynamically.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1198,6 +1198,13 @@  class localrepository(object):
         self.invalidate()
         self.invalidatedirstate()
 
+    def _refreshfilecachestats(self):
+        '''Reload stats of cached files so that they are flagged as valid'''
+        for k, ce in self._filecache.items():
+            if k == 'dirstate' or k not in self.__dict__:
+                continue
+            ce.refresh()
+
     def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc):
         try:
             l = lockmod.lock(vfs, lockname, 0, releasefn, desc=desc)
@@ -1240,13 +1247,7 @@  class localrepository(object):
             l.lock()
             return l
 
-        def unlock():
-            for k, ce in self._filecache.items():
-                if k == 'dirstate' or k not in self.__dict__:
-                    continue
-                ce.refresh()
-
-        l = self._lock(self.svfs, "lock", wait, unlock,
+        l = self._lock(self.svfs, "lock", wait, self._refreshfilecachestats,
                        self.invalidate, _('repository %s') % self.origroot)
         self._lockref = weakref.ref(l)
         return l