Patchwork [1,of,8] perf: have a generic "clearstorecache" function

login
register
mail settings
Submitter Pierre-Yves David
Date June 8, 2017, 7:44 p.m.
Message ID <bbc6d0c724ddd10f0d45.1496951057@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21253/
State Accepted
Headers show

Comments

Pierre-Yves David - June 8, 2017, 7:44 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1496853090 -3600
#      Wed Jun 07 17:31:30 2017 +0100
# Node ID bbc6d0c724ddd10f0d45971d9faf1a875bdee714
# Parent  3ef319e9505f376775c91b2ab7d89ac9ac4343e9
# EXP-Topic perf
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r bbc6d0c724dd
perf: have a generic "clearstorecache" function

There are multiple place were we will wants to purge some store cache. So we
promote the existing _clearobsstore function to a something reusable.
Yuya Nishihara - June 9, 2017, 2:05 p.m.
On Thu, 08 Jun 2017 20:44:17 +0100, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@octobus.net>
> # Date 1496853090 -3600
> #      Wed Jun 07 17:31:30 2017 +0100
> # Node ID bbc6d0c724ddd10f0d45971d9faf1a875bdee714
> # Parent  3ef319e9505f376775c91b2ab7d89ac9ac4343e9
> # EXP-Topic perf
> # Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
> #              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r bbc6d0c724dd
> perf: have a generic "clearstorecache" function

Nice. Queued the series, thanks.

I've made trivial English tweaks in commit messages. Hope that's correct.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -357,6 +357,14 @@  def repocleartagscachefunc(repo):
     # - 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 @@  def perfrevset(ui, repo, expr, clear=Fal
     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 perfvolatilesets(ui, repo, *names, *
         def d():
             repo.invalidatevolatilesets()
             if opts['clear_obsstore']:
-                _clearobsstore(repo)
+                clearfilecache(repo, 'obsstore')
             obsolete.getrevs(repo, name)
         return d
 
@@ -1294,7 +1296,7 @@  def perfvolatilesets(ui, repo, *names, *
         def d():
             repo.invalidatevolatilesets()
             if opts['clear_obsstore']:
-                _clearobsstore(repo)
+                clearfilecache(repo, 'obsstore')
             repoview.filterrevs(repo, name)
         return d