Patchwork [4,of,8] perf: make `clearfilecache` helper work with any object

login
register
mail settings
Submitter Boris Feld
Date Nov. 21, 2018, 6:33 p.m.
Message ID <ea3a9f11bceef210118f.1542825234@localhost.localdomain>
Download mbox | patch
Permalink /patch/36701/
State Accepted
Headers show

Comments

Boris Feld - Nov. 21, 2018, 6:33 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1542646221 0
#      Mon Nov 19 16:50:21 2018 +0000
# Node ID ea3a9f11bceef210118fc368908f4cfcd5a814fa
# Parent  73f19cded5865968e672a0e1d1b6aaaef2b77e18
# EXP-Topic perf-ignore
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r ea3a9f11bcee
perf: make `clearfilecache` helper work with any object

If the object is not a localrepo, it won't have an `unfiltered` method (and
won't need one).
Yuya Nishihara - Nov. 22, 2018, 1:02 p.m.
On Wed, 21 Nov 2018 19:33:54 +0100, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1542646221 0
> #      Mon Nov 19 16:50:21 2018 +0000
> # Node ID ea3a9f11bceef210118fc368908f4cfcd5a814fa
> # Parent  73f19cded5865968e672a0e1d1b6aaaef2b77e18
> # EXP-Topic perf-ignore
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r ea3a9f11bcee
> perf: make `clearfilecache` helper work with any object

Queued this, thanks.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -457,11 +457,13 @@  def repocleartagscachefunc(repo):
 
 # utilities to clear cache
 
-def clearfilecache(repo, attrname):
-    unfi = repo.unfiltered()
-    if attrname in vars(unfi):
-        delattr(unfi, attrname)
-    unfi._filecache.pop(attrname, None)
+def clearfilecache(obj, attrname):
+    unfiltered = getattr(obj, 'unfiltered', None)
+    if unfiltered is not None:
+        obj = obj.unfiltered()
+    if attrname in vars(obj):
+        delattr(obj, attrname)
+    obj._filecache.pop(attrname, None)
 
 # perf commands