changeset 50939:e4c4adb694f5 stable

perf: add a `--clear-fnode-cache-rev` argument to perf::tags This will help us test this in situation closer to an update after a commit or a push.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 22 Jun 2023 18:39:29 +0200
parents f02b62b7b056
children 98a7f325eb5d
files contrib/perf.py mercurial/tags.py
diffstat 2 files changed, 46 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/perf.py	Thu Jun 22 16:03:18 2023 +0200
+++ b/contrib/perf.py	Thu Jun 22 18:39:29 2023 +0200
@@ -894,6 +894,19 @@
     repo.cachevfs.tryunlink(tags._fnodescachefile)
 
 
+def _default_forget_fnodes(repo, revs):
+    """function used by the perf extension to prune some entries from the
+    fnodes cache"""
+    from mercurial import tags
+
+    missing_1 = b'\xff' * 4
+    missing_2 = b'\xff' * 20
+    cache = tags.hgtagsfnodescache(repo.unfiltered())
+    for r in revs:
+        cache._writeentry(r * tags._fnodesrecsize, missing_1, missing_2)
+    cache.write()
+
+
 @command(
     b'perf::tags|perftags',
     formatteropts
@@ -907,10 +920,17 @@
         ),
         (
             b'',
-            b'clear-fnode-cache',
+            b'clear-fnode-cache-all',
             False,
             b'clear on disk file node cache (DESTRUCTIVE),',
         ),
+        (
+            b'',
+            b'clear-fnode-cache-rev',
+            [],
+            b'clear on disk file node cache (DESTRUCTIVE),',
+            b'REVS',
+        ),
     ],
 )
 def perftags(ui, repo, **opts):
@@ -927,7 +947,9 @@
     repocleartagscache = repocleartagscachefunc(repo)
     clearrevlogs = opts[b'clear_revlogs']
     clear_disk = opts[b'clear_on_disk_cache']
-    clear_fnode = opts[b'clear_fnode_cache']
+    clear_fnode = opts[b'clear_fnode_cache_all']
+
+    clear_fnode_revs = opts[b'clear_fnode_cache_rev']
 
     clear_disk_fn = getattr(
         tags,
@@ -939,6 +961,15 @@
         "clear_cache_fnodes",
         _default_clear_on_disk_tags_fnodes_cache,
     )
+    clear_fnodes_rev_fn = getattr(
+        tags,
+        "forget_fnodes",
+        _default_forget_fnodes,
+    )
+
+    clear_revs = None
+    if clear_fnode_revs:
+        clear_revs = scmutil.revrange(repo, clear_fnode_revs)
 
     def s():
         if clearrevlogs:
@@ -948,6 +979,8 @@
             clear_disk_fn(repo)
         if clear_fnode:
             clear_fnodes_fn(repo)
+        elif clear_revs is not None:
+            clear_fnodes_rev_fn(repo, clear_revs)
         repocleartagscache()
 
     def t():
--- a/mercurial/tags.py	Thu Jun 22 16:03:18 2023 +0200
+++ b/mercurial/tags.py	Thu Jun 22 18:39:29 2023 +0200
@@ -920,3 +920,14 @@
 def clear_cache_fnodes(repo):
     """function used by the perf extension to clear "file node cache"""
     repo.cachevfs.tryunlink(_filename(repo))
+
+
+def forget_fnodes(repo, revs):
+    """function used by the perf extension to prune some entries from the fnodes
+    cache"""
+    missing_1 = b'\xff' * 4
+    missing_2 = b'\xff' * 20
+    cache = hgtagsfnodescache(repo.unfiltered())
+    for r in revs:
+        cache._writeentry(r * _fnodesrecsize, missing_1, missing_2)
+    cache.write()