Patchwork templatekw: cache mergestate even if merge is not ongoing

login
register
mail settings
Submitter Yuya Nishihara
Date April 15, 2020, 2:39 p.m.
Message ID <5b857d88bc5e391ff928.1586961587@mimosa>
Download mbox | patch
Permalink /patch/46126/
State Accepted
Headers show

Comments

Yuya Nishihara - April 15, 2020, 2:39 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1586959915 -32400
#      Wed Apr 15 23:11:55 2020 +0900
# Node ID 5b857d88bc5e391ff928ac253c42248784527b4e
# Parent  f9735a7cf54beb15dd252042df17cb620556b103
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.
Augie Fackler - April 15, 2020, 4:31 p.m.
queued, thanks

> On Apr 15, 2020, at 10:39, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1586959915 -32400
> #      Wed Apr 15 23:11:55 2020 +0900
> # Node ID 5b857d88bc5e391ff928ac253c42248784527b4e
> # Parent  f9735a7cf54beb15dd252042df17cb620556b103
> 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.
> 
> diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
> --- a/mercurial/templatekw.py
> +++ b/mercurial/templatekw.py
> @@ -417,13 +417,15 @@ def getgraphnodecurrent(repo, ctx, cache
>     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:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -417,13 +417,15 @@  def getgraphnodecurrent(repo, ctx, cache
     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: