templatekw: cache mergestate even if merge is not ongoing
authorYuya Nishihara <yuya@tcha.org>
Wed, 15 Apr 2020 23:11:55 +0900
changeset 44712 a825bfbf6642
parent 44711 637eb7f7559b
child 44713 97c10b157665
templatekw: cache mergestate even if merge is not ongoing While playing with eBPF, I noticed .hg/merge/state{,2} files were tried to open() for each revision. That's not healthy. Let's cache the "inactive" state as well.
mercurial/templatekw.py
--- a/mercurial/templatekw.py	Wed Apr 15 19:24:21 2020 +0900
+++ b/mercurial/templatekw.py	Wed Apr 15 23:11:55 2020 +0900
@@ -417,13 +417,15 @@
     if ctx.node() in wpnodes:
         return b'@'
     else:
-        merge_nodes = cache.get(b'merge_nodes', ())
-        if not merge_nodes:
+        merge_nodes = cache.get(b'merge_nodes')
+        if merge_nodes is None:
             from . import merge
 
             mergestate = merge.mergestate.read(repo)
             if mergestate.active():
                 merge_nodes = (mergestate.local, mergestate.other)
+            else:
+                merge_nodes = ()
             cache[b'merge_nodes'] = merge_nodes
 
         if ctx.node() in merge_nodes: