Patchwork [3,of,4] templatekw: avoid slow creation of changectx objects in showgraphnode()

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 3, 2015, 2:26 p.m.
Message ID <ebe7e6a6986675c44cef.1449152806@mimosa>
Download mbox | patch
Permalink /patch/11786/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 3, 2015, 2:26 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1447488177 -32400
#      Sat Nov 14 17:02:57 2015 +0900
# Node ID ebe7e6a6986675c44cef7bfd442d73e29a2dda40
# Parent  e60e6f49f4c83db91d57364a5308d95a9ce982f6
templatekw: avoid slow creation of changectx objects in showgraphnode()

This mitigates the minor perf regression introduced by the previous patch.

  % hg log -G -R mozilla-central -l10000 --time > /dev/null
  (original) real 2.200 secs
  (previous) real 2.590 secs
  (this)     real 2.280 secs

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -7,7 +7,7 @@ 
 
 from __future__ import absolute_import
 
-from .node import hex
+from .node import hex, nullid
 from . import (
     error,
     hbisect,
@@ -343,7 +343,9 @@  def showfiles(**args):
 def showgraphnode(repo, ctx, **args):
     """:graphnode: String. The character representing the changeset node in
     an ASCII revision graph"""
-    wpnodes = [pctx.node() for pctx in repo[None].parents()]
+    wpnodes = repo.dirstate.parents()
+    if wpnodes[1] == nullid:
+        wpnodes = wpnodes[:1]
     if ctx.node() in wpnodes:
         return '@'
     elif ctx.obsolete():