changeset 32731:6f791ca70640

perf: have a generic "clearstorecache" function There are multiple places where we will want to purge some store cache. So we promote the existing _clearobsstore function to a something reusable.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 07 Jun 2017 17:31:30 +0100
parents b8ff7d0ff361
children e36569bd9e28
files contrib/perf.py
diffstat 1 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/perf.py	Thu Jun 08 23:23:37 2017 -0700
+++ b/contrib/perf.py	Wed Jun 07 17:31:30 2017 +0100
@@ -357,6 +357,14 @@
     # - perf.py itself has been available since 1.1 (or eb240755386d)
     raise error.Abort(("tags API of this hg command is unknown"))
 
+# utilities to clear cache
+
+def clearfilecache(repo, attrname):
+    unfi = repo.unfiltered()
+    if attrname in vars(unfi):
+        delattr(unfi, attrname)
+    unfi._filecache.pop(attrname, None)
+
 # perf commands
 
 @command('perfwalk', formatteropts)
@@ -1259,12 +1267,6 @@
     timer(d)
     fm.end()
 
-def _clearobsstore(repo):
-    unfi = repo.unfiltered()
-    if 'obsstore' in vars(unfi):
-        del unfi.obsstore
-        del unfi._filecache['obsstore']
-
 @command('perfvolatilesets',
          [('', 'clear-obsstore', False, 'drop obsstore between each call.'),
          ] + formatteropts)
@@ -1279,7 +1281,7 @@
         def d():
             repo.invalidatevolatilesets()
             if opts['clear_obsstore']:
-                _clearobsstore(repo)
+                clearfilecache(repo, 'obsstore')
             obsolete.getrevs(repo, name)
         return d
 
@@ -1294,7 +1296,7 @@
         def d():
             repo.invalidatevolatilesets()
             if opts['clear_obsstore']:
-                _clearobsstore(repo)
+                clearfilecache(repo, 'obsstore')
             repoview.filterrevs(repo, name)
         return d